Presentation is loading. Please wait.

Presentation is loading. Please wait.

2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©

Similar presentations


Presentation on theme: "2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©"— Presentation transcript:

1 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu © ETH Zürich |

2 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch  Send us an abstract of your project.  Don't re-invent the wheel but try to build upon existing models.  Start simple and extend functionality.  Look at project reports from previous semesters. Projects 2

3 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 3 Lesson 5 - Contents  Swarm intelligence  Human cooperation and coordination  How to develop a multi-agent simulator

4 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch Swarm Intelligence 4  Decentralized control  Interaction and learning  Self-organization

5 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch Boids (Reynolds,1986) 5

6 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch More information: http://www.red3d.com/cwr/boids/ 6 Separation: steer to avoid crowding local flockmates Alignment: steer towards the average heading of local flockmates Cohesion: steer to move toward the average position of local flockmates

7 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch Human Cooperation  Prisoner’s dilemma 7 15,1520,0 0,2019,19

8 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch The Evolution of Cooperation (Axelrod,1984)  Tit for tat  Shadow of the future 8

9 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch Coordination 1,10,0 1,1 9

10 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch Learning  Imitation  Reinforcement  Best reply 10

11 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch From Factors to Actors (Macy,2002)  Agents are autonomous  Agents are interdependent  Agents follow simple rules  Agents are adaptive and backward-looking 11

12 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 12 Programming a simulator  Agent based simulations  The models simulate the simultaneous operations of multiple agents, in an attempt to re-create and predict the actions of complex phenomena.  Agents can be pedestrians, animals, customers, internet users, etc…

13 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 13 Programming a simulator  Agent based simulations Time line Characterized by a state (or states) (location, dead/alive, color, level of excitation) Time t Time t + dt State update According to set of behavioral rules New state T1 T2 dt

14 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 14 Programming a simulator  Agent based simulations Characterized by a state (location, dead/alive, level of excitation) Time t Time t + dt State update According to set of behavioral rules, including neighborhood New state Time line T1 T2

15 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 15 Programming a simulator  Programming an agent based simulator often goes in five steps  Initialization -Initial state; parameters; environment  Time loop -Processing each time steps  Agents loop -Processing each agents  Update -Updating agent i at time t  Save data -For further analysis Initialization Time loop end Save data Agents loop end Update state

16 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 16 Programming a simulator  Step 1: Defining the initial state & parameters % Initial state t 0 =0;%begining of the time line dt=1 ;%time step T=100; %number of time steps %Initial state of the agents State1 = [0 0 0 0]; State2 = [1 1 1 1]; etc…

17 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 17 Programming a simulator  Step 1: Defining the initial state & parameters % Initial state t 0 =0;%begining of the time line dt=1 ;%time step T=100; %number of time steps %Initial state of the agents State1 = zeros(1,50); State2 = rand(1,50);

18 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 18 Programming a simulator  Step 2: Covering each time step % time loop For t=t 0 :dt:T What happen at each time step? - Update environment - Update agents end

19 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 19 Programming a simulator  Step 3: Covering each agent % agent loop For i=1:length(States) What happen for each agent? end

20 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 20 Programming a simulator  Step 4: Updating agent i at time t % update % Each agent has 60% chance to switch to state 1 randomValue=rand(); if (randomValue<0.6) State(i)=1; else State(i)=0; end Use sub-functions for better organization!!

21 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 21 Programming a simulator  Step 4: Updating agent i at time t % update % Each agent has ‘proba’ chance to switch to state 1 randomValue=rand(); if (randomValue<proba) State(i)=1; else State(i)=0; end Define parameters in the first part!!

22 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 22 Programming a simulator  Step 4: Updating agent i at time t % Initial state t 0 =0;%begining of the time line dt=1 ;%time step T=100; %number of time steps proba=0.6;%probability to switch state Define parameters in the first part!!

23 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 23 Programming a simulator  Step 5: Final processing % Outputs and final processing propAlive = sum(states)/length(states); And return propAlive as the output of the simulation.

24 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch >> p=simulation() p = 0.54 >> p=simulation() p = 0.72 Programming a simulator  Running simulation

25 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 25 Programming a simulator  Alternatively : a framework for the simulator % Running N simulations N=1000%number of simulation for n=1:N p(n)=simulation(); end Use a framework to run N successive simulation and store the result each time.

26 2010-03-22 A. Johansson & W. Yu / andersj@ethz.ch yuwen@ethz.ch 26 Programming a simulator  Alternatively : a framework for the simulator >> hist(p)


Download ppt "2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©"

Similar presentations


Ads by Google