Modelling and Simulating Social Systems with MATLAB

Slides:



Advertisements
Similar presentations
Section 5-1 Characteristics of Populations
Advertisements

Empirical Model Building I: Objectives: By the end of this class you should be able to: find the equation of the “best fit” line for a linear model explain.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
The General Linear Model. The Simple Linear Model Linear Regression.
CITS2401 Computer Analysis & Visualisation
Development of Empirical Models From Process Data
Density-dependent population growth The concept of an upper limit –K denotes ‘carrying capacity’
Engineering Computation Curve Fitting 1 Curve Fitting By Least-Squares Regression and Spline Interpolation Part 7.
1 Introduction to MatLab MatLab stands for Matrix Laboratory. As the name suggests most of the programming operations have as input or output a matrix.
Ch. 14: The Multiple Regression Model building
Growth and decline. Exponential growth pop. size at time t+  t = pop. size at time t + growth increment N(t+  t) = N(t ) +  N Hypothesis:  N = r N.
1 TEMPLATE MATCHING  The Goal: Given a set of reference patterns known as TEMPLATES, find to which one an unknown pattern matches best. That is, each.
Descriptive Statistics II: By the end of this class you should be able to: describe the meaning of and calculate the mean and standard deviation of a sample.
Lecture 3: Inference in Simple Linear Regression BMTRY 701 Biostatistical Methods II.
Descriptive Statistics I: By the end of this class you should be able to: Palm: Section 7.1, 7.2 Program cords and delays in your music programs plot a.
Physics 114: Exam 2 Review Lectures 11-16
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
L – Modelling and Simulating Social Systems with MATLAB Lesson 2 – Statistics and plotting Anders Johansson and Wenjian Yu © ETH.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5B Model.
The Completely Randomized Design (§8.3)
Sampling Error SAMPLING ERROR-SINGLE MEAN The difference between a value (a statistic) computed from a sample and the corresponding value (a parameter)
Scientific Computing General Least Squares. Polynomial Least Squares Polynomial Least Squares: We assume that the class of functions is the class of all.
L – Modelling and Simulating Social Systems with MATLAB © ETH Zürich | Lesson 3 – Dynamical Systems Anders Johansson and Wenjian.
Today we will learn MATLAB Click Start  All programm  Class Software  Matlab This command window will be seen with a prompt sign >> Any command can.
CHAPTER 4 ESTIMATES OF MEAN AND ERRORS. 4.1 METHOD OF LEAST SQUARES I n Chapter 2 we defined the mean  of the parent distribution and noted that the.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
L – Modeling and Simulating Social Systems with MATLAB Lecture 2 – Statistics and plotting © ETH Zürich | Giovanni Luca Ciampaglia,
EEE 242 Computer Tools for Electrical Engineering
© ETH Zürich | L – Modeling and Simulating Social Systems with MATLAB Lecture 3 – Dynamical Systems © ETH Zürich | Giovanni Luca.
Virtual University of Pakistan
List manipulation;curve fitting
Lecture 16: Image alignment
Physics 114: Lecture 16 Least Squares Fit to Arbitrary Functions
Chapter 4: Basic Estimation Techniques
EXCEL: Multiple Regression
The Maximum Likelihood Method
Physics 114: Lecture 13 Probability Tests & Linear Fitting
Chapter 4 Basic Estimation Techniques
Physics 114: Lecture 18 Least Squares Fit to 2D Data
Linear Algebra Review.
Chapter 7. Classification and Prediction
Statistical Data Analysis - Lecture /04/03
Working with Data in MATLAB
Physics 114: Exam 2 Review Weeks 7-9
Modelling and Simulating Social Systems with MATLAB
Modelling and Simulating Social Systems with MATLAB
L – Modeling and Simulating Social Systems with MATLAB
Modelling and Simulating Social Systems with MATLAB
L – Modeling and Simulating Social Systems with MATLAB
Simple Linear Regression - Introduction
Fitting Linear Functions to Data
Physics 114: Exam 2 Review Material from Weeks 7-11
Introduction to Instrumentation Engineering
LESSON 21: REGRESSION ANALYSIS
Copyright © Cengage Learning. All rights reserved.
6-1 Introduction To Empirical Models
Weighted Least Squares Fit
Modelling data and curve fitting
Ying shen Sse, tongji university Sep. 2016
Population Ecology.
J.-F. Pâris University of Houston
The Simple Linear Regression Model: Specification and Estimation
Continuous distributions
Vectors, matrices, and arithmetic
M248: Analyzing data Block D UNIT D2 Regression.
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.
Amos Introduction In this tutorial, you will be briefly introduced to the student version of the SEM software known as Amos. You should download the current.
Announcements P3 due today
Linear Time Invariant systems
Presentation transcript:

