851 0585 04 L Modeling and Simulating Social

  • Slides: 77
Download presentation
851 -0585 -04 L – Modeling and Simulating Social Systems with MATLAB Lecture 4

851 -0585 -04 L – Modeling and Simulating Social Systems with MATLAB Lecture 4 – Cellular Automata Karsten Donnay and Stefano Balietti Chair of Sociology, in particular of Modeling and Simulation © ETH Zürich | 2012 -10 -15

Schedule of the course Introduction to MATLAB 24. 09. 01. 10. 08. 10. 15.

Schedule of the course Introduction to MATLAB 24. 09. 01. 10. 08. 10. 15. 10. 22. 10. 29. 10. Working on projects (seminar thesis) 05. 11. 12. 11. 19. 11. Create and Submit a Research Plan DEADLINE: 22. 10. Introduction to social-science modeling and simulations 26. 11. 03. 12. 10. 12. 17. 12. 2012 -10 -15 Handing in seminar thesis and giving a presentation K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 2

Projects – Suggested Topics 1 Traffic Dynamics 9 Evacuation Bottleneck 17 Self-organized Criticality 25

Projects – Suggested Topics 1 Traffic Dynamics 9 Evacuation Bottleneck 17 Self-organized Criticality 25 Facebook 2 Civil Violence 10 Friendship Network Formation 18 Social Networks Evolution 26 Sequential Investment Game 3 Collective Behavior 11 Innovation Diffusion 19 Task Allocation & Division of Labor 27 Modeling the Peer Review System 4 Disaster Spreading 12 Interstate Conflict 20 Artificial Financial Markets 28 Modeling Science 5 Emergence of Conventions 13 Language Formation 21 Desert Ant Behavior 29 Simulation of Networks in Science 6 Emergence of Cooperation 14 Learning 22 Trail Formation 30 Opinion Formation in Science 7 Emergence of Culture 15 Opinion Formation 23 Wikipedia 31 Organizational Learning 8 Emergence of Values 16 Pedestrian Dynamics 24 Social Contagion 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 3

Goals of Lecture 4: students will 1. Consolidate their knowledge of dynamical systems, through

Goals of Lecture 4: students will 1. Consolidate their knowledge of dynamical systems, through brief repetition of the main concepts and revision of the exercises. 2. Get familiar with how and why simulation models may contribute to our understanding of complex socio-dynamic processes. 3. Understand the important concept of Cellular Automata as discrete representations of interactions on an abstract grid (or configuration space). 4. Implement simple Cellular Automata in MATLAB (Game of Life, Highway Simulation, Epidemics: Kermack. Mc. Kendrick model revisited) 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 4

Repetition § dynamical systems described by a set of differential equations (example: Lotka-Volterra) §

Repetition § dynamical systems described by a set of differential equations (example: Lotka-Volterra) § numerical solutions iteratively for instances using 1 st Euler’s Method (example: Kermack-Mc. Kendrick) § the values and ranges of parameters critically matter; they determine which dynamics the model represents (Ex. 2, the ratio of recuperation to infection parameter determines the epidemiological threshold) § time resolution in Euler Method must be sufficiently high to capture (‘fast’) system dynamics (Ex. 3) § not all MATLAB-own ODE solvers work equally well for every dynamical system under consideration (Ex. 3) 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 5

Simulation Models § What do we mean when we speak of (simulation) models? Formalized

Simulation Models § What do we mean when we speak of (simulation) models? Formalized (computational) representation of social, economic etc. dynamics § Implies reduction of complexity, i. e. usually making (strong) simplifying assumptions § § Not trying to reproduce reality but rather systematize specific interdependencies of “real” systems § Formal framework to test and evaluate causal hypotheses against empirical data (or stylized facts) 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 6

Simulation Models § Strength of (simulation) models? § Computational laboratory: test how micro dynamics

Simulation Models § Strength of (simulation) models? § Computational laboratory: test how micro dynamics lead to macro patters § There are usually no experiments in social sciences but computer models can be a “testing ground” § Particularly suitable where formal models fail (or where dynamics are too complex formal modeling) § Possible to combine empirical input with quantitative validation of both the results and mechanisms 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 7

