Modelling and Simulating Social Systems with MATLAB

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

Bison Management Suppose you take over the management of a certain Bison population. The population dynamics are similar to those of the population we.
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
Solve for x. 28 = 4(2x + 1) = 8x = 8x + 8 – 8 – 8 20 = 8x = x Distribute Combine Subtract Divide.
VK Dice By: Kenny Gutierrez, Vyvy Pham Mentors: Sarah Eichhorn, Robert Campbell.
Controlled Assessment
Matlab tutorial course Exercises 4:. Exercises – for loops Download the scripts loops_example.m and if_else_example.m, run the code Download the function,
Horse race © Horse race: rules 1.Each player chooses a horse and puts it into a stall. Write your name next to the.
Minority Games A Complex Systems Project. Going to a concert… But which night to pick? Friday or Saturday? You want to go on the night with the least.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Probability And Expected Value ————————————
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 8 Multidimensional.
1 An introduction to programming concepts with Scratch.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Functions Part I.
Bell Work A card is drawn at random from the cards shown and not replaced. Then, a second card is drawn at random. Find each probability. 1. P(two even.
Check it out! : Simple Random Sampling. Players of a dice game roll five dice and earn points according to the combinations of numbers they roll.
Chapter 9: Simulation Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Agent Based Modeling and Simulation
Chapter 6: User-Defined Functions I Instructor: Mohammad Mojaddam
Scratch Internet- Open Chrome hit “Create” 1.
MOM! Phineas and Ferb are … Aims:
L – Modelling and Simulating Social Systems with MATLAB Lesson 5 – Introduction to agent-based simulations A. Johansson & W. Yu ©
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
Exploring Complex Systems through Games and Computer Models Santa Fe Institute – Project GUTS
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions (Header files and Library Functions) Outline.
Controlling the Behavior of Swarm Systems Zachary Kurtz CMSC 601, 5/4/
Activity 1: Play Fours Play in pairs Each player has a 3 by 3 grid Take turns to roll 2 dice Calculate the total- each spot is worth 4 points Write your.
Matlab tutorial course Lesson 4: Writing your own functions: programming constructs
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
Structured Programming II: If Statements By the end of this class you should be able to: implement branching in a program describe and use an “if” statement.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
LISTS. LEARNING OBJECTIVES Create a block that accepts a parameter Create a block that returns a value Create scripts that manipulates lists Incorporate.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 1 Monday 13 Oct 2014 EGR 115 Introduction to Computing for Engineers.
SCRIPTS AND FUNCTIONS DAVID COOPER SUMMER Extensions MATLAB has two main extension types.m for functions and scripts and.mat for variable save files.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Statistics 11 Understanding Randomness. Example If you had a coin from someone, that they said ended up heads more often than tails, how would you test.
Objective of the lesson Use Blockly to make a dice for Snakes and Ladders All of you will: – Make an image which displays when you press a button Most.
Modelling and Simulating Social Systems with MATLAB
L – Modeling and Simulating Social Systems with MATLAB
Modelling and Simulating Social Systems with MATLAB
Determining the theoretical probability of an event
Number guessing game Pick a random number between 1 and 10
L – Modeling and Simulating Social Systems with MATLAB
Student Activity 1: Fair trials with two dice
Chapter 5 - Functions Outline 5.1 Introduction
CS005 Introduction to Programming
Learning to Program in Python
© Akhilesh Bajaj, All rights reserved.
Computer-Mediated Communication
Probability And Expected Value ————————————
Lesson Objectives Aims You should be able to:
Truth tables: Ways to organize results of Boolean expressions.
Introduction to TouchDevelop
Matlab tutorial course
Truth tables: Ways to organize results of Boolean expressions.
Writing Functions( ) (Part 4)
Matthew Renner, Trish Beeksma, Patch Kenny
Probability And Expected Value ————————————
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Console.WriteLine(“Good luck!”);
Truth tables: Ways to organize results of Boolean expressions.
‘If’ statements, relational operators, and logical operators
Probability using Simulations
Hiroki Sayama NECSI Summer School 2008 Week 2: Complex Systems Modeling and Networks Agent-Based Models Hiroki Sayama
Drift and Sounder* Analytics
Matlab tutorial course
Programming Fundamental
Presentation transcript:

Modelling and Simulating Social Systems with MATLAB 07.05.2018 Modelling and Simulating Social Systems with MATLAB Lesson 4 – Introduction to Agent-based simulations A. Johansson & W. Yu © ETH Zürich |

Lesson 4 - Contents Swarm intelligence 07.05.2018 Lesson 4 - Contents Swarm intelligence Human cooperation and coordination How to develop a multi-agent simulator Exercises

Swarm Intelligence Decentralization Interaction Self-organization

Boids (Reynolds,1986)

More information: http://www.red3d.com/cwr/boids/ 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

Human Cooperation Prisoner’s dilemma 15,15 20,0 0,20 19,19

The Evolution of Cooperation (Axelrod,1984) Tit for tat Shadow of the future

Coordination 1,1 0,0

Learning Imitation Reinforcement Best reply

From Factors to Actors (Macy,2002) Agents are autonomous Agents are interdependent Agents follow simple rules Agents are adaptive and backward-looking

Programming a simulator 07.05.2018 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… 11 11

Programming a simulator 07.05.2018 Programming a simulator Agent based simulations State update According to set of behavioral rules Time t Time t + dt Characterized by a state (or states) (location, dead/alive, color, level of excitation) New state Time line T1 T2 dt 12 12

Programming a simulator 07.05.2018 Programming a simulator Agent based simulations State update According to set of behavioral rules, including neighborhood Time t Time t + dt Characterized by a state (location, dead/alive, level of excitation) New state Time line T1 T2 13 13

Programming a simulator 07.05.2018 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 Agents loop end Update state Save data 14 14

Programming a simulator 07.05.2018 Programming a simulator Step 1: Defining the initial state & parameters % Initial state t0=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… 15 15

Programming a simulator 07.05.2018 Programming a simulator Step 1: Defining the initial state & parameters % Initial state t0=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); 16 16