Modelling and Simulating Social Systems with MATLAB 07.05.2018 Modelling and Simulating Social Systems with MATLAB Lesson 3 – 3D plots and population growth A. Johansson & M. Moussaid © ETH Zürich |

Lesson 3 - Contents Repetition Additional plotting commands 07.05.2018 Lesson 3 - Contents Repetition Additional plotting commands 3-dimensions plots Case studies: exponential and logistic growth

Repetition Plotting functions >> x=[0:0.2:10]; >> a=3; 07.05.2018 Repetition Plotting functions >> x=[0:0.2:10]; >> a=3; >> y=a*exp(-x); >> plot(x,y,’b+-’)

Repetition Plotting functions 07.05.2018 Repetition Plotting functions >> xlabel(“X”) >> ylabel(“Y=3*exp(-x)”) >> title(“Plotting a simple function”) 4 4

Repetition Plotting functions >> x=randn(10^4 , 1); 07.05.2018 Repetition Plotting functions >> x=randn(10^4 , 1); >> hist(x); 5 5

Repetition Statistics >> mean(x) >> std(x) >> min(x) 07.05.2018 Repetition Statistics >> mean(x) 0.021 >> std(x) 1.005 >> min(x) -3.797 >> max(x) 4.198 6 6

Plotting Two useful commands >> x=[-5:0.1:5];a=2;b=3; 07.05.2018 Plotting Two useful commands Hold on|off Grid on|off >> x=[-5:0.1:5];a=2;b=3; >> y1=exp(-x.^2); >> y2=a*exp(-x.^2); >> y3=exp(-(x.^2)/b); 7 7

Plotting Two additional useful commands >> plot(x,y1); 07.05.2018 Plotting Two additional useful commands >> plot(x,y1); >> hold on >> plot(x,y2,’r’); >> plot(x,y3,’g’); 8 8

Plotting Two additional useful commands >> plot(x,y1); 07.05.2018 Plotting Two additional useful commands >> plot(x,y1); >> hold on >> plot(x,y2,’r’); >> plot(x,y3,’g’); >> grid on 9 9

Plotting Saving a plot >> hgsave(‘fileName.fig’) 07.05.2018 10

3 dimensions plots Plot a surface surf(X,Y,Z) with: x2 x1 x3 y1 y2 y3 07.05.2018 3 dimensions plots Plot a surface surf(X,Y,Z) with: X a vector containing the x-axis Y a vector containing the y-axis Z a matrix with Z(i,j) is the corresponding value for Y(i) and X(j) Number of lines and columns in Z must respectively equal length(Y) and length(X). x2 x1 x3 y1 y2 y3 z11 z12 z13 z21 z22 z23 z31 z32 z33 11 11

3 dimensions plots Plot a surface >> X=-2:0.1:2; 07.05.2018 3 dimensions plots Plot a surface >> X=-2:0.1:2; >> Y=0:0.1:1; >> Z = Y(2)*exp(-X.^2) Z = 0.0018 0.0027 0.0039 0.0056 >> for i=1:length(Y) Z(i,:)= Y(i)*exp(-X.^2); end 12 12

3 dimensions plots Plot a surface >> surf(X,Y,Z) 07.05.2018 13

3 dimensions plots Plot a surface >> surf(X,Y,Z) 07.05.2018 14

3 dimensions plots Plot a surface >> surf(X,Y,Z) 07.05.2018 15

3 dimensions plots Plot a surface 07.05.2018 3 dimensions plots Plot a surface >> contourf(X,Y,Z) >> contour(X,Y,Z) 16 16

Case 1 Exponential growth 07.05.2018 Case 1 Exponential growth Consider a population that has a constant birth rate through time and is never limited by food or disease. At each new generation the population increases with a given birth rate r This is called an exponential growth: the birth rate alone controls how fast the population grows. Generation 1 Generation 2 Generation 3 Generation 4