Simulation Models § Weakness of (simulation) models? § The choice of model parameters, implementation

Simulation Models § Weakness of (simulation) models? § The choice of model parameters, implementation etc. may strongly influence the simulation outcome § We can only model aspects of a system, i. e. the models are necessarily incomplete & reductionist § More complex models are NOT necessarily better: dynamics between model components often poorly understood (a known problem in climate modeling) § Can construct a computational model of virtually anything but hard to verify if you are actually studying a realistic empirical question! 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 8

Simulation Models § How to we deal with known limitations? § Use empirical input

Simulation Models § How to we deal with known limitations? § Use empirical input and formal optimization to rule out arbitrariness of the model § Test for implementation- and specificationdependence of simulations § Validate the model mechanism both with observations and causal theory § Use empirical data to evaluate the predictive power of the simulation model 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 9

Cellular Automaton (plural: Automata) 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz.

Cellular Automaton (plural: Automata) 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 10

Cellular Automaton (plural: Automata) § A cellular automaton is a rule, defining how the

Cellular Automaton (plural: Automata) § A cellular automaton is a rule, defining how the state of a cell in a grid is updated, depending on the states of its neighbor cells. § May be represented as grids with arbitrary dimension. § Cellular-automata simulations are discrete both in time and space. 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 11

Cellular Automaton (plural: Automata) § Simplest example for a (reduced) representation of an interaction

Cellular Automaton (plural: Automata) § Simplest example for a (reduced) representation of an interaction model § Automata dimensions represent an abstract “distance” that could be spatial, social relations etc. § Natural micro-to-macro link from interactions between cells to patterns visible in the automaton 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 12

Cellular Automaton § The grid can have an arbitrary number of dimensions: 1 -dimensional

Cellular Automaton § The grid can have an arbitrary number of dimensions: 1 -dimensional cellular automaton 2012 -10 -15 2 -dimensional cellular automaton K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 13

Moore Neighborhood § The cells are interacting with each neighbor cells, and the neighborhood

Moore Neighborhood § The cells are interacting with each neighbor cells, and the neighborhood can be defined in different ways, e. g. the Moore neighborhood: 1 st order Moore neighborhood 2012 -10 -15 2 nd order Moore neighborhood K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 14

Von-Neumann Neighborhood § The cells are interacting with each neighbor cells, and the neighborhood

Von-Neumann Neighborhood § The cells are interacting with each neighbor cells, and the neighborhood can be defined in different ways, e. g. the Von-Neumann neighborhood: 1 st order Von-Neumann neighborhood 2012 -10 -15 2 nd order Von-Neumann neighborhood K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 15

Game of Life § Ni = Number of 1 st order Moore neighbors to

Game of Life § Ni = Number of 1 st order Moore neighbors to cell i that are activated. § For each cell i: Deactivate: If Ni <2 or Ni >3. 2. Activate: if cell i is deactivated and Ni =3 1. www. mathworld. wolfram. com 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 16

Game of Life § Want to see the Game of Life in action? Type:

Game of Life § Want to see the Game of Life in action? Type: life 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 17

Game of Life Patterns: can you find them? § Ants § Rabbits § B-52

Game of Life Patterns: can you find them? § Ants § Rabbits § B-52 § R 2 D 2 § Blinker puffer § Spacefiller § Diehard § Wasp § Canada goose § Washerwoman § Gliders by the dozen § … § Kok’s galaxy 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 18

Cellular Automata: A New Kind of Science? § A thorough study of all 256

Cellular Automata: A New Kind of Science? § A thorough study of all 256 “behavioral” rules of a 1 -D cellular automata. 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 19

Cellular Automata: A New Kind of Science? 2012 -10 -15 K. Donnay & S.

Cellular Automata: A New Kind of Science? 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 20

Cellular Automaton: Principles 1. Self Organization: Patterns appear without a designer 2. Emergence: Gliders,

