2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 –...
-
Upload
claud-york -
Category
Documents
-
view
218 -
download
0
Transcript of 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 –...
![Page 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 ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/1.jpg)
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 |
![Page 2: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/2.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
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
![Page 3: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/3.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 3
Lesson 5 - Contents
Swarm intelligence
Human cooperation and coordination
How to develop a multi-agent simulator
![Page 4: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/4.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
Swarm Intelligence
4
Decentralized control
Interaction and learning
Self-organization
![Page 6: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/6.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
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
![Page 7: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/7.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
Human Cooperation
Prisoner’s dilemma
7
15,15 20,0
0,20 19,19
![Page 8: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/8.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
The Evolution of Cooperation (Axelrod,1984)
Tit for tat
Shadow of the future
8
![Page 9: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/9.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
Coordination
1,1 0,0
0,0 1,1
9
![Page 10: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/10.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
Learning
Imitation
Reinforcement
Best reply
10
![Page 11: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/11.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
From Factors to Actors (Macy,2002)
Agents are autonomous
Agents are interdependent
Agents follow simple rules
Agents are adaptive and backward-looking
11
![Page 12: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/12.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 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…
![Page 13: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/13.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 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 T2dt
![Page 14: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/14.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 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
![Page 15: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/15.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 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
![Page 16: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/16.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 16
Programming a simulator
Step 1: Defining the initial state & parameters
% Initial state
t0=0; %begining of the time linedt=1 ; %time stepT=100; %number of time steps
%Initial state of the agentsState1 = [0 0 0 0];State2 = [1 1 1 1];etc…
![Page 17: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/17.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 17
Programming a simulator
Step 1: Defining the initial state & parameters
% Initial state
t0=0; %begining of the time linedt=1 ; %time stepT=100; %number of time steps
%Initial state of the agentsState1 = zeros(1,50);State2 = rand(1,50);
![Page 18: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/18.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 18
Programming a simulator
Step 2: Covering each time step
% time loop
For t=t0:dt:T
What happen at each time step?- Update environment- Update agents
end
![Page 19: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/19.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 19
Programming a simulator
Step 3: Covering each agent
% agent loop
For i=1:length(States)
What happen for each agent?
end
![Page 20: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/20.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 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;
elseState(i)=0;
end
Use sub-functions for better organization!!
![Page 21: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/21.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 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;
elseState(i)=0;
end
Define parameters in the first part!!
![Page 22: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/22.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 22
Programming a simulator
Step 4: Updating agent i at time t
% Initial state
t0=0; %begining of the time linedt=1 ; %time stepT=100; %number of time stepsproba=0.6; %probability to switch state
Define parameters in the first part!!
![Page 23: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/23.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 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.
![Page 24: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/24.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
>> p=simulation()
p =
0.54
>> p=simulation()
p =
0.72
Programming a simulator
Running simulation
![Page 25: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/25.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 25
Programming a simulator
Alternatively : a framework for the simulator
% Running N simulations
N=1000 %number of simulation
for n=1:Np(n)=simulation();
end
Use a framework to run N successive simulation and store the result each time.
![Page 26: 2010-03-22 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©](https://reader034.fdocuments.net/reader034/viewer/2022051820/56649eb35503460f94bbaaf0/html5/thumbnails/26.jpg)
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 26
Programming a simulator
Alternatively : a framework for the simulator
>> hist(p)