55
Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

  • View
    216

  • Download
    3

Embed Size (px)

Citation preview

Page 1: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Stochastic modelling and Monte Carlo Simulation

Derek Karssenberg

Page 2: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

stochastic modelsStochastic and deterministic models

Deterministic model• no ‘probabilities’ involved• each time the model is run, the outcome is exactly the same• example: LIFE, practicals: snow melt model

Stochastic model• includes probabilistic rules or stochastic variables• each time the model is run, the outcome will be (slightly) different• example: practicals: plant seed dispersal

Page 3: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

stochastic modelsWhat is a probability?

Example: a coin

It is generally assumed that the probability for a head is 0.5:

P(head) = 1/2 = 0.5

Note that a coin has two ‘equal’ sides, both with the same probability

Page 4: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

what is probabilityWhat is a probability?

Example: a die

P(2) = 1/6 = 0.166666666

The probability of getting a 2 is 0.16666

Note that a die has six ‘equal’ sides, all with the same probability

Page 5: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

what is probabilityLaplace definition

withP(A) probability of A|A| number of points (outcomes) of A|S| total number of points (outcomes). i.e., the sample space

Note that

P(S) = 1

Page 6: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

what is probabilityLaplace definition

die:

Page 7: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

what is probabilityWhat is probability: viewpoint of experiments

We have a population of 180.000 people60.000 people are smokers

Page 8: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

what is probabilityWhat is probability: viewpoint of experiments

In general:

withP(A) probability that A occursn number of experimentsnA number of times that A occurred

Page 9: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

what is a stochastic variableWhat is a stochastic (i.e., random) variable?

A variable with a value depending on chance• discrete stochastic variables (i.e. classified values)• continuous stochastic variables (i.e. scalar values)

Example of a discrete stochastic variable: a die

The variable can have a value 1, 2, 3, 4, 5, or 6

The value depends on chance!

Page 10: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Probability function f of a discrete stochastic variable

Gives the probability for each possible value

Page 11: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Probability function of a discrete stochastic variable

Example: die

Page 12: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Cumulative distribution function F of a discrete stochastic variable

Page 13: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Cumulative distribution function F of a discrete stochastic variable

Probability function

Cumulative distribution function

Page 14: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Probability function f of a continuous stochastic variable

f(x) is a continous function, e.g. normal distribution

f(x)

Page 15: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Probability function f of a continuous stochastic variable

f(x) is a continous function, e.g. uniform

Page 16: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Cumulative distribution function F of a continuous stochastic variable

Page 17: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Cumulative distribution function F of a continuous stochastic variable

Probability function

Cumulative distributionfunction

Page 18: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Cumulative distribution function F of a continuous stochastic variable

Probability function

Cumulative distributionfunction

f(x)

F(x)

Page 19: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Probability corresponding to an interval

F(x)

F(-2)

F(-3)

Page 20: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Probability corresponding to an interval

f(x)

Page 21: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

what is a stochastic variableStochastic variables, notation rules

uppercase letter random variablelowercase letter outcome (realization) of the random variable

e.g., Z and z

For instance,- a random variable has a certain probability distribution with a mean and a variance, while- the realization of it is a single value, e.g. 4.23123

Page 22: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

stochastic variables in PCRasterDrawing a realization of a continuous stochastic variable

Non spatial case (map of 1 cell!)

..

dynamic # draw a realization from a stochastic continuous variable, # with uniform distribution between 0 and 1 Value=uniform(Clone);

report value.tss=timeoutput(Clone,Value);

Page 23: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

stochastic variables in PCRasterDrawing a realization of a stochastic variable

.

dynamic # draw a realization from a stochastic continuous variable, # with uniform distribution between 0 and 1 Value=uniform(Clone); report value.tss=timeoutput(Clone,Value);

Page 24: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

stochastic variables in PCRasterDrawing a realization of a discrete stochastic variable

non spatial case

...

dynamic # draw a realization from a stochastic continuous variable, # with uniform distribution between 0 and 1 Value=uniform(Clone); # get a realization of a value of a stochastic discrete

# variable, a dice outcome of 2 ATwo=Value lt (1/6);

report value.tss=timeoutput(Clone,Value); report atwo.tss=timeoutput(Clone,ATwo);

Page 25: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

stochastic variables in PCRasterDrawing a realization of a discrete stochastic variable

non spatial case

...

dynamic # draw a realization from a stochastic continuous variable, # with uniform distribution between 0 and 1 Value=uniform(Clone); # get a realization of a value of a stochastic discrete

# variable, a dice outcome of 2 ATwo=Value lt (1/6);

report value.tss=timeoutput(Clone,Value); report atwo.tss=timeoutput(Clone,ATwo);

Page 26: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

stochastic variables in PCRasterDrawing a realization of a stochastic variable

spatial case

script is the same, but realizations are drawn for each cell separately

...

dynamic # draw a realization from a stochastic continuous variable, # with uniform distribution between 0 and 1 Value=uniform(Clone); # get a realization of a value of a stochastic discrete

# variable, a dice outcome of 2 ATwo=Value lt (1/6);

report value.tss=timeoutput(Clone,Value); report atwo.tss=timeoutput(Clone,ATwo);

Page 27: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

stochastic variables in PCRasterDrawing a realization of a stochastic variable

spatial case

...

dynamic # draw a realization from a stochastic continuous variable, # with uniform distribution between 0 and 1 Value=uniform(Clone); # get a realization of a value of a stochastic discrete

# variable, a dice outcome of 2 ATwo=Value lt (1/6);

report value.tss=timeoutput(Clone,Value); report atwo.tss=timeoutput(Clone,ATwo);

Page 28: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

stochastic variables in PCRasterDrawing a realization of a stochastic variable

demo die

aguila –2 Value00.001+20 ATwo0000.001+20

Page 29: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

introductionReasons for using stochasticity in a model

1) Many processes are difficult to describe with deterministic rules

2) Inputs and parameters are associated with uncertaintyeffect of this uncertainty on the model output can be calculated when these are represented by stochastic variables => error propagation modelling

Page 30: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

forest fire modelA simple forest fire model

One boolean variable: TRUE (= fire) or FALSE (= not yet burning)

Uses the Neumann neighborhood

Page 31: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

forest fire modelA simple forest fire model

Transition rule:

• a cell catches fire with a probability P if at least one of its Neumann neighbors is burning• else the state of the cell does not change

Page 32: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

forest fire modelA simple forest fire model

..

initial Uniform=uniform(1);

Fire=order(Uniform) lt 5; # starting points

dynamic CellsNotBurningSurroundedByFire=

(window4total(scalar(Fire)) gt 0) and not Fire; NewFire=CellsNotBurningSurroundedByFire

and (uniform(Clone) lt P); Fire=Fire or NewFire;

Page 33: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

forest fire modelA more complicated forest fire model

Demo forest_fire_part1

aguila –2 fire0000.001+1000

Page 34: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

forest fire modelA more complicated forest fire model

Three possible states:0 no trees in cell (burnt down)1 trees in cell2 fire in cell

Transition rules:• a cell catches fire with a probability P if at least one of its

Neumann neighbors is burning• an empty cell sprouts trees with a probability F• a burning tree burns down and becomes an empty site

Page 35: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

forest fire modelClone=clone.map;

TreeIni=ini.map; # 0, empty; 1, tree; 2, fire

p=0.1; # prob. that an empty site sprouts a tree

g=0.01; # immunity for fire probability

timer

1 100 1;

initial

Uniform=uniform(1);

Tree=if(Uniform lt 0.33,nominal(1),if(Uniform gt 0.66,2,0));

report TreeIni=Tree;

...

Page 36: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

forest fire model...

dynamic

report tree=lookupnominal(tree.tbl,Tree);

# rule 1

NewSprouts=(uniform(1) lt p) and (Tree eq 0);

# rule 2

Fire=Tree eq 2;

NewFireClonal=(window4total(scalar(Fire)) gt 0) and (Tree eq 1) and (uniform(1) lt (1-g));

# rule 3

BurnDown=Tree eq 2;

# combine rules

Tree=if(NewSprouts,1,Tree);

Tree=if(NewFireClonal,2,Tree);

Tree=if(BurnDown,0,Tree);

Page 37: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

forest fire modelA more complicated forest fire model

Demo forest_fire_part2

aguila –2 tree0000.001+1000

Page 38: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Error propagation modelling using Monte Carlo simulation

Derek KarssenbergUtrecht University, the Netherlands

Page 39: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingDynamic deterministic model

z state variablesi inputs

f functionals

p parameters

This is a deterministic model:- all inputs, parameters are exactly known- functional is deterministic (no probabilistic rules)

Each time the model is run, it generates exactly the same output

Page 40: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingThe problem of uncertainty

If:

i (inputs) are are not exactly known?e.g., amount of rain is between a and b

or p (parameters) are not exactly known?

e.g., saturated conductivity is on average a plus/minus bor f (functionals) use probabilistic rules?

e.g. plant dispersal model

Then:z is not exactly known either

z(t +1) =f z(t), i(t),p,t( ) for each t