Cellular Automaton: Principles 1. Self Organization: Patterns appear without a designer 2. Emergence: Gliders, glider guns, wasps, rabbits appear 3. Complexity: Simple rules produce complex phenomena 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 21

Highway Simulation § Simple example of a 1 -dimensional cellular automaton § Rules for

Highway Simulation § Simple example of a 1 -dimensional cellular automaton § Rules for each car at cell i: Stay: If the cell directly to the right is occupied. 2. Move: Otherwise, move one step to the right, with probability p 1. Move to the next cell, with the probability p 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 22

Highway Simulation § We have prepared some files for the highway simulations: § draw_car.

Highway Simulation § We have prepared some files for the highway simulations: § draw_car. m : Draws a car, with the function draw_car(x 0, y 0, w, h) § simulate_cars. m: Runs the simulation, with the function simulate_cars(move. Prob, in. Flow, with. Graphics) 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 23

Highway Simulation § Running the simulation is done like this: simulate_cars(0. 9, 0. 2,

Highway Simulation § Running the simulation is done like this: simulate_cars(0. 9, 0. 2, true) 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 24

Kermack-Mc. Kendrick Model § In lecture 3, we introduced the Kermack. Mc. Kendrick model,

Kermack-Mc. Kendrick Model § In lecture 3, we introduced the Kermack. Mc. Kendrick model, used for simulating disease spreading. § We will now implement the model again, but this time instead of using differential equations we define it within the cellular-automata framework. 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 25

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β: Infection rate γ: Immunity rate 2012 -10 -15 S β transmission R γ recovery K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch I 26

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β: Infection rate γ: Immunity rate 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 27

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β: Infection rate γ: Immunity rate 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 28

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β: Infection rate γ: Immunity rate 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 29

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β: Infection rate γ: Immunity rate 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 30

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: For the MATLAB

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: For the MATLAB implementation, we need to decode the states {S, I, R}={0, 1, 2} in a matrix x. S S S S 0 0 0 0 I I I S S 1 1 1 0 0 I I S S S 1 1 0 0 0 R I I I S S S 2 1 1 1 0 0 0 I I I S S 1 1 1 0 0 I S S S 1 0 0 0 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 31

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: We now define

Kermack-Mc. Kendrick Model § The Kermack-Mc. Kendrick model is specified as: We now define a 2 -dimensional cellularautomaton, by defining a grid (matrix) x, where each of the cells is in one of the states: 0: Susceptible § 1: Infected § 2: Recovered § 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 32

Kermack-Mc. Kendrick Model § Define microscopic rules for Kermack. Mc. Kendrick model: In every

Kermack-Mc. Kendrick Model § Define microscopic rules for Kermack. Mc. Kendrick model: In every time step, the cells can change states according to: § A Susceptible individual can be infected by an Infected neighbor with probability β, i. e. State 0 -> 1, with probability β. § An individual can recover from an infection with probability γ, i. e. State 1 -> 2, with probability γ. 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 33

Cellular-Automaton Implementation § Implementation of a 2 -dimensional cellularautomaton model in MATLAB is done

Cellular-Automaton Implementation § Implementation of a 2 -dimensional cellularautomaton model in MATLAB is done like this: Iterate the time variable, t Iterate over all cells, i=1. . N, j=1. . N Iterate over all neighbors, k=1. . M … End k-iteration End i-iteration End t-iteration § The iteration over the cells can be done either sequentially, or randomly. 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 34

Cellular-Automaton Implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-Automaton Implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 35

Cellular-Automaton Implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-Automaton Implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 36

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 37

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 38

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 39

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 40

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 41

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 42

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 43

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 44

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 45

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 46

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 47

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 48

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 49

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 50

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Sequential update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 51

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 52

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 53

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 54

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 55

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 56

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 57

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 58

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 59

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti /

Cellular-automaton implementation § Random update: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 60

Cellular-automaton implementation § Attention: § Simulation results may be sensitive to the type of

Cellular-automaton implementation § Attention: § Simulation results may be sensitive to the type of update used! § Random update is usually preferable but also not always the best solution § Just be aware of this potential complication and check your results for dependency on the updating scheme! 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 61

Boundary Conditions § The boundary conditions can be any of the following: § Periodic:

Boundary Conditions § The boundary conditions can be any of the following: § Periodic: The grid is wrapped, so that what exits on one side reappears at the other side of the grid. § Fixed: Agents are not influenced by what happens at the other side of a border. 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 62

Boundary Conditions § The boundary conditions can be any of the following: Fixed boundaries

Boundary Conditions § The boundary conditions can be any of the following: Fixed boundaries 2012 -10 -15 Periodic boundaries K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 63

MATLAB Implementation of the Kermack. Mc. Kendrick Model 2012 -10 -15 K. Donnay &

MATLAB Implementation of the Kermack. Mc. Kendrick Model 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 64

Set parameter values MATLAB implementation 2012 -10 -15 K. Donnay & S. Balietti /

Set parameter values MATLAB implementation 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 65

Define grid, x MATLAB implementation 2012 -10 -15 K. Donnay & S. Balietti /

Define grid, x MATLAB implementation 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 66

Define neighborhood MATLAB implementation 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz.

Define neighborhood MATLAB implementation 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 67

Main loop. Iterate the time variable, t MATLAB implementation 2012 -10 -15 K. Donnay

Main loop. Iterate the time variable, t MATLAB implementation 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 68

Iterate over all cells, i=1. . N, j=1. . N MATLAB implementation 2012 -10

Iterate over all cells, i=1. . N, j=1. . N MATLAB implementation 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 69

For each cell i, j: Iterate over the neighbors MATLAB implementation 2012 -10 -15

For each cell i, j: Iterate over the neighbors MATLAB implementation 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 70

The model, i. e. updating rule goes here. MATLAB implementation 2012 -10 -15 K.

The model, i. e. updating rule goes here. MATLAB implementation 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 71

Breaking Execution § When running large computations or animations, the execution can be stopped

Breaking Execution § When running large computations or animations, the execution can be stopped by pressing Ctrl+C in the main window: 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 72

References § Wolfram, Stephen, A New Kind of Science. Wolfram Media, Inc. , May

References § Wolfram, Stephen, A New Kind of Science. Wolfram Media, Inc. , May 14, 2002. § http: //www. bitstorm. org/gameoflife/ § http: //ddi. cs. unipotsdam. de/Hy. FISCH/Produzieren/lis_projekt/pr oj_gamelife/Conway. Scientific. American. htm § Schelling, Thomas C. (1971). Dynamic Models of Segregation. Journal of Mathematical Sociology 1: 143 -186. 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 73

Exercise 1 § Get draw_car. m and simulate_cars. m from www. soms. ethz. ch/matlab

Exercise 1 § Get draw_car. m and simulate_cars. m from www. soms. ethz. ch/matlab or from https: //github. com/msssm/lectures_files Investigate how the flow (moving vehicles per time step) depends on the density (occupancy 0%. . 100%) in the simulator. This relation is called the fundamental diagram in transportation engineering. 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 74

Exercise 1 b § Generate a video of an interesting case in your traffic

Exercise 1 b § Generate a video of an interesting case in your traffic simulation. § We have uploaded an example file, simulate_cars_video. m, and simulate_cars_video_w 7. m 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 75

Exercise 2 § Download the file disease. m which is an implementation of the

Exercise 2 § Download the file disease. m which is an implementation of the Kermack-Mc. Kendrick model as a Cellular Automaton. § Plot the relative fractions of the states S, I, R, as a function of time, and see if the curves look the same as for the implementation last class 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 76

Exercise 3 § Modify the model Kermack-Mc. Kendrick model in the following ways: Change

Exercise 3 § Modify the model Kermack-Mc. Kendrick model in the following ways: Change from the 1 st order Moore neighborhood to a 2 nd and 3 rd order Moore neighborhood. § Make it possible for Removed individuals to change state back to Susceptible. § § What changes? 2012 -10 -15 K. Donnay & S. Balietti / kdonnay@ethz. ch sbalietti@ethz. ch 77