Case 1 Exponential growth 07.05.2018 Case 1 Exponential growth An exponential growth can be described as follow: Xt+1 = xt * (1 + r) XT : Size of population at time T r : birth rate 18 18

07.05.2018 Case 2 Logistic growth In most real populations, there is an upper limit to the number of individuals the environment can support. This limit is called the "carrying capacity" of the environment : K Populations in this kind of environment show what is known as logistic growth. Generation 1 Generation 2 Generation 3 Generation 4 19 19

Case 2 Logistic growth The logistic growth can be described as follow: 07.05.2018 Case 2 Logistic growth The logistic growth can be described as follow: Xt+1 = xt exp(r (1-xt/K) ) XT : Size of population at time T r : birth rate K: Carrying capacity 20 20

Application Logistic growth Food NEST 07.05.2018 Application Logistic growth Experimental data: Ants recruitment dynamic Each ant recruit N others Limited space around the food source Data in: antsData.m Food NEST 21 21

Exercise 1 Exponential Growth 07.05.2018 Exercise 1 Exponential Growth Write a function expGrowth.m that computes the population size xT, after T generations. The initial population x0, the birth rate r and the final generation T must be given as function parameters. For an initial population of 10 individuals and a birth rate of 0.1, use the function to compute the population size after T=30, 40 and 50 generations. Modify the function so that it returns a vector ST that contains the sequence x0, x1, x2, … xT. Plot S30 (with the same parameters). On the same figure plot S30 for r = -0.05, 0, 0.05, 0.1 . Set title, axis names and save the file. Download and launch file exercise1.m . Read the code and understand how it works. Add some comments. 22 22

Exercise 2 Logistic Growth 07.05.2018 Exercise 2 Logistic Growth Write a function logGrowth.m that compute the evolution of population size ST, after T generations. The initial population x0, the birth rate r, the capacity K and the final generation T must be given as function parameters. Consider x0=10 , r=0.3 , and K = 500 , plot evolution of population after T=30. On a new plot, draw the evolution of population size for r=0.3, 0.5, 1, 1.5, and 2. What can you say about the overall dynamic? How do you interpret it? Use the functions surf or contourf to determine the critical value of r beyond which the stationary dynamic switch to an oscillatory dynamic. In order to do so, build and plot a matrix that contains the evolution of population during 30 generations with r varying from 0.3 to 2.5 with a step of 0.01 23 23

Exercise 3 Ants recruitment 07.05.2018 Exercise 3 Ants recruitment Download the data file antsData.m and read the data description written into the file. On the same plot, represent the data from the 5 experiments: number of ants as a function of time. Use the option ‘.’ to plot dots instead of lines. Build a vector called avgAnts of length 15 that contains the average value of the 5 experiments at each time step. Always on the same plot, draw the vector avgAnts in red. Try to estimate the recruitment rate r and the capacity K. Choose x0=6 and T=15. 24 24

Exercise 4 (optional) Ants recruitment : least-square fitting 07.05.2018 Exercise 4 (optional) Ants recruitment : least-square fitting The ‘trial and error' approach is obviously not the best way to fit a curve. The least squares method assumes that the best-fit curve is the one that has the minimal sum of the squared deviations from a given set of data. 1. Build a function lsDeviation that computes the least-square error for a given set of parameters, as follow: ls = lsDeviation (observedData, r,K,x0,T) where observedData is the observed mean values vector (use the vector avgAnts from exercise3) r,K,x0,T is a given set of parameters ls is the sum of the squared deviations between observed data and the theoretical data at each time step: ls = ( avgAnts(i) - S(i) ) 2 with S = logGrowth(x0,r,K,T) 25 25

Exercise 4 (optional) Ants recruitment : least-square fitting 07.05.2018 Exercise 4 (optional) Ants recruitment : least-square fitting For r = 0.1:0.01:1 and K=50:250 compute and plot the matrix LS , defined as : LS(i,j) = lsDeviation(avgAnts, r(i), K(j) , x0 , T) Choose x0=6 and T=15; What is the minimum value of LS? What are the corresponding optimal parameters r and K ? 26 26