Programming a simulator 07.05.2018 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 17 17

Programming a simulator 07.05.2018 Programming a simulator Step 3: Covering each agent % agent loop For i=1:length(States) What happen for each agent? end 18 18

Programming a simulator 07.05.2018 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!! 19 19

Programming a simulator 07.05.2018 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!! 20 20

Programming a simulator 07.05.2018 Programming a simulator Step 4: Updating agent i at time t % Initial state t0=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!! 21 21

Programming a simulator 07.05.2018 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. 22 22

Programming a simulator Running simulation >> p=simulation() p = 0.54 0.72

Programming a simulator 07.05.2018 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. 24 24

Programming a simulator 07.05.2018 Programming a simulator Alternatively : a framework for the simulator >> hist(p) 25 25

A simple dice game The rules: 07.05.2018 A simple dice game The rules: Each player throws 2 dice and gain a number of points equal to the sum of the two dice. If the dice produce the same value, the score is double. 2 ; 5 : 7 Normal score 4 ; 4 : 8 x 2 = 16 Bonus score The players roll the dice N times, in turn. Each one cumulate his points. The player that has the best score after N rolls win.

A simple dice game The cheater: 07.05.2018 A simple dice game The cheater: There is a cheater among the players. This cheater own some special dice that have a higher probability to produce the same value. In a multi-agents simulation, each player would be an agent characterized by his score, and his behaviour (cheater or fair player). We now develop this simulation… 27 27

Exercise 1 The behaviour of a fair player: 07.05.2018 Exercise 1 The behaviour of a fair player: Write a function called fairRoll.m that returns the score of a fair player: Inputs : nothing Outputs: the score S Write the function in 3 steps: (1) simulate the rolling of dice n°1 and dice n°2, (2) calculate the sum, (3) check if the two values are the same and, in that event, double the sum to get the final score. Hints : The command rand()*6 returns a random value between 0 and 6 The function ceil(n) returns the nearest integer greater than or equal to n Combine them to get a random integer value between 1 and 6. 28 28

Exercise 2 The dice game with fair players 07.05.2018 Exercise 2 The dice game with fair players Use the template file simulation.m to build the simulator Initialization: set variables N=100 agents, T=50 time steps, and a vector called score of length N, used to store the score of each player (initial values set to zero). In the update section, use the function fairRoll.m to update the score of player n Return the final vector score as an output. Run the simulation. What is the mean score of all players at the end of the game? Use the function max(score) to determine who is the winner. 29 29

Exercise 3 The behaviour of a cheater: 07.05.2018 Exercise 3 The behaviour of a cheater: Write a function called cheatRoll.m that return the score of a cheater: Inputs : a variable called probaCheat representing the probability to have a successful cheat. Outputs: the final score S Hints Write your code in four steps : Determine the value of the first dice Pick a random number between 0 and 1, the cheat is successful if this number is lower then probaCheat Determine the value of the second dice according to step 2. Calculate and return the score S 30 30

Exercise 4 The dice game with one cheater: 07.05.2018 Exercise 4 The dice game with one cheater: Go back to your simulator. In the initialization section, add a new state called behaviour with length(behaviour)=N , behaviour(i)=1 if player i is a cheater and behaviour(i)=0 if i is a fair player. Set player n°1 as a cheater and all the others as fair players. Modify the update section in order to call either fairRoll or cheatRoll, with respect to the behaviour of the player n . Set the value of probaCheat to 0.6 (ideally, set it as a parameter in the initialization section). Run the simulation. Who is the winner? What is the score of the cheater and the average score of the fair players? 31 31

Exercise 5 A framework for the simulator: Create a new script file. 07.05.2018 Exercise 5 A framework for the simulator: Create a new script file. Use a for loop to repeat S times the simulation. At the end of each simulation, store the id of the winner (the cheater has its id=1). What is the winning rate of the cheater after S=100 games? Try to change the probability of successful cheating (probaCheat) to reduce the winning rate to 75%. 32 32

Exercise 6 (optional) Interactions and behavioural changes 07.05.2018 Exercise 6 (optional) Interactions and behavioural changes In most of the case, the cheater does not cheat systematically, in order not to be too suspicious. Change the update section again, so that the cheater only use his special dice when another player has a better score than him. Call the functions fairRoll or cheatRoll according to the current score of the cheater. The behaviour vector should eventually be updated as well, in case of a change of strategy. What is the cheater’s new winning rate ? 33 33