Page 41: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingDealing with uncertainty

Represent inputs or parameters and variables as stochastic entities

becomes:

Z state variables; stochastic variables, spatial)I inputs; stochastic variables, spatial (or non-spatial)f functional

P parameters; stochastic variables, spatial (or non-spatial)

z(t +1) =f z(t), i(t),p,t( ) for each t

Page 42: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

introductionExample model

• Rainfall (timeseries)

• Infiltrationconstant infiltration capacityparameter: KSat (mm/h)

• RunoffManning equation (kinematic wave)parameter: n

timestep: 10 seconds, cellsize 10 m

Page 43: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingExample model, deterministic version

• Rainfall (timeseries)

• Infiltrationconstant infiltration capacityparameter: KSat (mm/h) = 23 mm/h

• RunoffManning equation (kinematic wave)parameter: n = 0.033

timestep: 10 seconds, cellsize 10 m

CALCULATE HYDROGRAPH BY RUNNING THE MODEL ONCE

Page 44: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingExample model, stochastic version

Keep everything the same, but represent saturated conductivity as a stochastic variable

KSat (mm/h), stochastic variable (non-spatial, i.e. everywhere the same value):

- probability distribution is normal- meanKSat = 23 mm/h

- varianceKSat = 3 mm/h

WHAT IS THE HYDROGRAPH?

HOW DO WE CALCULATE IT?

Page 45: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modelling

one parameter (Ksat)is stochastic

inputs are deterministic

(most) variablesbecome stochastic

WHAT IS Zdischarge (i.e., the HYDROGRAPH)?

HOW DO WE CALCULATE IT?

Page 46: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingMonte Carlo approach for running a stochastic model

Define a number of Monte Carlo loops N (e.g., N=1000)

Three steps:

1) Generate N sets of realizations of each of the stochastic variables (inputs and parameters)

2) Run the dynamic model with each set of realizations (i.e., N times) and store the N outcomes

3) Calculate sample statistics of the N outcomes

Page 47: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingExample model, first step

1) Generate N sets of realizations of each of the stochastic variables (inputs and parameters)

One stochastic variable KSat (mm/h):- probability distribution is normal- meanKSat = 23 mm/h

- varianceKSat = 3 mm/h

1st ‘set’, KSat = 22.22nd ‘set, KSat = 18.23rd ‘set’, KSat = 26.4

.

.

.1000nd ‘set’, KSat = 19.2

Page 48: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingExample model, second step

2) Run the dynamic model with each set of realizations (i.e., N times) and store the N outcomes

1st ‘set’, KSat = 22.2 => run model, store outcome:

2nd ‘set, KSat = 18.2 => run model, store outcome:

3rd ‘set’, KSat = 26.4 => run model, store outcome:.....

1000nd ‘set’, KSat = 19.2 => run model, store outcome:

Page 49: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingExample model, second step

hydrographs

3 hours

dis

charg

e,

m3/

s

Page 50: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingExample model, third step

3) Calculate sample statistics of the N outcomes

KSat = 22.2 => outcome:

KSat = 18.2 => outcome:

KSat = 26.4 => outcome:.....

KSat = 19.2 => outcome:

For each time stepcalculateof the discharge the

average standard deviation median quartiles etc..

Page 51: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingExample model, third step

3 hours

dis

charg

e,

m3/

s

first quartile (25th percentile)

median (50th percentile)

third quartile (75th percentile)

Page 52: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

Example model, third step

the outcome (statistics) represents Zdischarge

error propagation modelling

3 hours

dis

charg

e,

m3/

s

first quartile (25th percentile)

median (50th percentile)

third quartile (75th percentile)

Z(t +1) =f Z(t), i(t),P,t( ) for each t

Page 53: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingIn which cases is Monte Carlo simulation used

1. Error propagation modelling

- inputs or parameters are measured and we know the error associated with these

- represent these inputs or parameters as a stochastic variable

- perform Monte Carlo simulation

- result: model output with error bands

Page 54: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingIn which cases is Monte Carlo simulation used

2. Global sensitivity analysis

- assume certain variation in input parameter

- represent this variation as a stochastic variable

- perform Monte Carlo simulation

- result: model output with its variation

- variation represents sensitivity to the parameter under consideration

Page 55: Stochastic modelling and Monte Carlo Simulation Derek Karssenberg

error propagation modellingIn which cases is Monte Carlo simulation used

3. Probabilistic models

- f includes stochastic rules (e.g. plant dispersal model)

- perform Monte Carlo simulation

- result: model output with its variation

- variation represents ‘behaviour’ of the model