SlideShare a Scribd company logo
Simulation: a ubiquitous tool for statistical computation
Statistique exploratoire (NOISE)
introduction to computer language R
rudiments of simulation (aka Monte Carlo methods)
illustration by the boostrap method
Simulation: a ubiquitous tool for statistical computation
Organisation
weekly computer labs using R and Rstudio
one computer account per student
midterm and final exams on anonymous account
exam made of programming problems (e.g., 3 out of 6)
exam evaluation based on executable R code
handouts and on-line help available on anonymous account
no other document
Simulation: a ubiquitous tool for statistical computation
Reference
documents on
https://www.ceremade.dauphine.fr/~xian/Noise.html
R. Drouihlet, P. Lafaye de Micheaux & B. Liquet (2010) Le
logiciel R Springer, Paris
C. Robert & G. Casella (2007) Introduction to Monte Carlo
Methods with R Springer, New York
Manuals on http://cran.r-project.org/manuals.html
(CRAN is the Comprehensive R Archive Network)
Simulation: a ubiquitous tool for statistical computation
Simulation: a ubiquitous tool for statistical
computation
Christian P. Robert
Universit´e Paris-Dauphine
http://www.ceremade.dauphine.fr/~xian
September 26, 2013
Simulation: a ubiquitous tool for statistical computation
Outline
Simulation, what’s that for?!
Producing randomness by deterministic means
Monte Carlo principles
Simulated annealing
Simulation: a ubiquitous tool for statistical computation
Simulation, what’s that for?!
Illustrations
Necessity to “(re)produce chance” on a computer
Evaluation of the behaviour of a complex system (network,
computer program, queue, particle system, atmosphere,
epidemics, economic actions, &tc)
[ c Office of Oceanic and Atmospheric Research]
Simulation: a ubiquitous tool for statistical computation
Simulation, what’s that for?!
Illustrations
Necessity to “(re)produce chance” on a computer
Production of changing landscapes, characters, behaviours in
computer games and flight simulators
[ c guides.ign.com]
Simulation: a ubiquitous tool for statistical computation
Simulation, what’s that for?!
Illustrations
Necessity to “(re)produce chance” on a computer
Determine probabilistic properties of a new statistical
procedure or under an unknown distribution [bootstrap]
(left) Estimation of the cdf F from a normal sample of 100 points;
(right) variation of this estimation over 200 normal samples
Simulation: a ubiquitous tool for statistical computation
Simulation, what’s that for?!
Illustrations
Necessity to “(re)produce chance” on a computer
Validation of a probabilistic model
Histogram of 103
variates from a distribution and fit by this distribution density
Simulation: a ubiquitous tool for statistical computation
Simulation, what’s that for?!
Illustrations
Necessity to “(re)produce chance” on a computer
Approximation of a integral
[ c my daughter’s math book]
Simulation: a ubiquitous tool for statistical computation
Simulation, what’s that for?!
Illustrations
Necessity to “(re)produce chance” on a computer
Maximisation of a weakly regular function/likelihood
[ c Dan Rice Sudoku blog]
Simulation: a ubiquitous tool for statistical computation
Simulation, what’s that for?!
Illustrations
Necessity to “(re)produce chance” on a computer
Pricing of a complex financial product (exotic options)
Simulation of a Garch(1,1) process and of its volatility (103
time units)
Simulation: a ubiquitous tool for statistical computation
Simulation, what’s that for?!
Illustrations
Necessity to “(re)produce chance” on a computer
Handling complex statistical problems by approximate
Bayesian computation (ABC)
core principle
Simulate a parameter value (at random) and pseudo-data from the
likelihood until the pseudo-data is “close enough” to the observed
data, then
keep the corresponding parameter value
[Griffith & al., 1997; Tavar´e & al., 1999]
Simulation: a ubiquitous tool for statistical computation
Simulation, what’s that for?!
Illustrations
Necessity to “(re)produce chance” on a computer
Handling complex statistical problems by approximate
Bayesian computation (ABC)
demo-genetic inference
Genetic model of evolution from a
common ancestor (MRCA)
characterized by a set of parameters
that cover historical, demographic, and
genetic factors
Dataset of polymorphism (DNA sample)
observed at the present time
!""#$%&'()*+,(-*.&(/+0$'"1)()&$/+2!,03!
1/+*%*'"4*+56(""4&7()&$/.+.1#+4*.+8-9':*.+
Différents scénarios possibles, choix de scenario par ABC
Le scenario 1a est largement soutenu par rapport aux
Simulation: a ubiquitous tool for statistical computation
Simulation, what’s that for?!
Illustrations
Necessity to “(re)produce chance” on a computer
Handling complex statistical problems by approximate
Bayesian computation (ABC)
Pygmies population demo-genetics
Pygmies populations: do they
have a common origin? when
and how did they split from
non-pygmies populations? were
there more recent interactions
between pygmies and
non-pygmies populations?
94
!""#$%&'()*+,(-*.&(/+0$'"1)()&$/+2!,03!
1/+*%*'"4*+56(""4&7()&$/.+.1#+4*.+8-9':*.+
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Pseudo-random generator
Pivotal element/building block of simulation: always requires
availability of uniform U (0, 1) random variables
[ c MMP World]
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Pseudo-random generator
Pivotal element/building block of simulation: always requires
availability of uniform U (0, 1) random variables
0.1333139
0.3026299
0.4342966
0.2395357
0.3223723
0.8531162
0.3921457
0.7625259
0.1701947
0.2816627
...
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Pseudo-random generator
Pivotal element/building block of simulation: always requires
availability of uniform U (0, 1) random variables
Definition (Pseudo-random generator)
A pseudo-random generator is a deterministic function f from ]0, 1[
to ]0, 1[ such that, for any starting value u0 and any n, the
sequence
{u0, f(u0), f(f(u0)), . . . , fn
(u0)}
behaves (statistically) like an iid U (0, 1) sequence
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Pseudo-random generator
Pivotal element/building block of simulation: always requires
availability of uniform U (0, 1) random variables
q
q
q
q
q
q
q
q
q
0.0 0.2 0.4 0.6 0.8
0.00.20.40.60.8
xt+1
10 steps (ut , ut+1) of a uniform generator
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Philosophical foray
¡Paradox!
While avoiding randomness, the deterministic sequence
(u0, u1 = f(u0), . . . , un = f(un−1))
must resemble a random sequence!
Debate on whether or not true
randomness does exist (Laplace’s
demon versus Schroedinger’s
cat), in which case pseudo
random generators are not
random (von Neuman’s state of
sin)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Philosophical foray
¡Paradox!
While avoiding randomness, the deterministic sequence
(u0, u1 = f(u0), . . . , un = f(un−1))
must resemble a random sequence!
Debate on whether or not true
randomness does exist (Laplace’s
demon versus Schroedinger’s
cat), in which case pseudo
random generators are not
random (von Neuman’s state of
sin)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Philosophical foray
¡Paradox!
While avoiding randomness, the deterministic sequence
(u0, u1 = f(u0), . . . , un = f(un−1))
must resemble a random sequence!
Debate on whether or not true
randomness does exist (Laplace’s
demon versus Schroedinger’s
cat), in which case pseudo
random generators are not
random (von Neuman’s state of
sin)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Philosophical foray
¡Paradox!
While avoiding randomness, the deterministic sequence
(u0, u1 = f(u0), . . . , un = f(un−1))
must resemble a random sequence!
Debate on whether or not true
randomness does exist (Laplace’s
demon versus Schroedinger’s
cat), in which case pseudo
random generators are not
random (von Neuman’s state of
sin)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
True random generators
Intel circuit producing “truly random” numbers:
There is no reason physical generators should be
“more” random than congruential (deterministic)
pseudo-random generators, as those are valid
generators, i.e. their distribution is exactly known
(e.g., uniform) and, in the case of parallel
generations, completely independent
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
True random generators
Intel generator satisfies all benchmarks of
“randomness” maintained by NIST:
Skepticism about physical devices, when compared
with mathematical functions, because of (a)
non-reproducibility and (b) instability of the device,
which means that proven uniformity at time t does
not induce uniformity at time t + 1
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
A standard uniform generator
The congruencial generator on {1, 2, . . . , M}
f(x) = (ax + b) mod (M)
has a period equal to M for proper choices of (a, b) and becomes a
generator on ]0, 1[ when dividing by M + 1
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
A standard uniform generator
The congruencial generator on {1, 2, . . . , M}
f(x) = (ax + b) mod (M)
has a period equal to M for proper choices of (a, b) and becomes a
generator on ]0, 1[ when dividing by M + 1
Example
Take
f(x) = (69069069x + 12345) mod (232
)
and produce
... 518974515 2498053016 1113825472 1109377984 ...
i.e.
... 0.1208332 0.5816233 0.2593327 0.2582972 ...
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
A standard uniform generator
The congruencial generator on {1, 2, . . . , M}
f(x) = (ax + b) mod (M)
has a period equal to M for proper choices of (a, b) and becomes a
generator on ]0, 1[ when dividing by M + 1
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
A standard uniform generator
The congruencial generator on {1, 2, . . . , M}
f(x) = (ax + b) mod (M)
has a period equal to M for proper choices of (a, b) and becomes a
generator on ]0, 1[ when dividing by M + 1
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Approximating π
My daughter’s pseudo-code:
N=1000
ˆπ = 0
for I=1,N do
X=RDN(1), Y=RDN(1)
if X2
+ Y2
< 1 then
ˆπ = ˆπ + 1
end if
end for
return 4*ˆπ/N
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Approximating π
My daughter’s pseudo-code:
N=1000
ˆπ = 0
for I=1,N do
X=RDN(1), Y=RDN(1)
if X2
+ Y2
< 1 then
ˆπ = ˆπ + 1
end if
end for
return 4*ˆπ/N
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
pi = 3.2
100 simulations
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Approximating π
My daughter’s pseudo-code:
N=1000
ˆπ = 0
for I=1,N do
X=RDN(1), Y=RDN(1)
if X2
+ Y2
< 1 then
ˆπ = ˆπ + 1
end if
end for
return 4*ˆπ/N
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
qq
q
q
q
q
q q
q
q
q
q q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
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q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
qq
q
q
q
q
q
q
q
q
q
q
qq
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
pi = 3.108
1000 simulations
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Approximating π
My daughter’s pseudo-code:
N=1000
ˆπ = 0
for I=1,N do
X=RDN(1), Y=RDN(1)
if X2
+ Y2
< 1 then
ˆπ = ˆπ + 1
end if
end for
return 4*ˆπ/N
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
qq
q
q
q
q
q
q q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q q
q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
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
qq
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
qq
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
qq
pi = 3.136
10,000 simulations
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Approximating π
My daughter’s pseudo-code:
N=1000
ˆπ = 0
for I=1,N do
X=RDN(1), Y=RDN(1)
if X2
+ Y2
< 1 then
ˆπ = ˆπ + 1
end if
end for
return 4*ˆπ/N
106
simulations
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Distributions that differ from uniform distributions
Proble
Given a probability distribution with
density f , how can we produce
randomness according to f ?!
implemented algorithms in a
resident software only available for
common distributions
new distributions may require fast
resolution
no approximation allowed
x
f(x)
an arbitrary density
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Distributions that differ from uniform distributions
Proble
Given a probability distribution with
density f , how can we produce
randomness according to f ?!
implemented algorithms in a
resident software only available for
common distributions
new distributions may require fast
resolution
no approximation allowed
x
f(x)
an arbitrary density
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Accept-Reject Algorithm (remember π?!)
Given a probability distribution with density f , how can we produce
randomness according to f ?!
The uniform distribution on the
sub-graph region
Sf = {(x, u); 0 ≤ u ≤ f (x)}
produces a marginal distribution
in x with density f .
(”Fundamental theorem of
simulation”)
x
f(x)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Accept-Reject Algorithm (remember π?!)
Given a probability distribution with density f , how can we produce
randomness according to f ?!
In practice, this means we are
back to throwing dots on a box
containing
Sf = {(x, u); 0 ≤ u ≤ f (x)}
and counting those inside!
x
f(x)
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
qq
q q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Accept-Reject Algorithm
Refinement of the above through construction of a proper box:
1. Find a hat on f , i.e. a density g that can be simulated and
such that
sup
x
f (x) g(x) = M < ∞
2. Generate dots on the subgraph of g, i.e. Y1, Y2, . . . ∼ g, and
U1, U2, . . . ∼ U ([0, 1])
3. Accept only the Yk’s such that
Uk ≤ f (Yk)/Mg(Yk)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Accept-Reject Algorithm
Refinement of the above through construction of a proper box:
1. Find a hat on f , i.e. a density g that can be simulated and
such that
sup
x
f (x) g(x) = M < ∞
2. Generate dots on the subgraph of g, i.e. Y1, Y2, . . . ∼ g, and
U1, U2, . . . ∼ U ([0, 1])
3. Accept only the Yk’s such that
Uk ≤ f (Yk)/Mg(Yk)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Accept-Reject Algorithm
Refinement of the above through construction of a proper box:
1. Find a hat on f , i.e. a density g that can be simulated and
such that
sup
x
f (x) g(x) = M < ∞
2. Generate dots on the subgraph of g, i.e. Y1, Y2, . . . ∼ g, and
U1, U2, . . . ∼ U ([0, 1])
3. Accept only the Yk’s such that
Uk ≤ f (Yk)/Mg(Yk)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Accept-Reject Algorithm
Refinement of the above through construction of a proper box:
x
f(x)
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q q
q
q
q
q
q
q
q
q
q
q
q
q
q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q
q
q
q
q
q
qq
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
qq
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
q
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Properties
Does not require normalisation constant of f
Does not require an exact upper bound M
Requires on average M Yk’s for one simulated X (efficiency
measure)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Properties
Does not require normalisation constant of f
Does not require an exact upper bound M
Requires on average M Yk’s for one simulated X (efficiency
measure)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Properties
Does not require normalisation constant of f
Does not require an exact upper bound M
Requires on average M Yk’s for one simulated X (efficiency
measure)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
There exists other ways of exploitating the fundamental idea of
simulation over the subgraph:
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
There exists other ways of exploitating the fundamental idea of
simulation over the subgraph:
If direct uniform simulation on
Sf = {(u, x); 0 ≤ u ≤ f (x)}
is too complex [because of unavailable hat] use instead a random
walk on Sf :
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
There exists other ways of exploitating the fundamental idea of
simulation over the subgraph:
this means doing random jumps in vertical then horizontal
direction, accounting for the boundaries
0 ≤ u ≤ f (x), i.e. U(0, 1)
f (x) ≥ u, i.e. x ∼ US(u)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
Slice sampler algorithm
For t = 1, . . . , T
when at (x(t), ω(t)) simulate
1. ω(t+1) ∼ U[0,f (x(t))]
2. x(t+1) ∼ US(t+1) , where
S(t+1)
= {y; f (y) ≥ ω(t+1)
}.
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
Slice sampler algorithm
For t = 1, . . . , T
when at (x(t), ω(t)) simulate
1. ω(t+1) ∼ U[0,f (x(t))]
2. x(t+1) ∼ US(t+1) , where
S(t+1)
= {y; f (y) ≥ ω(t+1)
}.
0.0 0.2 0.4 0.6 0.8 1.0
0.0000.0020.0040.0060.0080.010
x
y
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
Slice sampler algorithm
For t = 1, . . . , T
when at (x(t), ω(t)) simulate
1. ω(t+1) ∼ U[0,f (x(t))]
2. x(t+1) ∼ US(t+1) , where
S(t+1)
= {y; f (y) ≥ ω(t+1)
}.
0.0 0.2 0.4 0.6 0.8 1.0
0.0000.0020.0040.0060.0080.010
x
y
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
Slice sampler algorithm
For t = 1, . . . , T
when at (x(t), ω(t)) simulate
1. ω(t+1) ∼ U[0,f (x(t))]
2. x(t+1) ∼ US(t+1) , where
S(t+1)
= {y; f (y) ≥ ω(t+1)
}.
0.0 0.2 0.4 0.6 0.8 1.0
0.0000.0020.0040.0060.0080.010
x
y
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
Slice sampler algorithm
For t = 1, . . . , T
when at (x(t), ω(t)) simulate
1. ω(t+1) ∼ U[0,f (x(t))]
2. x(t+1) ∼ US(t+1) , where
S(t+1)
= {y; f (y) ≥ ω(t+1)
}.
0.0 0.2 0.4 0.6 0.8 1.0
0.0000.0020.0040.0060.0080.010
x
y
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
Slice sampler algorithm
For t = 1, . . . , T
when at (x(t), ω(t)) simulate
1. ω(t+1) ∼ U[0,f (x(t))]
2. x(t+1) ∼ US(t+1) , where
S(t+1)
= {y; f (y) ≥ ω(t+1)
}.
0.0 0.2 0.4 0.6 0.8 1.0
0.0000.0020.0040.0060.0080.010
x
y
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
Slice sampler algorithm
For t = 1, . . . , T
when at (x(t), ω(t)) simulate
1. ω(t+1) ∼ U[0,f (x(t))]
2. x(t+1) ∼ US(t+1) , where
S(t+1)
= {y; f (y) ≥ ω(t+1)
}.
0.0 0.2 0.4 0.6 0.8 1.0
0.0000.0020.0040.0060.0080.010
x
y
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Slice sampler
Slice sampler algorithm
For t = 1, . . . , T
when at (x(t), ω(t)) simulate
1. ω(t+1) ∼ U[0,f (x(t))]
2. x(t+1) ∼ US(t+1) , where
S(t+1)
= {y; f (y) ≥ ω(t+1)
}.
0.0 0.2 0.4 0.6 0.8 1.0
0.0000.0020.0040.0060.0080.010
x
y
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Metropolis–Hastings algorithm
Further generalisation of the fundamental idea to situations when
the slice sampler cannot be easily implemented
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Metropolis–Hastings algorithm
Further generalisation of the fundamental idea to situations when
the slice sampler cannot be easily implemented
Idea
Create a sequence (Xn) such that, for n ‘large enough’, the density
of Xn is close to f , only using a ‘local’ knowledge of f ...
This is the domain of Markovian
simulation methods: there is a Markov
dependence between the Xn’s
Andre¨ı Markov
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Metropolis–Hastings algorithm
Further generalisation of the fundamental idea to situations when
the slice sampler cannot be easily implemented
Idea
Create a sequence (Xn) such that, for n ‘large enough’, the density
of Xn is close to f , only using a ‘local’ knowledge of f ...
This is the domain of Markovian
simulation methods: there is a Markov
dependence between the Xn’s
Markov bar, Melbourne
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Metropolis–Hastings algorithm
Further generalisation of the fundamental idea to situations when
the slice sampler cannot be easily implemented
‘local’ exploration can produce ‘global’ vision:
[ c Civilization 5]
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Metropolis–Hastings algorithm (2)
If f is the density of interest, we pick a proposal conditional density
q(y|xn)
such that
it connects with the current value xn
it is easy to simulate
it is positive everywhere f is positive
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
The Metropolis–Hastings algorithm (2)
If f is the density of interest, we pick a proposal conditional density
q(y|xn)
such that
it connects with the current value xn
it is easy to simulate
it is positive everywhere f is positive
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Random walk Metropolis–Hastings
Proposal
Yt = Xn + εn,
where εn ∼ g, independent from Xn, and g symmetrical
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Random walk Metropolis–Hastings
Proposal
Yt = Xn + εn,
where εn ∼ g, independent from Xn, and g symmetrical
Motivation
local perturbation of Xn / myopic exploration of its neighbourhood
Yn accepted or rejected depending on the relative values of f (Xn)
and f (Yn)
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Random walk Metropolis–Hastings
Proposal
Yt = Xn + εn,
where εn ∼ g, independent from Xn, and g symmetrical
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Random walk Metropolis–Hastings
Resulting algorithm
Random walk Metropolis–Hastings
Starting from X(t) = x(t)
1. Generate Yt ∼ g(y − x(t))
2. Take
X(t+1)
=



Yt with proba. min 1,
f (Yt)
f (x(t))
,
x(t) otherwise
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Properties
Always accepts higher point and sometimes lower points
(similar to gradient algorithms)
Depends on the dispersion of g
Average probability of acceptance
= min{f (x), f (y)}g(y − x) dxdy
close to 1 if g has a small variance [Danger!]
far from 1 if g has a large variance [Re-Danger!]
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Properties
Always accepts higher point and sometimes lower points
(similar to gradient algorithms)
Depends on the dispersion of g
Average probability of acceptance
= min{f (x), f (y)}g(y − x) dxdy
close to 1 if g has a small variance [Danger!]
far from 1 if g has a large variance [Re-Danger!]
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Properties
Always accepts higher point and sometimes lower points
(similar to gradient algorithms)
Depends on the dispersion of g
Average probability of acceptance
= min{f (x), f (y)}g(y − x) dxdy
close to 1 if g has a small variance [Danger!]
far from 1 if g has a large variance [Re-Danger!]
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Properties
scale=1
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Properties
scale=2
Simulation: a ubiquitous tool for statistical computation
Producing randomness by deterministic means
Properties
scale=3
Simulation: a ubiquitous tool for statistical computation
Monte Carlo principles
General purpose of Monte Carlo methods
Given a probability density f known up to a normalizing constant,
f (x) ∝ ˜f (x), and an integrable function h, compute
I(h) = h(x)f (x)dx =
h(x)˜f (x)dx
˜f (x)dx
when h(x)˜f (x)dx is intractable.
[Remember π!!]
Simulation: a ubiquitous tool for statistical computation
Monte Carlo principles
General purpose of Monte Carlo methods
Given a probability density f known up to a normalizing constant,
f (x) ∝ ˜f (x), and an integrable function h, compute
I(h) = h(x)f (x)dx =
h(x)˜f (x)dx
˜f (x)dx
when h(x)˜f (x)dx is intractable.
[Remember π!!]
Simulation: a ubiquitous tool for statistical computation
Monte Carlo principles
Monte Carlo basics
Generate a pseudo-random
sample x1, . . . , xN from f and
estimate I(h) by
ˆIMC
N (h) = N−1
N
i=1
h(xi ).
and let N grow to infinity...
Simulation: a ubiquitous tool for statistical computation
Monte Carlo principles
Monte Carlo basics
Generate a pseudo-random
sample x1, . . . , xN from f and
estimate I(h) by
ˆIMC
N (h) = N−1
N
i=1
h(xi ).
and let N grow to infinity...
A. Doucet, C. Andrieu, X, A. Philippe, J. Rosenthal, E. Moulines
Simulation: a ubiquitous tool for statistical computation
Monte Carlo principles
Monte Carlo basics
Generate a pseudo-random
sample x1, . . . , xN from f and
estimate I(h) by
ˆIMC
N (h) = N−1
N
i=1
h(xi ).
and let N grow to infinity...
Simulation: a ubiquitous tool for statistical computation
Monte Carlo principles
Monte Carlo basics
Generate a pseudo-random
sample x1, . . . , xN from f and
estimate I(h) by
ˆIMC
N (h) = N−1
N
i=1
h(xi ).
and let N grow to infinity...
Caveat
Often impossible or inefficient to simulate directly from f
Simulation: a ubiquitous tool for statistical computation
Monte Carlo principles
Importance Sampling
For proposal distribution with density q(x), alternative
representations
I(h) = h(x){f /q}(x)q(x)dx
Principle
Generate an iid sample x1, . . . , xN ∼ q and estimate I(h) by
ˆIIS
q,N(h) = N−1
N
i=1
h(xi ){f /q}(xi ).
Simulation: a ubiquitous tool for statistical computation
Monte Carlo principles
Importance Sampling
For proposal distribution with density q(x), alternative
representations
I(h) = h(x){f /q}(x)q(x)dx
Principle
Generate an iid sample x1, . . . , xN ∼ q and estimate I(h) by
ˆIIS
q,N(h) = N−1
N
i=1
h(xi ){f /q}(xi ).
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Optimisation problems
A (genuine) puzzle
During a dinner with 20 couples sitting at four tables with ten
seats, everyone wants to share a table with everyone. The
assembly decides to switch seats after each serving towards this
goal. What is the minimal number of servings needed to ensure
that every couple shared a table with every other couple at some
point? And what is the optimal switching strategy?
[http://xianblog.wordpress.com/2012/04/12/not-le-monde-puzzle/]
solution to the puzzle
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Stochastic minimisation
Example (Egg-box function)
Consider the function
h(x, y) = (x sin(20y) + y sin(20x))2
cosh(sin(10x)x)
+ (x cos(10y) − y sin(10x))2
cosh(cos(20y)y) ,
to be minimised.
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Stochastic minimisation
Example (Egg-box function)
Consider the function
h(x, y) = (x sin(20y) + y sin(20x))2
cosh(sin(10x)x)
+ (x cos(10y) − y sin(10x))2
cosh(cos(20y)y) ,
to be minimised. (I know
that the global minimum is 0
for (x, y) = (0, 0).)
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Stochastic minimisation
Example (Egg-box function)
Consider the function
h(x, y) = (x sin(20y) + y sin(20x))2
cosh(sin(10x)x)
+ (x cos(10y) − y sin(10x))2
cosh(cos(20y)y) ,
to be minimised. (I know
that the global minimum is 0
for (x, y) = (0, 0).)
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Stochastic minimisation
Example (egg-box function (2))
Instead of solving the first order equations
∂h(x, y)
∂x
= 0 ,
∂h(x, y)
∂y
= 0
and of checking that the second order conditions are met, we can
generate a random sequence in R2
θj+1 = θj +
αj
2βj
∆h(θj , βj ζj ) ζj
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Stochastic minimisation
Example (egg-box function (2))
we can generate a random sequence in R2
θj+1 = θj +
αj
2βj
∆h(θj , βj ζj ) ζj
where
the ζj ’s are uniform on the unit circle x2 + y2 = 1;
∆h(θ, ζ) = h(θ + ζ) − h(θ − ζ);
(αj ) and (βj ) converge to 0
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Calibration parameters
choice 1 2 3 4
αj 1/ log(j + 1) 1/100 log(j + 1) 1/(j + 1) 1/(j + 1)
βj 1/ log(j + 1).1 1/ log(j + 1).1 1/(j + 1).5 1/(j + 1).1
α ↓ 0 slowly, j αj = ∞
β ↓ 0 more slowly,
j (αj /βj )2 < ∞
Scenarios 1-2: not enough
energy
Scenarios 3-4: good
[ c George Casella 1951–2012
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
The traveling salesman problem
A classical allocation problem:
Salesman who needs to
visit n cities in a row
Traveling costs between
pairs of cities are known
Search of the optimal
circuit
Aboriginal art, NGA, Melbourne
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
The traveling salesman problem
A classical allocation problem:
Salesman who needs to
visit n cities in a row
Traveling costs between
pairs of cities are known
Search of the optimal
circuit
Aboriginal art, NGA, Melbourne
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
The traveling salesman problem
A classical allocation problem:
Salesman who needs to
visit n cities in a row
Traveling costs between
pairs of cities are known
Search of the optimal
circuit
Procter & Gamble competition, 1962
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
An NP-complete problem
The traveling salesman
problem is an example of
mathematical problems that
require explosive resolution
times
Aboriginal art, NGA, Melbourne
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
An NP-complete problem
The traveling salesman
problem is an example of
mathematical problems that
require explosive resolution
times
Number of possible circuits n!
and exact solutions available
in O(2n) time
Exact solution for 15, 112 German cities
found in 2001 in 22.6 CPU years.
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
An NP-complete problem
The traveling salesman
problem is an example of
mathematical problems that
require explosive resolution
times
Numerous practical
consequences (networks,
integrated circuit design,
genomic sequencing, &tc.)
Exact solution for the 24, 978 Sweedish cities
found in 2004 in 84.8 CPU years.
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Resolution via simulation
The simulated annealing algorithm:
name is borrowed from metallurgy
metal manufactured by a slow
decrease of temperature
(annealing) stronger than when
manufactured by fast decrease
[ c Joachim Robert, ca. 2006]
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Resolution via simulation
Repeat
Random modifications of parts of the original circuit with cost
C0
Evaluation of the cost C of the new circuit
Acceptation of the new circuit with probability
min exp
C0 − C
T
, 1
[Metropolis et al., 1953]
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Resolution via simulation
Repeat
Random modifications of parts of the original circuit with cost
C0
Evaluation of the cost C of the new circuit
Acceptation of the new circuit with probability
min exp
C0 − C
T
, 1
T, temperature, is progressively reduced
[Metropolis et al., 1953]
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
A family meeting (1)
Recall the table puzzle
Definition of a target function
Set the story of the 20 couple tables during the 6 courses as a
(20, 6) matrix, e.g.,
S =





1 1 3 2 4 2
2 1 3 3 2 4
...
...
...
...
...
...
3 2 2 2 4 4





and define a penalty function as the number of missed encounters
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
A family meeting (1)
Recall the table puzzle
Definition of a target function
I=sample(rep(1:4,5))
for (i in 2:6)
I=cbind(I,sample(rep(1:4,5)))
meet=function(I){
M=outer(I[,1],I[,1],"==")
for (i in 2:6)
M=M+outer(I[,i],I[,i],"==")
M
}
penalty=function(M){ sum(M==0) }
penat=penalty(meet(I))
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
A family meeting (2)
Random switch of couples
Pick two couples [among the 20 couples] at random with
probabilities proportional to the number of other couples they
have not seen
prob=apply(meet(I)==0,1,sum)
switch their respective position during one of the 6 courses
accept the switch with Metropolis–Hastings probability
log(runif(1))<(penalty(old)-penalty(new))/gamma
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
A family meeting (2)
Random switch of couples
For instance, propose to replace
S =





1 1 3 2 4 2
2 1 3 3 2 4
...
...
...
...
...
...
3 2 2 2 4 4





with S =





1 1 3 2 2 2
2 1 3 3 4 4
...
...
...
...
...
...
3 2 2 2 4 4





Simulation: a ubiquitous tool for statistical computation
Simulated annealing
A family meeting (2)
Random switch of couples
for (t in 1:N){
prop=sample(1:20,2,prob=apply(meet(I)==0,1,sum))
cour=sample(1:6,1)
Ip=I
Ip[prop[1],cour]=I[prop[2],cour]
Ip[prop[2],cour]=I[prop[1],cour]
penatp=penalty(meet(Ip))
if (log(runif(1))<(penat-penatp)/gamma){
I=Ip
penat=penatp}
}
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
A family meeting (3)
Solution
I
[1,] 1 4 3 2 2 3
[2,] 1 2 4 3 4 4
[3,] 3 2 1 4 1 3
[4,] 1 2 3 1 1 1
[5,] 4 2 4 2 3 3
[6,] 2 4 1 2 4 1
[7,] 4 3 1 1 2 4
[8,] 1 3 2 4 3 1
[9,] 3 3 3 3 4 3
[10,] 4 4 2 3 1 1
[11,] 1 1 1 3 3 2
[12,] 3 4 4 1 3 2
[13,] 4 1 3 4 4 2
[14,] 2 4 3 4 3 4
[15,] 2 3 4 2 1 2
[16,] 2 2 2 3 2 2
[17,] 2 1 2 1 4 3
[18,] 4 3 1 1 2 4
[19,] 3 1 4 4 2 1
[20,] 3 1 2 2 1 4 [ c http://www.metrolyrics.com]
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Solving sudokus
Solving a Sudoku grid as a minimisation problem:
[ c Dan Rice Sudoku blog]
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Solving sudokus
Given a partly filled Sudoku grid (with a single solution),
define a random Sudoku grid by filling the empty slots at
random
s=matrix(0,ncol=9,nrow=9)
s[1,c(1,6,7)]=c(8,1,2)
s[2,c(2:3)]=c(7,5)
s[3,c(5,8,9)]=c(5,6,4)
s[4,c(3,9)]=c(7,6)
s[5,c(1,4)]=c(9,7)
s[6,c(1,2,6,8,9)]=c(5,2,9,4,7)
s[7,c(1:3)]=c(2,3,1)
s[8,c(3,5,7,9)]=c(6,2,1,9)
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Solving sudokus
Given a partly filled Sudoku grid (with a single solution),
define a random Sudoku grid by filling the empty slots at
random
define a penalty function corresponding to the number of
missed constraints
#local score
scor=function(i,s){
a=((i-1)%%9)+1
b=trunc((i-1)/9)
boxa=3*trunc((a-1)/3)+1
boxb=3*trunc(b/3)+1
return(sum(s[i]==s[9*b+(1:9)])+
sum(s[i]==s[a+9*(0:8)])+
sum(s[i]==s[boxa:(boxa+2),boxb:(boxb+2)])-3)
}
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Solving sudokus
Given a partly filled Sudoku grid (with a single solution),
define a random Sudoku grid by filling the empty slots at
random
define a penalty function corresponding to the number of
missed constraints
fill “deterministic” slots
make simulated annealing moves
# random moves on the sites
i=sample((1:81)[as.vector(s)==0],sample(1:sum(s==0),1,pro=1/(1:sum(s==0))))
for (r in 1:length(i))
prop[i[r]]=sample((1:9)[pool[i[r]+81*(0:8)]],1)
if (log(runif(1))/lcur<tarcur-target(prop)){
nchange=nchange+(tarcur>target(prop))
cur=prop
points(t,tarcur,col="forestgreen",cex=.3,pch=19)
tarcur=target(cur)
}
Simulation: a ubiquitous tool for statistical computation
Simulated annealing
Solving sudokus
many possible variants in the
proposals
rather slow and sometimes
really slow
may get stuck on a penalty of
2 (and never reach zero)
does not compete at all with
nonrandom solvers

More Related Content

Similar to Presentation slides for my simulation course at Dauphine

PhysicsSIG2008-01-Seneviratne
PhysicsSIG2008-01-SeneviratnePhysicsSIG2008-01-Seneviratne
PhysicsSIG2008-01-Seneviratne
Sarath Senevirtatne
 
Ml presentation
Ml presentationMl presentation
Ml presentation
Mark Fetherolf
 
Nimrita koul Machine Learning
Nimrita koul  Machine LearningNimrita koul  Machine Learning
Nimrita koul Machine Learning
Nimrita Koul
 
Week08.pdf
Week08.pdfWeek08.pdf
Monte Carlo Simulations (UC Berkeley School of Information; July 11, 2019)
Monte Carlo Simulations (UC Berkeley School of Information; July 11, 2019)Monte Carlo Simulations (UC Berkeley School of Information; July 11, 2019)
Monte Carlo Simulations (UC Berkeley School of Information; July 11, 2019)
Ivan Corneillet
 
Artificial Agents Without Ontological Access to Reality
Artificial Agents Without Ontological Access to RealityArtificial Agents Without Ontological Access to Reality
Artificial Agents Without Ontological Access to Reality
ogeorgeon
 
Two methods for optimising cognitive model parameters
Two methods for optimising cognitive model parametersTwo methods for optimising cognitive model parameters
Two methods for optimising cognitive model parameters
University of Huddersfield
 
Statistical software for Sampling from Finite Populations: an analysis using ...
Statistical software for Sampling from Finite Populations: an analysis using ...Statistical software for Sampling from Finite Populations: an analysis using ...
Statistical software for Sampling from Finite Populations: an analysis using ...
michele de meo
 
G. Barcaroli, The use of machine learning in official statistics
G. Barcaroli, The use of machine learning in official statisticsG. Barcaroli, The use of machine learning in official statistics
G. Barcaroli, The use of machine learning in official statistics
Istituto nazionale di statistica
 
06-01 Machine Learning and Linear Regression.pptx
06-01 Machine Learning and Linear Regression.pptx06-01 Machine Learning and Linear Regression.pptx
06-01 Machine Learning and Linear Regression.pptx
SaharA84
 
ABC short course: final chapters
ABC short course: final chaptersABC short course: final chapters
ABC short course: final chapters
Christian Robert
 
Computational Biology, Part 4 Protein Coding Regions
Computational Biology, Part 4 Protein Coding RegionsComputational Biology, Part 4 Protein Coding Regions
Computational Biology, Part 4 Protein Coding Regions
butest
 
Ml ppt at
Ml ppt atMl ppt at
Ml ppt at
pradeep kumar
 
La résolution de problèmes à l'aide de graphes
La résolution de problèmes à l'aide de graphesLa résolution de problèmes à l'aide de graphes
La résolution de problèmes à l'aide de graphes
Data2B
 
PHStat Notes Using the PHStat Stack Data and .docx
    PHStat Notes    Using the  PHStat Stack Data  and .docx    PHStat Notes    Using the  PHStat Stack Data  and .docx
PHStat Notes Using the PHStat Stack Data and .docx
ShiraPrater50
 
Automatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsAutomatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory Errors
Emery Berger
 
One Algorithm to Rule Them All: How to Automate Statistical Computation
One Algorithm to Rule Them All: How to Automate Statistical ComputationOne Algorithm to Rule Them All: How to Automate Statistical Computation
One Algorithm to Rule Them All: How to Automate Statistical Computation
Work-Bench
 
The fundamental problem of Forensic Statistics
The fundamental problem of Forensic StatisticsThe fundamental problem of Forensic Statistics
The fundamental problem of Forensic Statistics
Giulia Cereda
 
advanced_statistics.pdf
advanced_statistics.pdfadvanced_statistics.pdf
advanced_statistics.pdf
GerryMakilan2
 
20181212 ibm aot
20181212 ibm aot20181212 ibm aot
20181212 ibm aot
Hiroshi Maruyama
 

Similar to Presentation slides for my simulation course at Dauphine (20)

PhysicsSIG2008-01-Seneviratne
PhysicsSIG2008-01-SeneviratnePhysicsSIG2008-01-Seneviratne
PhysicsSIG2008-01-Seneviratne
 
Ml presentation
Ml presentationMl presentation
Ml presentation
 
Nimrita koul Machine Learning
Nimrita koul  Machine LearningNimrita koul  Machine Learning
Nimrita koul Machine Learning
 
Week08.pdf
Week08.pdfWeek08.pdf
Week08.pdf
 
Monte Carlo Simulations (UC Berkeley School of Information; July 11, 2019)
Monte Carlo Simulations (UC Berkeley School of Information; July 11, 2019)Monte Carlo Simulations (UC Berkeley School of Information; July 11, 2019)
Monte Carlo Simulations (UC Berkeley School of Information; July 11, 2019)
 
Artificial Agents Without Ontological Access to Reality
Artificial Agents Without Ontological Access to RealityArtificial Agents Without Ontological Access to Reality
Artificial Agents Without Ontological Access to Reality
 
Two methods for optimising cognitive model parameters
Two methods for optimising cognitive model parametersTwo methods for optimising cognitive model parameters
Two methods for optimising cognitive model parameters
 
Statistical software for Sampling from Finite Populations: an analysis using ...
Statistical software for Sampling from Finite Populations: an analysis using ...Statistical software for Sampling from Finite Populations: an analysis using ...
Statistical software for Sampling from Finite Populations: an analysis using ...
 
G. Barcaroli, The use of machine learning in official statistics
G. Barcaroli, The use of machine learning in official statisticsG. Barcaroli, The use of machine learning in official statistics
G. Barcaroli, The use of machine learning in official statistics
 
06-01 Machine Learning and Linear Regression.pptx
06-01 Machine Learning and Linear Regression.pptx06-01 Machine Learning and Linear Regression.pptx
06-01 Machine Learning and Linear Regression.pptx
 
ABC short course: final chapters
ABC short course: final chaptersABC short course: final chapters
ABC short course: final chapters
 
Computational Biology, Part 4 Protein Coding Regions
Computational Biology, Part 4 Protein Coding RegionsComputational Biology, Part 4 Protein Coding Regions
Computational Biology, Part 4 Protein Coding Regions
 
Ml ppt at
Ml ppt atMl ppt at
Ml ppt at
 
La résolution de problèmes à l'aide de graphes
La résolution de problèmes à l'aide de graphesLa résolution de problèmes à l'aide de graphes
La résolution de problèmes à l'aide de graphes
 
PHStat Notes Using the PHStat Stack Data and .docx
    PHStat Notes    Using the  PHStat Stack Data  and .docx    PHStat Notes    Using the  PHStat Stack Data  and .docx
PHStat Notes Using the PHStat Stack Data and .docx
 
Automatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory ErrorsAutomatically Tolerating And Correcting Memory Errors
Automatically Tolerating And Correcting Memory Errors
 
One Algorithm to Rule Them All: How to Automate Statistical Computation
One Algorithm to Rule Them All: How to Automate Statistical ComputationOne Algorithm to Rule Them All: How to Automate Statistical Computation
One Algorithm to Rule Them All: How to Automate Statistical Computation
 
The fundamental problem of Forensic Statistics
The fundamental problem of Forensic StatisticsThe fundamental problem of Forensic Statistics
The fundamental problem of Forensic Statistics
 
advanced_statistics.pdf
advanced_statistics.pdfadvanced_statistics.pdf
advanced_statistics.pdf
 
20181212 ibm aot
20181212 ibm aot20181212 ibm aot
20181212 ibm aot
 

More from Christian Robert

Adaptive Restore algorithm & importance Monte Carlo
Adaptive Restore algorithm & importance Monte CarloAdaptive Restore algorithm & importance Monte Carlo
Adaptive Restore algorithm & importance Monte Carlo
Christian Robert
 
Asymptotics of ABC, lecture, Collège de France
Asymptotics of ABC, lecture, Collège de FranceAsymptotics of ABC, lecture, Collège de France
Asymptotics of ABC, lecture, Collège de France
Christian Robert
 
Workshop in honour of Don Poskitt and Gael Martin
Workshop in honour of Don Poskitt and Gael MartinWorkshop in honour of Don Poskitt and Gael Martin
Workshop in honour of Don Poskitt and Gael Martin
Christian Robert
 
discussion of ICML23.pdf
discussion of ICML23.pdfdiscussion of ICML23.pdf
discussion of ICML23.pdf
Christian Robert
 
How many components in a mixture?
How many components in a mixture?How many components in a mixture?
How many components in a mixture?
Christian Robert
 
restore.pdf
restore.pdfrestore.pdf
restore.pdf
Christian Robert
 
Testing for mixtures at BNP 13
Testing for mixtures at BNP 13Testing for mixtures at BNP 13
Testing for mixtures at BNP 13
Christian Robert
 
Inferring the number of components: dream or reality?
Inferring the number of components: dream or reality?Inferring the number of components: dream or reality?
Inferring the number of components: dream or reality?
Christian Robert
 
CDT 22 slides.pdf
CDT 22 slides.pdfCDT 22 slides.pdf
CDT 22 slides.pdf
Christian Robert
 
Testing for mixtures by seeking components
Testing for mixtures by seeking componentsTesting for mixtures by seeking components
Testing for mixtures by seeking components
Christian Robert
 
discussion on Bayesian restricted likelihood
discussion on Bayesian restricted likelihooddiscussion on Bayesian restricted likelihood
discussion on Bayesian restricted likelihood
Christian Robert
 
NCE, GANs & VAEs (and maybe BAC)
NCE, GANs & VAEs (and maybe BAC)NCE, GANs & VAEs (and maybe BAC)
NCE, GANs & VAEs (and maybe BAC)
Christian Robert
 
ABC-Gibbs
ABC-GibbsABC-Gibbs
ABC-Gibbs
Christian Robert
 
Coordinate sampler : A non-reversible Gibbs-like sampler
Coordinate sampler : A non-reversible Gibbs-like samplerCoordinate sampler : A non-reversible Gibbs-like sampler
Coordinate sampler : A non-reversible Gibbs-like sampler
Christian Robert
 
eugenics and statistics
eugenics and statisticseugenics and statistics
eugenics and statistics
Christian Robert
 
Laplace's Demon: seminar #1
Laplace's Demon: seminar #1Laplace's Demon: seminar #1
Laplace's Demon: seminar #1
Christian Robert
 
ABC-Gibbs
ABC-GibbsABC-Gibbs
ABC-Gibbs
Christian Robert
 
asymptotics of ABC
asymptotics of ABCasymptotics of ABC
asymptotics of ABC
Christian Robert
 
ABC-Gibbs
ABC-GibbsABC-Gibbs
ABC-Gibbs
Christian Robert
 
Likelihood-free Design: a discussion
Likelihood-free Design: a discussionLikelihood-free Design: a discussion
Likelihood-free Design: a discussion
Christian Robert
 

More from Christian Robert (20)

Adaptive Restore algorithm & importance Monte Carlo
Adaptive Restore algorithm & importance Monte CarloAdaptive Restore algorithm & importance Monte Carlo
Adaptive Restore algorithm & importance Monte Carlo
 
Asymptotics of ABC, lecture, Collège de France
Asymptotics of ABC, lecture, Collège de FranceAsymptotics of ABC, lecture, Collège de France
Asymptotics of ABC, lecture, Collège de France
 
Workshop in honour of Don Poskitt and Gael Martin
Workshop in honour of Don Poskitt and Gael MartinWorkshop in honour of Don Poskitt and Gael Martin
Workshop in honour of Don Poskitt and Gael Martin
 
discussion of ICML23.pdf
discussion of ICML23.pdfdiscussion of ICML23.pdf
discussion of ICML23.pdf
 
How many components in a mixture?
How many components in a mixture?How many components in a mixture?
How many components in a mixture?
 
restore.pdf
restore.pdfrestore.pdf
restore.pdf
 
Testing for mixtures at BNP 13
Testing for mixtures at BNP 13Testing for mixtures at BNP 13
Testing for mixtures at BNP 13
 
Inferring the number of components: dream or reality?
Inferring the number of components: dream or reality?Inferring the number of components: dream or reality?
Inferring the number of components: dream or reality?
 
CDT 22 slides.pdf
CDT 22 slides.pdfCDT 22 slides.pdf
CDT 22 slides.pdf
 
Testing for mixtures by seeking components
Testing for mixtures by seeking componentsTesting for mixtures by seeking components
Testing for mixtures by seeking components
 
discussion on Bayesian restricted likelihood
discussion on Bayesian restricted likelihooddiscussion on Bayesian restricted likelihood
discussion on Bayesian restricted likelihood
 
NCE, GANs & VAEs (and maybe BAC)
NCE, GANs & VAEs (and maybe BAC)NCE, GANs & VAEs (and maybe BAC)
NCE, GANs & VAEs (and maybe BAC)
 
ABC-Gibbs
ABC-GibbsABC-Gibbs
ABC-Gibbs
 
Coordinate sampler : A non-reversible Gibbs-like sampler
Coordinate sampler : A non-reversible Gibbs-like samplerCoordinate sampler : A non-reversible Gibbs-like sampler
Coordinate sampler : A non-reversible Gibbs-like sampler
 
eugenics and statistics
eugenics and statisticseugenics and statistics
eugenics and statistics
 
Laplace's Demon: seminar #1
Laplace's Demon: seminar #1Laplace's Demon: seminar #1
Laplace's Demon: seminar #1
 
ABC-Gibbs
ABC-GibbsABC-Gibbs
ABC-Gibbs
 
asymptotics of ABC
asymptotics of ABCasymptotics of ABC
asymptotics of ABC
 
ABC-Gibbs
ABC-GibbsABC-Gibbs
ABC-Gibbs
 
Likelihood-free Design: a discussion
Likelihood-free Design: a discussionLikelihood-free Design: a discussion
Likelihood-free Design: a discussion
 

Recently uploaded

Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 

Recently uploaded (20)

Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 

Presentation slides for my simulation course at Dauphine

  • 1. Simulation: a ubiquitous tool for statistical computation Statistique exploratoire (NOISE) introduction to computer language R rudiments of simulation (aka Monte Carlo methods) illustration by the boostrap method
  • 2. Simulation: a ubiquitous tool for statistical computation Organisation weekly computer labs using R and Rstudio one computer account per student midterm and final exams on anonymous account exam made of programming problems (e.g., 3 out of 6) exam evaluation based on executable R code handouts and on-line help available on anonymous account no other document
  • 3. Simulation: a ubiquitous tool for statistical computation Reference documents on https://www.ceremade.dauphine.fr/~xian/Noise.html R. Drouihlet, P. Lafaye de Micheaux & B. Liquet (2010) Le logiciel R Springer, Paris C. Robert & G. Casella (2007) Introduction to Monte Carlo Methods with R Springer, New York Manuals on http://cran.r-project.org/manuals.html (CRAN is the Comprehensive R Archive Network)
  • 4. Simulation: a ubiquitous tool for statistical computation Simulation: a ubiquitous tool for statistical computation Christian P. Robert Universit´e Paris-Dauphine http://www.ceremade.dauphine.fr/~xian September 26, 2013
  • 5. Simulation: a ubiquitous tool for statistical computation Outline Simulation, what’s that for?! Producing randomness by deterministic means Monte Carlo principles Simulated annealing
  • 6. Simulation: a ubiquitous tool for statistical computation Simulation, what’s that for?! Illustrations Necessity to “(re)produce chance” on a computer Evaluation of the behaviour of a complex system (network, computer program, queue, particle system, atmosphere, epidemics, economic actions, &tc) [ c Office of Oceanic and Atmospheric Research]
  • 7. Simulation: a ubiquitous tool for statistical computation Simulation, what’s that for?! Illustrations Necessity to “(re)produce chance” on a computer Production of changing landscapes, characters, behaviours in computer games and flight simulators [ c guides.ign.com]
  • 8. Simulation: a ubiquitous tool for statistical computation Simulation, what’s that for?! Illustrations Necessity to “(re)produce chance” on a computer Determine probabilistic properties of a new statistical procedure or under an unknown distribution [bootstrap] (left) Estimation of the cdf F from a normal sample of 100 points; (right) variation of this estimation over 200 normal samples
  • 9. Simulation: a ubiquitous tool for statistical computation Simulation, what’s that for?! Illustrations Necessity to “(re)produce chance” on a computer Validation of a probabilistic model Histogram of 103 variates from a distribution and fit by this distribution density
  • 10. Simulation: a ubiquitous tool for statistical computation Simulation, what’s that for?! Illustrations Necessity to “(re)produce chance” on a computer Approximation of a integral [ c my daughter’s math book]
  • 11. Simulation: a ubiquitous tool for statistical computation Simulation, what’s that for?! Illustrations Necessity to “(re)produce chance” on a computer Maximisation of a weakly regular function/likelihood [ c Dan Rice Sudoku blog]
  • 12. Simulation: a ubiquitous tool for statistical computation Simulation, what’s that for?! Illustrations Necessity to “(re)produce chance” on a computer Pricing of a complex financial product (exotic options) Simulation of a Garch(1,1) process and of its volatility (103 time units)
  • 13. Simulation: a ubiquitous tool for statistical computation Simulation, what’s that for?! Illustrations Necessity to “(re)produce chance” on a computer Handling complex statistical problems by approximate Bayesian computation (ABC) core principle Simulate a parameter value (at random) and pseudo-data from the likelihood until the pseudo-data is “close enough” to the observed data, then keep the corresponding parameter value [Griffith & al., 1997; Tavar´e & al., 1999]
  • 14. Simulation: a ubiquitous tool for statistical computation Simulation, what’s that for?! Illustrations Necessity to “(re)produce chance” on a computer Handling complex statistical problems by approximate Bayesian computation (ABC) demo-genetic inference Genetic model of evolution from a common ancestor (MRCA) characterized by a set of parameters that cover historical, demographic, and genetic factors Dataset of polymorphism (DNA sample) observed at the present time !""#$%&'()*+,(-*.&(/+0$'"1)()&$/+2!,03! 1/+*%*'"4*+56(""4&7()&$/.+.1#+4*.+8-9':*.+ Différents scénarios possibles, choix de scenario par ABC Le scenario 1a est largement soutenu par rapport aux
  • 15. Simulation: a ubiquitous tool for statistical computation Simulation, what’s that for?! Illustrations Necessity to “(re)produce chance” on a computer Handling complex statistical problems by approximate Bayesian computation (ABC) Pygmies population demo-genetics Pygmies populations: do they have a common origin? when and how did they split from non-pygmies populations? were there more recent interactions between pygmies and non-pygmies populations? 94 !""#$%&'()*+,(-*.&(/+0$'"1)()&$/+2!,03! 1/+*%*'"4*+56(""4&7()&$/.+.1#+4*.+8-9':*.+
  • 16. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Pseudo-random generator Pivotal element/building block of simulation: always requires availability of uniform U (0, 1) random variables [ c MMP World]
  • 17. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Pseudo-random generator Pivotal element/building block of simulation: always requires availability of uniform U (0, 1) random variables 0.1333139 0.3026299 0.4342966 0.2395357 0.3223723 0.8531162 0.3921457 0.7625259 0.1701947 0.2816627 ...
  • 18. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Pseudo-random generator Pivotal element/building block of simulation: always requires availability of uniform U (0, 1) random variables Definition (Pseudo-random generator) A pseudo-random generator is a deterministic function f from ]0, 1[ to ]0, 1[ such that, for any starting value u0 and any n, the sequence {u0, f(u0), f(f(u0)), . . . , fn (u0)} behaves (statistically) like an iid U (0, 1) sequence
  • 19. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Pseudo-random generator Pivotal element/building block of simulation: always requires availability of uniform U (0, 1) random variables q q q q q q q q q 0.0 0.2 0.4 0.6 0.8 0.00.20.40.60.8 xt+1 10 steps (ut , ut+1) of a uniform generator
  • 20. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Philosophical foray ¡Paradox! While avoiding randomness, the deterministic sequence (u0, u1 = f(u0), . . . , un = f(un−1)) must resemble a random sequence! Debate on whether or not true randomness does exist (Laplace’s demon versus Schroedinger’s cat), in which case pseudo random generators are not random (von Neuman’s state of sin)
  • 21. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Philosophical foray ¡Paradox! While avoiding randomness, the deterministic sequence (u0, u1 = f(u0), . . . , un = f(un−1)) must resemble a random sequence! Debate on whether or not true randomness does exist (Laplace’s demon versus Schroedinger’s cat), in which case pseudo random generators are not random (von Neuman’s state of sin)
  • 22. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Philosophical foray ¡Paradox! While avoiding randomness, the deterministic sequence (u0, u1 = f(u0), . . . , un = f(un−1)) must resemble a random sequence! Debate on whether or not true randomness does exist (Laplace’s demon versus Schroedinger’s cat), in which case pseudo random generators are not random (von Neuman’s state of sin)
  • 23. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Philosophical foray ¡Paradox! While avoiding randomness, the deterministic sequence (u0, u1 = f(u0), . . . , un = f(un−1)) must resemble a random sequence! Debate on whether or not true randomness does exist (Laplace’s demon versus Schroedinger’s cat), in which case pseudo random generators are not random (von Neuman’s state of sin)
  • 24. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means True random generators Intel circuit producing “truly random” numbers: There is no reason physical generators should be “more” random than congruential (deterministic) pseudo-random generators, as those are valid generators, i.e. their distribution is exactly known (e.g., uniform) and, in the case of parallel generations, completely independent
  • 25. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means True random generators Intel generator satisfies all benchmarks of “randomness” maintained by NIST: Skepticism about physical devices, when compared with mathematical functions, because of (a) non-reproducibility and (b) instability of the device, which means that proven uniformity at time t does not induce uniformity at time t + 1
  • 26. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means A standard uniform generator The congruencial generator on {1, 2, . . . , M} f(x) = (ax + b) mod (M) has a period equal to M for proper choices of (a, b) and becomes a generator on ]0, 1[ when dividing by M + 1
  • 27. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means A standard uniform generator The congruencial generator on {1, 2, . . . , M} f(x) = (ax + b) mod (M) has a period equal to M for proper choices of (a, b) and becomes a generator on ]0, 1[ when dividing by M + 1 Example Take f(x) = (69069069x + 12345) mod (232 ) and produce ... 518974515 2498053016 1113825472 1109377984 ... i.e. ... 0.1208332 0.5816233 0.2593327 0.2582972 ...
  • 28. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means A standard uniform generator The congruencial generator on {1, 2, . . . , M} f(x) = (ax + b) mod (M) has a period equal to M for proper choices of (a, b) and becomes a generator on ]0, 1[ when dividing by M + 1
  • 29. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means A standard uniform generator The congruencial generator on {1, 2, . . . , M} f(x) = (ax + b) mod (M) has a period equal to M for proper choices of (a, b) and becomes a generator on ]0, 1[ when dividing by M + 1
  • 30. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Approximating π My daughter’s pseudo-code: N=1000 ˆπ = 0 for I=1,N do X=RDN(1), Y=RDN(1) if X2 + Y2 < 1 then ˆπ = ˆπ + 1 end if end for return 4*ˆπ/N
  • 31. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Approximating π My daughter’s pseudo-code: N=1000 ˆπ = 0 for I=1,N do X=RDN(1), Y=RDN(1) if X2 + Y2 < 1 then ˆπ = ˆπ + 1 end if end for return 4*ˆπ/N q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q pi = 3.2 100 simulations
  • 32. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Approximating π My daughter’s pseudo-code: N=1000 ˆπ = 0 for I=1,N do X=RDN(1), Y=RDN(1) if X2 + Y2 < 1 then ˆπ = ˆπ + 1 end if end for return 4*ˆπ/N q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q pi = 3.108 1000 simulations
  • 33. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Approximating π My daughter’s pseudo-code: N=1000 ˆπ = 0 for I=1,N do X=RDN(1), Y=RDN(1) if X2 + Y2 < 1 then ˆπ = ˆπ + 1 end if end for return 4*ˆπ/N q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q qq q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q qq q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q qq q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq pi = 3.136 10,000 simulations
  • 34. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Approximating π My daughter’s pseudo-code: N=1000 ˆπ = 0 for I=1,N do X=RDN(1), Y=RDN(1) if X2 + Y2 < 1 then ˆπ = ˆπ + 1 end if end for return 4*ˆπ/N 106 simulations
  • 35. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Distributions that differ from uniform distributions Proble Given a probability distribution with density f , how can we produce randomness according to f ?! implemented algorithms in a resident software only available for common distributions new distributions may require fast resolution no approximation allowed x f(x) an arbitrary density
  • 36. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Distributions that differ from uniform distributions Proble Given a probability distribution with density f , how can we produce randomness according to f ?! implemented algorithms in a resident software only available for common distributions new distributions may require fast resolution no approximation allowed x f(x) an arbitrary density
  • 37. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Accept-Reject Algorithm (remember π?!) Given a probability distribution with density f , how can we produce randomness according to f ?! The uniform distribution on the sub-graph region Sf = {(x, u); 0 ≤ u ≤ f (x)} produces a marginal distribution in x with density f . (”Fundamental theorem of simulation”) x f(x)
  • 38. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Accept-Reject Algorithm (remember π?!) Given a probability distribution with density f , how can we produce randomness according to f ?! In practice, this means we are back to throwing dots on a box containing Sf = {(x, u); 0 ≤ u ≤ f (x)} and counting those inside! x f(x) q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q
  • 39. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Accept-Reject Algorithm Refinement of the above through construction of a proper box: 1. Find a hat on f , i.e. a density g that can be simulated and such that sup x f (x) g(x) = M < ∞ 2. Generate dots on the subgraph of g, i.e. Y1, Y2, . . . ∼ g, and U1, U2, . . . ∼ U ([0, 1]) 3. Accept only the Yk’s such that Uk ≤ f (Yk)/Mg(Yk)
  • 40. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Accept-Reject Algorithm Refinement of the above through construction of a proper box: 1. Find a hat on f , i.e. a density g that can be simulated and such that sup x f (x) g(x) = M < ∞ 2. Generate dots on the subgraph of g, i.e. Y1, Y2, . . . ∼ g, and U1, U2, . . . ∼ U ([0, 1]) 3. Accept only the Yk’s such that Uk ≤ f (Yk)/Mg(Yk)
  • 41. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Accept-Reject Algorithm Refinement of the above through construction of a proper box: 1. Find a hat on f , i.e. a density g that can be simulated and such that sup x f (x) g(x) = M < ∞ 2. Generate dots on the subgraph of g, i.e. Y1, Y2, . . . ∼ g, and U1, U2, . . . ∼ U ([0, 1]) 3. Accept only the Yk’s such that Uk ≤ f (Yk)/Mg(Yk)
  • 42. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Accept-Reject Algorithm Refinement of the above through construction of a proper box: x f(x) q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q qq q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q q
  • 43. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Properties Does not require normalisation constant of f Does not require an exact upper bound M Requires on average M Yk’s for one simulated X (efficiency measure)
  • 44. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Properties Does not require normalisation constant of f Does not require an exact upper bound M Requires on average M Yk’s for one simulated X (efficiency measure)
  • 45. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Properties Does not require normalisation constant of f Does not require an exact upper bound M Requires on average M Yk’s for one simulated X (efficiency measure)
  • 46. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler There exists other ways of exploitating the fundamental idea of simulation over the subgraph:
  • 47. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler There exists other ways of exploitating the fundamental idea of simulation over the subgraph: If direct uniform simulation on Sf = {(u, x); 0 ≤ u ≤ f (x)} is too complex [because of unavailable hat] use instead a random walk on Sf :
  • 48. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler There exists other ways of exploitating the fundamental idea of simulation over the subgraph: this means doing random jumps in vertical then horizontal direction, accounting for the boundaries 0 ≤ u ≤ f (x), i.e. U(0, 1) f (x) ≥ u, i.e. x ∼ US(u)
  • 49. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler Slice sampler algorithm For t = 1, . . . , T when at (x(t), ω(t)) simulate 1. ω(t+1) ∼ U[0,f (x(t))] 2. x(t+1) ∼ US(t+1) , where S(t+1) = {y; f (y) ≥ ω(t+1) }.
  • 50. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler Slice sampler algorithm For t = 1, . . . , T when at (x(t), ω(t)) simulate 1. ω(t+1) ∼ U[0,f (x(t))] 2. x(t+1) ∼ US(t+1) , where S(t+1) = {y; f (y) ≥ ω(t+1) }. 0.0 0.2 0.4 0.6 0.8 1.0 0.0000.0020.0040.0060.0080.010 x y
  • 51. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler Slice sampler algorithm For t = 1, . . . , T when at (x(t), ω(t)) simulate 1. ω(t+1) ∼ U[0,f (x(t))] 2. x(t+1) ∼ US(t+1) , where S(t+1) = {y; f (y) ≥ ω(t+1) }. 0.0 0.2 0.4 0.6 0.8 1.0 0.0000.0020.0040.0060.0080.010 x y
  • 52. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler Slice sampler algorithm For t = 1, . . . , T when at (x(t), ω(t)) simulate 1. ω(t+1) ∼ U[0,f (x(t))] 2. x(t+1) ∼ US(t+1) , where S(t+1) = {y; f (y) ≥ ω(t+1) }. 0.0 0.2 0.4 0.6 0.8 1.0 0.0000.0020.0040.0060.0080.010 x y
  • 53. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler Slice sampler algorithm For t = 1, . . . , T when at (x(t), ω(t)) simulate 1. ω(t+1) ∼ U[0,f (x(t))] 2. x(t+1) ∼ US(t+1) , where S(t+1) = {y; f (y) ≥ ω(t+1) }. 0.0 0.2 0.4 0.6 0.8 1.0 0.0000.0020.0040.0060.0080.010 x y
  • 54. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler Slice sampler algorithm For t = 1, . . . , T when at (x(t), ω(t)) simulate 1. ω(t+1) ∼ U[0,f (x(t))] 2. x(t+1) ∼ US(t+1) , where S(t+1) = {y; f (y) ≥ ω(t+1) }. 0.0 0.2 0.4 0.6 0.8 1.0 0.0000.0020.0040.0060.0080.010 x y
  • 55. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler Slice sampler algorithm For t = 1, . . . , T when at (x(t), ω(t)) simulate 1. ω(t+1) ∼ U[0,f (x(t))] 2. x(t+1) ∼ US(t+1) , where S(t+1) = {y; f (y) ≥ ω(t+1) }. 0.0 0.2 0.4 0.6 0.8 1.0 0.0000.0020.0040.0060.0080.010 x y
  • 56. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Slice sampler Slice sampler algorithm For t = 1, . . . , T when at (x(t), ω(t)) simulate 1. ω(t+1) ∼ U[0,f (x(t))] 2. x(t+1) ∼ US(t+1) , where S(t+1) = {y; f (y) ≥ ω(t+1) }. 0.0 0.2 0.4 0.6 0.8 1.0 0.0000.0020.0040.0060.0080.010 x y
  • 57. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Metropolis–Hastings algorithm Further generalisation of the fundamental idea to situations when the slice sampler cannot be easily implemented
  • 58. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Metropolis–Hastings algorithm Further generalisation of the fundamental idea to situations when the slice sampler cannot be easily implemented Idea Create a sequence (Xn) such that, for n ‘large enough’, the density of Xn is close to f , only using a ‘local’ knowledge of f ... This is the domain of Markovian simulation methods: there is a Markov dependence between the Xn’s Andre¨ı Markov
  • 59. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Metropolis–Hastings algorithm Further generalisation of the fundamental idea to situations when the slice sampler cannot be easily implemented Idea Create a sequence (Xn) such that, for n ‘large enough’, the density of Xn is close to f , only using a ‘local’ knowledge of f ... This is the domain of Markovian simulation methods: there is a Markov dependence between the Xn’s Markov bar, Melbourne
  • 60. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Metropolis–Hastings algorithm Further generalisation of the fundamental idea to situations when the slice sampler cannot be easily implemented ‘local’ exploration can produce ‘global’ vision: [ c Civilization 5]
  • 61. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Metropolis–Hastings algorithm (2) If f is the density of interest, we pick a proposal conditional density q(y|xn) such that it connects with the current value xn it is easy to simulate it is positive everywhere f is positive
  • 62. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means The Metropolis–Hastings algorithm (2) If f is the density of interest, we pick a proposal conditional density q(y|xn) such that it connects with the current value xn it is easy to simulate it is positive everywhere f is positive
  • 63. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Random walk Metropolis–Hastings Proposal Yt = Xn + εn, where εn ∼ g, independent from Xn, and g symmetrical
  • 64. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Random walk Metropolis–Hastings Proposal Yt = Xn + εn, where εn ∼ g, independent from Xn, and g symmetrical Motivation local perturbation of Xn / myopic exploration of its neighbourhood Yn accepted or rejected depending on the relative values of f (Xn) and f (Yn)
  • 65. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Random walk Metropolis–Hastings Proposal Yt = Xn + εn, where εn ∼ g, independent from Xn, and g symmetrical
  • 66. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Random walk Metropolis–Hastings Resulting algorithm Random walk Metropolis–Hastings Starting from X(t) = x(t) 1. Generate Yt ∼ g(y − x(t)) 2. Take X(t+1) =    Yt with proba. min 1, f (Yt) f (x(t)) , x(t) otherwise
  • 67. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Properties Always accepts higher point and sometimes lower points (similar to gradient algorithms) Depends on the dispersion of g Average probability of acceptance = min{f (x), f (y)}g(y − x) dxdy close to 1 if g has a small variance [Danger!] far from 1 if g has a large variance [Re-Danger!]
  • 68. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Properties Always accepts higher point and sometimes lower points (similar to gradient algorithms) Depends on the dispersion of g Average probability of acceptance = min{f (x), f (y)}g(y − x) dxdy close to 1 if g has a small variance [Danger!] far from 1 if g has a large variance [Re-Danger!]
  • 69. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Properties Always accepts higher point and sometimes lower points (similar to gradient algorithms) Depends on the dispersion of g Average probability of acceptance = min{f (x), f (y)}g(y − x) dxdy close to 1 if g has a small variance [Danger!] far from 1 if g has a large variance [Re-Danger!]
  • 70. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Properties scale=1
  • 71. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Properties scale=2
  • 72. Simulation: a ubiquitous tool for statistical computation Producing randomness by deterministic means Properties scale=3
  • 73. Simulation: a ubiquitous tool for statistical computation Monte Carlo principles General purpose of Monte Carlo methods Given a probability density f known up to a normalizing constant, f (x) ∝ ˜f (x), and an integrable function h, compute I(h) = h(x)f (x)dx = h(x)˜f (x)dx ˜f (x)dx when h(x)˜f (x)dx is intractable. [Remember π!!]
  • 74. Simulation: a ubiquitous tool for statistical computation Monte Carlo principles General purpose of Monte Carlo methods Given a probability density f known up to a normalizing constant, f (x) ∝ ˜f (x), and an integrable function h, compute I(h) = h(x)f (x)dx = h(x)˜f (x)dx ˜f (x)dx when h(x)˜f (x)dx is intractable. [Remember π!!]
  • 75. Simulation: a ubiquitous tool for statistical computation Monte Carlo principles Monte Carlo basics Generate a pseudo-random sample x1, . . . , xN from f and estimate I(h) by ˆIMC N (h) = N−1 N i=1 h(xi ). and let N grow to infinity...
  • 76. Simulation: a ubiquitous tool for statistical computation Monte Carlo principles Monte Carlo basics Generate a pseudo-random sample x1, . . . , xN from f and estimate I(h) by ˆIMC N (h) = N−1 N i=1 h(xi ). and let N grow to infinity... A. Doucet, C. Andrieu, X, A. Philippe, J. Rosenthal, E. Moulines
  • 77. Simulation: a ubiquitous tool for statistical computation Monte Carlo principles Monte Carlo basics Generate a pseudo-random sample x1, . . . , xN from f and estimate I(h) by ˆIMC N (h) = N−1 N i=1 h(xi ). and let N grow to infinity...
  • 78. Simulation: a ubiquitous tool for statistical computation Monte Carlo principles Monte Carlo basics Generate a pseudo-random sample x1, . . . , xN from f and estimate I(h) by ˆIMC N (h) = N−1 N i=1 h(xi ). and let N grow to infinity... Caveat Often impossible or inefficient to simulate directly from f
  • 79. Simulation: a ubiquitous tool for statistical computation Monte Carlo principles Importance Sampling For proposal distribution with density q(x), alternative representations I(h) = h(x){f /q}(x)q(x)dx Principle Generate an iid sample x1, . . . , xN ∼ q and estimate I(h) by ˆIIS q,N(h) = N−1 N i=1 h(xi ){f /q}(xi ).
  • 80. Simulation: a ubiquitous tool for statistical computation Monte Carlo principles Importance Sampling For proposal distribution with density q(x), alternative representations I(h) = h(x){f /q}(x)q(x)dx Principle Generate an iid sample x1, . . . , xN ∼ q and estimate I(h) by ˆIIS q,N(h) = N−1 N i=1 h(xi ){f /q}(xi ).
  • 81. Simulation: a ubiquitous tool for statistical computation Simulated annealing Optimisation problems A (genuine) puzzle During a dinner with 20 couples sitting at four tables with ten seats, everyone wants to share a table with everyone. The assembly decides to switch seats after each serving towards this goal. What is the minimal number of servings needed to ensure that every couple shared a table with every other couple at some point? And what is the optimal switching strategy? [http://xianblog.wordpress.com/2012/04/12/not-le-monde-puzzle/] solution to the puzzle
  • 82. Simulation: a ubiquitous tool for statistical computation Simulated annealing Stochastic minimisation Example (Egg-box function) Consider the function h(x, y) = (x sin(20y) + y sin(20x))2 cosh(sin(10x)x) + (x cos(10y) − y sin(10x))2 cosh(cos(20y)y) , to be minimised.
  • 83. Simulation: a ubiquitous tool for statistical computation Simulated annealing Stochastic minimisation Example (Egg-box function) Consider the function h(x, y) = (x sin(20y) + y sin(20x))2 cosh(sin(10x)x) + (x cos(10y) − y sin(10x))2 cosh(cos(20y)y) , to be minimised. (I know that the global minimum is 0 for (x, y) = (0, 0).)
  • 84. Simulation: a ubiquitous tool for statistical computation Simulated annealing Stochastic minimisation Example (Egg-box function) Consider the function h(x, y) = (x sin(20y) + y sin(20x))2 cosh(sin(10x)x) + (x cos(10y) − y sin(10x))2 cosh(cos(20y)y) , to be minimised. (I know that the global minimum is 0 for (x, y) = (0, 0).)
  • 85. Simulation: a ubiquitous tool for statistical computation Simulated annealing Stochastic minimisation Example (egg-box function (2)) Instead of solving the first order equations ∂h(x, y) ∂x = 0 , ∂h(x, y) ∂y = 0 and of checking that the second order conditions are met, we can generate a random sequence in R2 θj+1 = θj + αj 2βj ∆h(θj , βj ζj ) ζj
  • 86. Simulation: a ubiquitous tool for statistical computation Simulated annealing Stochastic minimisation Example (egg-box function (2)) we can generate a random sequence in R2 θj+1 = θj + αj 2βj ∆h(θj , βj ζj ) ζj where the ζj ’s are uniform on the unit circle x2 + y2 = 1; ∆h(θ, ζ) = h(θ + ζ) − h(θ − ζ); (αj ) and (βj ) converge to 0
  • 87. Simulation: a ubiquitous tool for statistical computation Simulated annealing Calibration parameters choice 1 2 3 4 αj 1/ log(j + 1) 1/100 log(j + 1) 1/(j + 1) 1/(j + 1) βj 1/ log(j + 1).1 1/ log(j + 1).1 1/(j + 1).5 1/(j + 1).1 α ↓ 0 slowly, j αj = ∞ β ↓ 0 more slowly, j (αj /βj )2 < ∞ Scenarios 1-2: not enough energy Scenarios 3-4: good [ c George Casella 1951–2012
  • 88. Simulation: a ubiquitous tool for statistical computation Simulated annealing The traveling salesman problem A classical allocation problem: Salesman who needs to visit n cities in a row Traveling costs between pairs of cities are known Search of the optimal circuit Aboriginal art, NGA, Melbourne
  • 89. Simulation: a ubiquitous tool for statistical computation Simulated annealing The traveling salesman problem A classical allocation problem: Salesman who needs to visit n cities in a row Traveling costs between pairs of cities are known Search of the optimal circuit Aboriginal art, NGA, Melbourne
  • 90. Simulation: a ubiquitous tool for statistical computation Simulated annealing The traveling salesman problem A classical allocation problem: Salesman who needs to visit n cities in a row Traveling costs between pairs of cities are known Search of the optimal circuit Procter & Gamble competition, 1962
  • 91. Simulation: a ubiquitous tool for statistical computation Simulated annealing An NP-complete problem The traveling salesman problem is an example of mathematical problems that require explosive resolution times Aboriginal art, NGA, Melbourne
  • 92. Simulation: a ubiquitous tool for statistical computation Simulated annealing An NP-complete problem The traveling salesman problem is an example of mathematical problems that require explosive resolution times Number of possible circuits n! and exact solutions available in O(2n) time Exact solution for 15, 112 German cities found in 2001 in 22.6 CPU years.
  • 93. Simulation: a ubiquitous tool for statistical computation Simulated annealing An NP-complete problem The traveling salesman problem is an example of mathematical problems that require explosive resolution times Numerous practical consequences (networks, integrated circuit design, genomic sequencing, &tc.) Exact solution for the 24, 978 Sweedish cities found in 2004 in 84.8 CPU years.
  • 94. Simulation: a ubiquitous tool for statistical computation Simulated annealing Resolution via simulation The simulated annealing algorithm: name is borrowed from metallurgy metal manufactured by a slow decrease of temperature (annealing) stronger than when manufactured by fast decrease [ c Joachim Robert, ca. 2006]
  • 95. Simulation: a ubiquitous tool for statistical computation Simulated annealing Resolution via simulation Repeat Random modifications of parts of the original circuit with cost C0 Evaluation of the cost C of the new circuit Acceptation of the new circuit with probability min exp C0 − C T , 1 [Metropolis et al., 1953]
  • 96. Simulation: a ubiquitous tool for statistical computation Simulated annealing Resolution via simulation Repeat Random modifications of parts of the original circuit with cost C0 Evaluation of the cost C of the new circuit Acceptation of the new circuit with probability min exp C0 − C T , 1 T, temperature, is progressively reduced [Metropolis et al., 1953]
  • 97. Simulation: a ubiquitous tool for statistical computation Simulated annealing A family meeting (1) Recall the table puzzle Definition of a target function Set the story of the 20 couple tables during the 6 courses as a (20, 6) matrix, e.g., S =      1 1 3 2 4 2 2 1 3 3 2 4 ... ... ... ... ... ... 3 2 2 2 4 4      and define a penalty function as the number of missed encounters
  • 98. Simulation: a ubiquitous tool for statistical computation Simulated annealing A family meeting (1) Recall the table puzzle Definition of a target function I=sample(rep(1:4,5)) for (i in 2:6) I=cbind(I,sample(rep(1:4,5))) meet=function(I){ M=outer(I[,1],I[,1],"==") for (i in 2:6) M=M+outer(I[,i],I[,i],"==") M } penalty=function(M){ sum(M==0) } penat=penalty(meet(I))
  • 99. Simulation: a ubiquitous tool for statistical computation Simulated annealing A family meeting (2) Random switch of couples Pick two couples [among the 20 couples] at random with probabilities proportional to the number of other couples they have not seen prob=apply(meet(I)==0,1,sum) switch their respective position during one of the 6 courses accept the switch with Metropolis–Hastings probability log(runif(1))<(penalty(old)-penalty(new))/gamma
  • 100. Simulation: a ubiquitous tool for statistical computation Simulated annealing A family meeting (2) Random switch of couples For instance, propose to replace S =      1 1 3 2 4 2 2 1 3 3 2 4 ... ... ... ... ... ... 3 2 2 2 4 4      with S =      1 1 3 2 2 2 2 1 3 3 4 4 ... ... ... ... ... ... 3 2 2 2 4 4     
  • 101. Simulation: a ubiquitous tool for statistical computation Simulated annealing A family meeting (2) Random switch of couples for (t in 1:N){ prop=sample(1:20,2,prob=apply(meet(I)==0,1,sum)) cour=sample(1:6,1) Ip=I Ip[prop[1],cour]=I[prop[2],cour] Ip[prop[2],cour]=I[prop[1],cour] penatp=penalty(meet(Ip)) if (log(runif(1))<(penat-penatp)/gamma){ I=Ip penat=penatp} }
  • 102. Simulation: a ubiquitous tool for statistical computation Simulated annealing A family meeting (3) Solution I [1,] 1 4 3 2 2 3 [2,] 1 2 4 3 4 4 [3,] 3 2 1 4 1 3 [4,] 1 2 3 1 1 1 [5,] 4 2 4 2 3 3 [6,] 2 4 1 2 4 1 [7,] 4 3 1 1 2 4 [8,] 1 3 2 4 3 1 [9,] 3 3 3 3 4 3 [10,] 4 4 2 3 1 1 [11,] 1 1 1 3 3 2 [12,] 3 4 4 1 3 2 [13,] 4 1 3 4 4 2 [14,] 2 4 3 4 3 4 [15,] 2 3 4 2 1 2 [16,] 2 2 2 3 2 2 [17,] 2 1 2 1 4 3 [18,] 4 3 1 1 2 4 [19,] 3 1 4 4 2 1 [20,] 3 1 2 2 1 4 [ c http://www.metrolyrics.com]
  • 103. Simulation: a ubiquitous tool for statistical computation Simulated annealing Solving sudokus Solving a Sudoku grid as a minimisation problem: [ c Dan Rice Sudoku blog]
  • 104. Simulation: a ubiquitous tool for statistical computation Simulated annealing Solving sudokus Given a partly filled Sudoku grid (with a single solution), define a random Sudoku grid by filling the empty slots at random s=matrix(0,ncol=9,nrow=9) s[1,c(1,6,7)]=c(8,1,2) s[2,c(2:3)]=c(7,5) s[3,c(5,8,9)]=c(5,6,4) s[4,c(3,9)]=c(7,6) s[5,c(1,4)]=c(9,7) s[6,c(1,2,6,8,9)]=c(5,2,9,4,7) s[7,c(1:3)]=c(2,3,1) s[8,c(3,5,7,9)]=c(6,2,1,9)
  • 105. Simulation: a ubiquitous tool for statistical computation Simulated annealing Solving sudokus Given a partly filled Sudoku grid (with a single solution), define a random Sudoku grid by filling the empty slots at random define a penalty function corresponding to the number of missed constraints #local score scor=function(i,s){ a=((i-1)%%9)+1 b=trunc((i-1)/9) boxa=3*trunc((a-1)/3)+1 boxb=3*trunc(b/3)+1 return(sum(s[i]==s[9*b+(1:9)])+ sum(s[i]==s[a+9*(0:8)])+ sum(s[i]==s[boxa:(boxa+2),boxb:(boxb+2)])-3) }
  • 106. Simulation: a ubiquitous tool for statistical computation Simulated annealing Solving sudokus Given a partly filled Sudoku grid (with a single solution), define a random Sudoku grid by filling the empty slots at random define a penalty function corresponding to the number of missed constraints fill “deterministic” slots make simulated annealing moves # random moves on the sites i=sample((1:81)[as.vector(s)==0],sample(1:sum(s==0),1,pro=1/(1:sum(s==0)))) for (r in 1:length(i)) prop[i[r]]=sample((1:9)[pool[i[r]+81*(0:8)]],1) if (log(runif(1))/lcur<tarcur-target(prop)){ nchange=nchange+(tarcur>target(prop)) cur=prop points(t,tarcur,col="forestgreen",cex=.3,pch=19) tarcur=target(cur) }
  • 107. Simulation: a ubiquitous tool for statistical computation Simulated annealing Solving sudokus many possible variants in the proposals rather slow and sometimes really slow may get stuck on a penalty of 2 (and never reach zero) does not compete at all with nonrandom solvers