Tom Schelling introduced this model of segregation towards the end of the 1960s. In it he attempted to explain the phenomona of segregation in communities. He did this by placing black and white pieces randomly on a chess board and saying that each had a certain threshold of "happiness". This happiness was based upon the surrounding pieces and if their colors were the same as the color in question. If the piece were to be unhappy, it would move to a randomly selected place on the board. Do this enough times and the board will be completely segregated.
Yes. Duh. Of course. Fluids. Pretty much most systems. C'mon now. Physics is ruled by segregation. Things want to be around things like them or things that like them. "In our interpretation, the agent's satisfaction is equivalent to the energy stored in him. An increase in happiness is a decrease in internal energy. An agent, therefore, wants to minimize his energy, which is generated either by taking some action or through the interaction with his environment." Applying this directly to my model, it clearly shows that the particles a.k.a boxes want to have lower energy, with a few outliers. The electrons want to fall to lower energy levels, but some of them do remain excited but they would fall if they could.
Assuming that the particle's happiness thresholds govern their interal energy, it is right to say that all particles want to be happy. Particles will fight to be at lower energy and so they move location to be surrounded by particles more like them. Particles are conserved, however, energy is not conserved. Particles are losing energy as they drop to lower energy levels and therefore, the system is losing energy. When a particle moves out of its unsegregated neighborhood to a segregated one, it is losing energy. When a particle moves into a neighborhood that makes it very unhappy, it gains energy. Therefore, the system can be seen as absorbing and emitting energy as the particles move around. The final model will not be 50/50 split down the middle, rather, there will be clusters of particles. These clusters minimize the energy of the maximum amount of particles possible.
Each cluster wants to be the biggest, baddest cluster around. It does this by taking in as many particles as it possibly can by stealing from other clusters. However, each cluster steals from each other, which means that there will not be a super-massive cluster that encompasses every single particle. Yes, there will be a central cluster that contains the majority, but it will not contain all. Small clusters are initally favorable because they are so quick and easy to form, but once these start to combine, bigger clusters begin to form. "Particles on the cluster surface risk having low utility and thus, are energetically less favored, which means that bigger clusters now become energetically favored because of their smaller surface-to-volume ratio." The surface is the outermost particles. "Two things can happen with big clusters. Either clusters touch the system boundaries and the whole system becomes segregated into two distinct clusters separated by a flat surface, or a single spherical cluster forms away from the boundaries because particles have the same probability of reaching the cluster's surface from any direction." Rarely does the flat line segregation occur, rather, a single spherical cluster forms typically encompassing the boundaries. This is because it maintains some of the smaller clusters while some outliers remain.
make_num_grid(width,height,Red_Perc,Blue_Perc): This function takes four arguments: width, height, Red_Perc, and Blue_Perc. The width and height are pretty self explanatory as they are the the size of the grid the user wishes to make. Red_Perc and Blue_Perc are a little different as they are the percentage of the grid that will be that color. For example, in a 10x10 grid, if Red_Perc = 75% there will be 75 red blocks. This returns a height x width grid with 0's for empties, 1's for Blue spaces, and 2's for Red spaces.
near_me_num(grid,percent): This function takes two arguments: a grid and a percent threshold. The percent threshold is what determines if boxes should move or not. The percentage is the amount of unlike boxes surround the selected box. For example, a 100% threshold would move only the boxes completely surrounded by unlike boxes while a threshold of 12.5% would move every box that has an unlike box touching it. This function is my longest, but not my most complex. Rather, the length is attributed to dealing with the edge cases for each number. There are three types of cases. One is a corner, which has three boxes touching it. The next is an edge, excluding the corner, which has 5 boxes touching it. The final case is a box in the middle which has 8 boxes touching it. So this function deals with these cases in the various ways that they come up. If the percent threshold is greater than the percent of unlike boxes surrounding the box, it will add that space to the appropiate array. This function then returns the grid and three arrays: every 0 space, every 1 space that needs to be moved, and every 2 space that needs to be moved.
Meathead_Movers(grid,array0,array1,array2): This function takes the returns of near_me_num and moves the spaces that are in these arrays. It does this by dealing with the various lengths of the arrays and switching unhappy 1's with unhappy 2's. The logic behind this approach is that unhappy 1's would make happy 2's and vice versa. Granted, if there are empty spaces and the length of one array is shorter than the other, the longer array will switch with the empty spaces. In conjunction with near_me_num, these two functions make up the bulk of my project, every other function is for either aesthetics or does a rather small task. It returns the new grid that is has created by moving around the blocks.
colorful(grid): This function converts the grid which has consisted of numbers up to this point to BlockGrid, with 0' being black, 1's being blue, and 2's being red. Simply made a block grid with black fill and looped through every space and made the 1's blue and 2's red.
For this question, I asked, how do the amount of loops (can be likened to time) change as grid size increases? Is it linear? Is it exponential? What does the graph of loops vs size look like? This models particle density as it increases and the time it takes for these particles to segregate themselves. For these models I ran a 50/50 distribution between red and blue and a 50% happiness threshold. I ran each grid size four times and took the average of the number of loops.
The result of this was the graph was more or less linear, with a few major outliers. The reason for the outliers? Boxes that constantly switch but provide no greater happiness force the loop to continue. This construes the data, but it is much like what may happen in real life. The system is absorbing and emitting energy at a constant rate, meaning that the status quo at that time will remain a more or less constant.
The Schelling model was initially created to look at how neighborhoods change over time. The above question has already shown how the grid will segregate into clusters with the exception of certain outliers. What I was interested in here is what does a single block look like on the edge of a cluster. When a neighborhood is confined to a single city block what happens? How will this single block segregate itself? What happens when the happiness threshold is changed?
The block becomes the most segregated at around 45% of happiness threshold. As the happiness threshold increases or deccreases from the 45% threshold, the blocks become less and less segregated. Looking at the definition of the happiness threshold, the reason behind this number becomes evident. For most of these blocks there are 5 neighboring blocks. In order for a straight line to be segregating the boxes, the boxes must be happy with two boxes neighboring them. 2/5 is 0.4 and there a 41% threshold would allow for this to occur. When the happiness threshold goes below this, the loop never stops because the blocks on the edge will never be satisfied because there must always be two neighbors for the outermost blocks. Even if there were more of one type of block, the edge cases would not be happy and would constantly be moving. As the threshold increases, the blocks are happier with neighbors that are unlike them and therefore, are less segregated. As long as the threshold is over 40%, clusters will form and the block will be segregated.
http://stackoverflow.com/questions/11813548/python-pass-multiple-arguments-from-one-function-to-another Learned the unpacking of arguments *
http://www.pnas.org/content/103/51/19261.full This helped me with most of the analysis of my code.
In [ ]: