Visualizing Segregation: A Deep Dive into Schelling's Model with 3D Manifolds

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.

Schelling Model Simulation

A simulation of the Schelling model showing agents moving to find neighborhoods that meet their similarity preferences.

The Beauty of Emergent Behavior

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.

Key Model Parameters

3D Visualization: The Segregation Manifold

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.

Schelling 2D Manifold View 1 Schelling 2D Manifold View 2

What the Manifold Reveals

The 3D surface reveals several fascinating insights:

Technical Implementation

This project showcases several advanced techniques:

Distributed Computing with Modal

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

Machine Learning Analysis

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.

Interactive Visualizations

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.

Key Insights

This deep dive into Schelling's model reveals several important lessons:

Code and Data

The complete implementation is available on GitHub, including:

View the full project on GitHub

Conclusion

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.