The threshold model

A threshold model is any model where some threshold value(s) is/are used to distinguish the ranges of values, where the behavior predicted by the model converges in some important way. Schelling attempted to model the dynamics of segregation, which was motivated when individual interactions by constructing two simulation models.

Schelling's Segregation Model

Schelling's Segregation Model (SSM) was first developed by Thomas C. Schelling. This model is one of the first constructive models of a system that is capable of self-organization.

Schelling experimented by placing pennies and dimes on a chessboard and moving them around according to various rules. In his experiment, he used a board analogous to a city, a board square to a domicile, and squares to a neighborhood. The pennies and dimes (visually different as well) could represent smokers, nonsmokers, male, female, executives, nonexecutives, students, or teachers for two groups.

The simulation rules specify the termination condition as none of the agents moved from their current position because they are happy, which means that agents will move if they are not happy.

The Schelling Model is used to simulate the segregation of a classroom, where the model shows that segregated patterns can occur even for weak preferences on neighboring classmates.

Suppose we have three types of student categories based on their number one priority: sports, advanced proficiency academics, and regular, each with type 0, 1, and 2 respectively.

For the purpose of illustration here, we will assume that there are 250 students of each type in a high school. Each agent represents a student. These agents all live on a single unit square (this can be visualized as a high school building). The position of an agent is just a point (x, y), where 0 < x ,y <1. An agent is happy if half or more of her 12 nearest neighbors are of the same type (nearest in terms of Euclidean distance). The initial position of each agent is an independent draw from a bivariate uniform distribution, as shown in the following code:

from random import uniform, seed
from math import sqrt
import matplotlib.pyplot as plt

num = 250             # These many agents of a particular type
numNeighbors = 12     # Number of agents regarded as neighbors
requireSameType = 8   # At least this many neighbors to be same type

seed(10)  # for reproducible random numbers

class StudentAgent:

    def __init__(self, type):
        #Students of different type will be shown in colors
        self.type = type
        self.show_position()

    def show_position(self):
        # position changed by using uniform(x,y)
        self.position = uniform(0, 1), uniform(0, 1)

    def get_distance(self, other):
        #returns euclidean distance between self and other agent.
        a = (self.position[0] - other.position[0])**2
        b = (self.position[1] - other.position[1])**2
        return sqrt(a + b)

    def happy(self, agents):
        "returns True if reqd number of neighbors are the same type."
        distances = []

        for agent in agents:
            if self != agent:
                distance = self.get_distance(agent)
                distances.append((distance, agent))
        distances.sort()
        neighbors = [agent for d, agent in distances[:numNeighbors]]
        numSameType = sum(self.type == agent.type 
            for agent in neighbors)
        return numSameType >= requireSameType

    def update(self, agents):
        "If not happy, randomly choose new positions until happy."
        while not self.happy(agents):
            self.show_position()


def plot_distribution(agents, cycle_num):
    
    x1,y1 = [],[]
    x2,y2 = [],[]
    x3,y3 = [],[]
    
    for agent in agents:
        x, y = agent.position
        if agent.type == 0:
            x1.append(x); y1.append(y)
        elif agent.type == 1:
            x2.append(x); y2.append(y)        
        else:
            x3.append(x); y3.append(y)

    fig, ax = plt.subplots(figsize=(10,10))
    plot_args = {'markersize' : 8, 'alpha' : 0.65, 'markersize': 14}
    ax.set_axis_bgcolor('#ffffff')
    ax.plot(x1, y1, 'o', markerfacecolor='#1b62a5',  **plot_args)
    ax.plot(x2, y2, 'o', markerfacecolor='#279321', **plot_args)
    ax.plot(x3, y3, 'D', markerfacecolor='#fd6610', **plot_args)
    ax.set_title('Iteration {}'.format(cycle_num))
    plt.show()

agents = [StudentAgent(0) for i in range(num)]
agents.extend(StudentAgent(1) for i in range(num))
agents.extend(StudentAgent(2) for i in range(num))
count = 1
terminate=False
while terminate == False:
    plot_distribution(agents, count)
    count += 1
    no_one_moved = True
    for agent in agents:
        old_position = agent.position
        agent.update(agents)
        if agent.position != old_position:
            no_one_moved = False
    if no_one_moved:
        terminate=True
Schelling's Segregation Model
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset