Thomas Schelling's segregation model is one of the most powerful demonstrations of how simple individual preferences can lead to complex, emergent social patterns. In this project, I implemented the classic agent-based model and visualized the results as stunning 3D manifolds that reveal the hidden structure of segregation dynamics.
A simulation of the Schelling model showing agents moving to find neighborhoods that meet their similarity preferences.
What makes Schelling's model so compelling is its counterintuitive result: even when individuals have only mild preferences for similar neighbors, the system can evolve into highly segregated patterns. My implementation explores this phenomenon across 9,801 different parameter combinations, creating a comprehensive map of segregation dynamics.
The most striking aspect of this project is the 3D visualization that maps the relationship between model parameters and outcomes. By plotting empty ratio against similarity threshold, with mean similarity as the z-axis, we can see the "segregation manifold" - a mathematical surface that captures the essence of how segregation emerges.
The 3D surface reveals several fascinating insights:
This project showcases several advanced techniques:
To handle 9,801 simulations efficiently, I used Modal for distributed computing. Each simulation runs independently on cloud infrastructure, allowing for massive parallelization:
@app.function(image=image, cpu=1, timeout=600)
def run_simulation(params):
# Run Schelling simulation with given parameters
model = Schelling(size, empty_ratio, similarity_threshold, n_neighbors, seed)
# Run for 15 iterations
for step in range(iterations):
model.run()
# Record agent metadata at each step
return simulation_results
Beyond visualization, I applied XGBoost regression to predict segregation outcomes, using Latin Hypercube Sampling for efficient parameter space exploration. The model achieved strong performance with R² scores above 0.95 in cross-validation.
The project generates interactive 3D plots using Plotly, allowing viewers to explore the parameter space from multiple angles and discover the hidden structure of segregation dynamics.
This deep dive into Schelling's model reveals several important lessons:
The complete implementation is available on GitHub, including:
View the full project on GitHub
Schelling's segregation model remains as relevant today as when it was first proposed in 1971. By combining computational power with modern visualization techniques, we can gain new insights into how individual choices shape collective outcomes. The 3D manifold visualization not only makes the model's behavior more intuitive but also reveals the elegant mathematical structure underlying complex social dynamics.
This project demonstrates the power of computational social science to illuminate fundamental questions about human behavior and social organization. As we face ongoing challenges around segregation and social cohesion, tools like these help us understand the mechanisms at work and potentially design better interventions.