Date post: | 31-Dec-2015 |
Category: |
Documents |
Upload: | claud-york |
View: | 213 times |
Download: | 0 times |
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 |
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
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
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
Swarm Intelligence
4
Decentralized control
Interaction and learning
Self-organization
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
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
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
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
Coordination
1,1 0,0
0,0 1,1
9
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected]
Learning
Imitation
Reinforcement
Best reply
10
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
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…
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
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
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
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…
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);
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
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
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!!
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!!
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!!
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.
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
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.
2010-03-22 A. Johansson & W. Yu / [email protected] [email protected] 26
Programming a simulator
Alternatively : a framework for the simulator
>> hist(p)