2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 –...

24
2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

Transcript of 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 –...

Page 1: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04

851-0585-04L – Modelling and Simulating Social Systems with MATLAB

Lesson 7 – Continuous simulations

Wenjian Yu

© ETH Zürich |

Page 2: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected] 2

Lesson 6 - Contents

Micro-macro link

Some basis of motion dynamics

Pedestrian simulation

Page 3: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Drunkard’s Walk

The drunkard takes a series of steps away from

the lamp post, each with a random angle.

3

(Figure Resource: Sethna JP, 2006)

Page 4: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Random Walk and Diffusion Equation

4

Consider a general, uncorrelated random walk where at

each time step the particle’s position changes by

a step :

The probability distribution for each step is , which

has zero mean and standard deviation .

t

).()()( tltxttx )(tl

)(tx

)(lD

Page 5: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

For the particle to go from at time to at time ,

the step . Such event occurs with probability

times the probability density . Therefore,

we have

5

'x t x tt

')( xxtl

)'( xxD ),'( tx

dzzDtzx

dxxxDtxttx

)(),(

')'(),'(),(

'xxz

Page 6: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

The Micro-Macro Link

Use Taylor expansion, we have

6

22

2

22

2

2

22

2

1),(

)(2

1)()(),(

)(]2

),([),(

xtx

dzzDzx

dzzzDx

dzzDtx

dzzDx

z

xztxttx

tt

txttx

),(),(

2

22

2 xtt

The following is the diffusion equation

Page 7: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

The Continuous Assumption

7

Resources: Google

Page 8: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

From discreet to continuous space

Cellular automaton (CA)

Continuous simulation

Page 9: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

Agents are characterized by

Their position

- X (m)

- Y (m)

Their velocity

- Vx (m/s)

- Vy (m/s)

x

y

Vx

Vy

Page 10: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

Next position after 1 second

is given by:

x(t+1) = x(t) + Vx(t)

y(t+1) = y(t) + Vy(t)

x

y

Vx

Vy

Time t

Time t+1

Page 11: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

Time step dt is often different

from 1:

x(t+dt) = x(t) + dt*Vx(t)

y(t+dt) = y(t) + dt*Vy(t)

x

y

Vx

Vy

Time tTime t+dt dt<1

Time t+dt dt>1

Page 12: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

The velocity is also updated in

time.

x

y

Page 13: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

The velocity changes as a result

of inter-individual interactions

Repulsion

Attraction

Examples: atoms, planets,

pedestrians, animals swarms…

Page 14: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

The changes of velocity vector is

defined by an acceleration.

Page 15: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

The velocity changes as a result

of interactions with the

environment

Repulsion

Attraction

Examples: bacteria, ants,

pedestrian trails …

Page 16: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

The velocity changes as a result

of a random process

With or without bias

Examples: exploration behaviour

in many species of animals

Page 17: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

How to define a random move?

Choose a random angle in a

normal distribution

Rotate the velocity by this angle

In Matlab:

newAngle = randn()

Mean=0

Variance=1

Page 18: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

How to define a random move?

Choose a random angle in a

normal distribution

Rotate the velocity by this angle

In Matlab:

meanVal=2;

v=0.1;

newAngle = meanVal + v*randn()

Page 19: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Modelling agent’s motion in a continuous space

How to define a BIASED random

move?

Unbalance the distribution

toward positive or negative

values

In Matlab:

meanVal=2;

v=0.1;

newAngle = meanVal + v*randn()

Page 20: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected]

Programming the simulator

X = [1 1 3 ]; Y = [2 1 1];Vx = [0 0 0.1];Vy = [1 1 0.5];

For t=1:dt:T

For p=1:N

[Vx(p) Vy(p)] = update( …) ;

X(p) = X(p) + dt*Vx(p) ; Y(p) = Y(p) + dt*Vy(p) ;

endend

Initialization: Four

elements are required to

define the state of

individuals

The velocity is updated

first, and then the

position as a function of

the velocity and the time

step

Page 21: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected] 2121

Brownian Motion%Brownian Motiont = 100;n = 1000;dt=t/n;x = zeros(1,n);y = zeros(1,n);dx = zeros(1,n);dy = zeros(1,n);x(1) = 0;y(1) = 0;hold on;k = 1;for j=2:n x(j) = x(j-1) + sqrt(dt)*randn; y(j) = y(j-1) + sqrt(dt)*randn; plot([x(j-1),x(j)],[y(j-1),y(j)]); M(k) = getframe; k = k + 1;end

Page 22: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected] 22

Pedestrian Simulation

CA model

Many-particle model

Page 23: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected] 23

CA Model (A. Kirchner, A. Schadschneider, Phys. A, 2002)

Page 24: 2010-12-04 851-0585-04L – Modelling and Simulating Social Systems with MATLAB Lesson 7 – Continuous simulations Wenjian Yu © ETH Zürich |

2010-12-04 W. Yu / [email protected] 24

Many-particle Model (Helbing, Nature, 2000)

Desired velocityRepulsive force