Stochastic modelling and Monte Carlo Simulation Derek Karssenberg.

Post on 22-Dec-2015

216 views 3 download

Transcript of Stochastic modelling and Monte Carlo Simulation Derek Karssenberg.

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

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

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

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

what is probabilityLaplace definition

die:

what is probabilityWhat is probability: viewpoint of experiments

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

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

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!

Probability function f of a discrete stochastic variable

Gives the probability for each possible value

Probability function of a discrete stochastic variable

Example: die

Cumulative distribution function F of a discrete stochastic variable

Cumulative distribution function F of a discrete stochastic variable

Probability function

Cumulative distribution function

Probability function f of a continuous stochastic variable

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

f(x)

Probability function f of a continuous stochastic variable

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

Cumulative distribution function F of a continuous stochastic variable

Cumulative distribution function F of a continuous stochastic variable

Probability function

Cumulative distributionfunction

Cumulative distribution function F of a continuous stochastic variable

Probability function

Cumulative distributionfunction

f(x)

F(x)

Probability corresponding to an interval

F(x)

F(-2)

F(-3)

Probability corresponding to an interval

f(x)

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

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);

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);

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);

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);

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);

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);

stochastic variables in PCRasterDrawing a realization of a stochastic variable

demo die

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

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

forest fire modelA simple forest fire model

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

Uses the Neumann neighborhood

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

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;

forest fire modelA more complicated forest fire model

Demo forest_fire_part1

aguila –2 fire0000.001+1000

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

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;

...

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);

forest fire modelA more complicated forest fire model

Demo forest_fire_part2

aguila –2 tree0000.001+1000

Error propagation modelling using Monte Carlo simulation

Derek KarssenbergUtrecht University, the Netherlands

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

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

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

introductionExample model

• Rainfall (timeseries)

• Infiltrationconstant infiltration capacityparameter: KSat (mm/h)

• RunoffManning equation (kinematic wave)parameter: n

timestep: 10 seconds, cellsize 10 m

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

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?

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?

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

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

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:

error propagation modellingExample model, second step

hydrographs

3 hours

dis

charg

e,

m3/

s

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..

error propagation modellingExample model, third step

3 hours

dis

charg

e,

m3/

s

first quartile (25th percentile)

median (50th percentile)

third quartile (75th percentile)

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

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

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

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