Stochastic Simulation Lecture Notes
Stochastic Simulation Lecture Notes
Ulm University
Institute of Stochastics
Lecture Notes
Dr. Tim Brereton
Summer Term 2014
Ulm, 2014
2
Contents
3
4 CONTENTS
7
8 CHAPTER 1. RANDOM WALKS ETC.
P(Y = 1) = 1 − P(Y = 0) = p.
3 for i = 1:n
4 Y(i) = (rand <= p);
5 end
5 clf;
6 axis([1 n+1 -0.5 1.5]);
7 for i = 1:n
8 line([i, i+.9],[Y(i) Y(i)]);
9 end
1
Yn
2 4 6 8 10 12 14 16 18 20
n
where NU is the number of times the Bernoulli process takes the value 1.
More technically, we define NU as
NU = #{0 ≤ i ≤ n : yi = 1},
Definition 1.2.2 (Random Walk). Given a Bernoulli process {Yn }n≥1 with
parameter p, we define a random walk {Xn }n≥0 with parameter p and initial
condition X0 = x0 by
Because the value of {Xn }n≥0 changes at every value of n, we can draw the
lines to be length 1. This approach is nice, because it reinforces the idea that
{Xn }n≥0 jumps at each value of n (this is made obvious by the gaps between
the lines).
−1
Xn
−2
−3
−4
−5
2 4 6 8 10 12 14 16 18 20
n
Figure 1.2.2: A realization of the first 20 steps of a random walk with p = 0.5.
Note how, as the number of steps simulated gets bigger, the sample paths
look wilder and wilder.
12 CHAPTER 1. RANDOM WALKS ETC.
16
14
12
10
Xn
0
2 4 6 8 10 12 14 16 18 20
n
Figure 1.2.3: A realization of the first 20 steps of a random walk with p = 0.9.
2
Xn
−2
−4
−6
10 20 30 40 50 60 70 80 90 100
n
Figure 1.2.4: A realization of the first 100 steps of a random walk with
p = 0.5.
80
60
40
Xn
20
−20
1000 2000 3000 4000 5000 6000 7000 8000 9000 10000
n
Figure 1.2.5: A realization of the first 10000 steps of a random walk with
p = 0.5.
1.2. RANDOM WALKS 13
If we think about how a random walk can move after n steps (assuming
we know the values of the first n steps), we have
p if xn+1 = xn + 1,
P(Xn+1 = xn+1 | Xn = xn , . . . , X0 = x0 ) = 1 − p if xn+1 = xn − 1,
0 otherwise.
Note that these probabilities do not depend on any value other than Xn .
That is, it is always the case that P(Xn+1 = xn+1 | Xn = xn , . . . , X0 = x0 ) =
P(Xn+1 = xn+1 | Xn = xn ), so {Xn }n≥0 is a Markov chain.
Using this result, we can assign probabilities to various paths of the ran-
dom walk. That is, we can write
where NU is the number of times the random walk goes up. More precisely,
NU = #{1 ≤ i ≤ n : xi − xi−1 = 1}
1.2.4 Distribution of Xn
One thing we might be interested in is the distribution of Xn , given we
only know the initial value of the random walk, x0 . We can make this a bit
14 CHAPTER 1. RANDOM WALKS ETC.
simpler by thinking about the distribution of Xn −x0 (this always starts at 0).
Notice that Xn cannot be more than n steps from x0 . That is, |Xn − x0 | ≤ n.
Also, if x0 is even then Xn must be even if n is even and odd if n is odd. If
x0 is odd, it is the other way around.
Now, Xn − x0 = n can only happen if all n of the steps are up. There is
only one possible path for which this is true. This path has probability pn .
Likewise, Xn − x0 = n − 2 can only happen if all but one of the steps are up.
Any path for which this is true has probability pn−1 (1 − p)1 . However, there
is more than one path that has n − 1 up steps and 1 down step (the first step
could be the down one or the second step could be the down one, etc.). In
n
fact, there are n−1 possible paths. Continuing with this pattern, we have
P(Xn − x0 = x)
( (n+x)/2
n
(n+x)/2
p (1 − p)(n−x)/2 if |x| ≤ n and x have the same parity as n
=
0 otherwise.
Having the same parity means both n and x are even or both n and x are
odd.
Lemma 1.2.5 (First Passage Time Distribution for a Random Walk). The
distribution of the first passage time for a random walk, {Xn }n≥0 with x0 = 0,
where a 6= 0 and A = {a, a + 1, . . .} if a > 0 or A = {a, a − 1, a − 2, . . .} if
a < 0, is given by
(
|a|
P(Xn = a) if a and n have the same parity and n ≥ |a|
P(τA = n) = n .
0 otherwise
Working out first passage time probabilities for a random walk hitting a
with x0 6= 0 is the same as working out first passage time probabilities for a
random walk starting from 0 hitting a − x0 .
Then,
lim SN = EX (1) almost surely.
N →∞
4 X = zeros(N,5);
5
4 tau_4 = zeros(N,1);
5
6 for i = 1:N
7 X = X_0; n = 0;
8 while(X ~= 4)
9 X = X + 2*(rand <= p) - 1;
10 n = n + 1;
11 end
12 tau_4(i) = n;
13 end
14
15 est_expec_tau_4 = mean(tau_4)
Notice that we have to use a ‘while’ loop instead of a ‘for’ loop, as we do not
know how long we will have to simulate {Xn }n≥0 for.
18 CHAPTER 1. RANDOM WALKS ETC.
Eℓb = ℓ.
N
X N
1 (i) 1 X (i)
Eℓb = E I(X5 > 3) = EI(X5 > 3)
N i=1
N i=1
(we can justify exchanging expectation and summation using the fact that the
(i)
sum is finite) and, because the {X5 }Ni=1 are i.i.d. with the same distribution
as X5 ,
N
1 X (i) 1 (1)
EI(X5 > 3) = N EI(X5 > 3) = EI(X5 > 3) = P(X5 > 3) = ℓ.
N i=1 N
1.3. PROPERTIES OF ESTIMATORS 19
Because Monte Carlo estimators are random (they are averages of random
variables), their errors (deviations from the true value) are random as well.
This means we should use probabilistic concepts to describe these errors.
For unbiased estimators, variance / standard deviation is an obvious choice
of error measure. This is because variance is a measure of the deviation of
a random variable from the mean of its distribution (which, for unbiased
estimators, is the value which is being estimated). For an estimator of the
P
form ℓb = N1 N (i) (i) N
i=1 X , with the {X }i=1 i.i.d., the variance is given by
N
!
b = Var 1 X (i) 1 1
Var(ℓ) X = 2
N Var(X (1) ) = Var(X (1) ). (1.2)
N i=1 N N
It should be clear that, as N gets larger, the variance of Monte Carlo esti-
mators gets smaller. The standard deviation of the estimator is given by
q p
(1) )
Std(ℓ) b = Var(X
b = Var(ℓ) √ .
N
Example 1.3.7 (The variance of our estimator of P(X5 > 3)). The variance
of
N
1 X (i)
ℓb = I(X5 > 3),
N i=1
is given by
b = 1
Var(ℓ) Var(I(X5 > 3)).
N
Observe that I(X5 > 3) takes the value 1 with probability ℓ = P(X5 > 3) and
the value 0 with probability 1 − ℓ. That is, it is a Bernoulli random variable
with parameter p = ℓ. Now, the variance of a Ber(p) random variable is given
by p(1 − p). So, Var(I(X5 > 3)) = ℓ(1 − ℓ). In example 1.3.2 we observed
that ℓ = p5 . So,
5 5
b = ℓ(1 − ℓ) = p (1 − p ) .
Var(ℓ)
N N
In order to calculate variances of the form (1.2), we need to know Var(X (1) ).
Unfortunately, we usually do not know this. In the example above, calcu-
lating Var(I(X5 > 3)) required us to know ℓ, which was the very quantity
we were trying to estimate. In practice, we usually estimate the variance
(or, more meaningfully, standard deviation) instead. This is easy to do in
Matlab.
20 CHAPTER 1. RANDOM WALKS ETC.
Listing 1.11: Estimating the mean and variance of our estimator of P(X5 > 3)
1 N = 10^4;
2 n = 5; p = 0.5; X_0 = 0;
3
4 X = zeros(N,5);
5
is approximately Normally distributed with mean 0 and variance Var(X (1) )/N .
As a result, we can make confidence intervals for our estimators. For exam-
ple, a 95% confidence interval would be of the form
p p !
Var(X (1) ) Var(X (1) )
ℓb − 1.96 √ , ℓb + 1.96 √ .
N N
Sometimes, for whatever reason, we are unable to find an unbiased es-
timator, or our unbiased estimator is not very good. For biased estimators
(and, arguably, for unbiased estimators) a good measure of the error is mean
squared error.
1.3. PROPERTIES OF ESTIMATORS 21
Definition 1.3.9 (Mean Squared Error). The mean square error of the es-
b of ℓ is given by
timator, ℓ,
2
b = E ℓb − ℓ .
MSE(ℓ)
The mean square error can be decomposed into variance and bias terms.
b = Var(ℓ)
Lemma 1.3.10. It holds true that MSE(ℓ) b + Bias(ℓ)
b 2.
Proof. We have
2
b = E ℓb − ℓ = Eℓb2 − 2ℓEℓb + ℓ2
MSE(ℓ)
2 2
= Eℓb2 + ℓ2 − 2ℓEℓb + Eℓb − Eℓb
2
= Eℓ − Eℓb + (ℓ − Eℓ)
b2 b2
b + Bias(ℓ)
= Var(ℓ) b2
Eg(X)
P(g(X) ≥ a) ≤ .
a
Proof. It is clear that g(X) ≥ aI(g(X) ≥ a), so Eg(X) ≥ EaI(g(X) ≥ a) =
aEI(g(X) ≥ a) = aP(g(X) ≥ a).
If we set g(x) = (x − EX)2 and a = ǫ2 , where ǫ > 0, we have
(X − EX)2 Var(X)
P((X − EX)2 ≥ ǫ2 ) ≤ 2
⇒ P(|X − EX| ≥ ǫ) ≤ .
ǫ ǫ2
This is Chebyshev’s inequality.
22 CHAPTER 1. RANDOM WALKS ETC.
Var(X)
P(|X − EX| ≥ ǫ) ≤ .
ǫ2
Example 1.3.13 (Error Bounds on Probability Estimators). Consider the
standard estimator of ℓ = P(X > γ),
N
b 1 X
ℓ= I(Xi > γ).
N i=1
We know the variance of this estimator is N −1 P(X > γ)(1 − P(X > γ)). So,
we have the error bound
P(X > γ)(1 − P(X > γ))
P(|ℓb − ℓ| > ǫ) ≤ .
N ǫ2
|f (x)| ≤ Cg(x)
of f is the order of the component function with the biggest order. In our
example, f1 (x) = O(x2 ) and f2 (x) = O(x), so f (x) = O(x2 ).
We use big O notation to describe the behavior of algorithms. If we
measure the dimension of a problem by n — for example, the number of items
in a list that we have to sort — then the work done by the algorithm will
usually be a function of n. Usually, we prefer algorithms with smaller growth
1.4. MARKOV CHAINS 23
rates for the work they have to do. For example, if algorithm 1 accomplishes
a task with O(n) work and another algorithm needs O(n2 ) work, then we
will tend to prefer algorithm 1. However, if the work done by algorithm 1
is f1 (n) = 106 n and the work done by algorithm 2 is f2 (n) = n2 , then the
second algorithm is actually better if n < 106 , even though its order is worse.
It is worth noting that x2 = O(x2 ), but it is also true that x2 = O(x3 ),
so the equals sign is something of an abuse of notation.
Example 1.3.16 (The Standard Deviation of the Monte Carlo Estimator).
The standard deviation of the Monte Carlo estimator
N
b 1 X (i)
ℓ= X ,
N i=1
is q
1
√ Var(X (1) ) = O(N −1/2 ).
N
Example 1.4.1. Consider the Markov chain with the following graphical
representation (the nodes are the states and the arrows represent possible
transitions, with the probabilities attached).
PICTURE HERE
We can also work out the distribution of Xn quite easily. Labeling the
states from 1, . . . , L, the probability that we are in state 1 in the first step is
given by
P(X1 = 1) = λ1 P1,1 + λ2 P2,1 + · · · + λL PL,1 .
Likewise,
P(X1 = 2) = λ1 P1,2 + λ2 P2,2 + · · · + λL PL,2 .
and,
P(X1 = L) = λ1 P1,L + λ2 P2,L + · · · + λL PL,L .
1.4. MARKOV CHAINS 25
P(Xn = j) = (λP n )j .
Given an initial distribution, λ = (1/4, 1/4, 1/4, 1/4), we can calculate the
distribution of Xn in Matlab as follows.
Listing 1.12: Finding the Distribution of Xn
1 n = 2;
2 P = [0 1/3 1/3 1/3; 0 1/2 1/2 0; 1/2 0 0 1/2; 1/2 0 1/2 0];
3 lambda = [1/4 1/4 1/4 1/4];
4
For n = 1, we get
For n = 2, we have
For n = 2, we have
and so on. This suggests that ⌈LU ⌉ is a random variable distributed uni-
formly on {1, . . . , L}.
Listing 1.13: Drawing uniformly from L values.
1 X = ceil(L * rand);
Unfortunately, in the case of Markov chains with big (or infinite) state
spaces, this approach does not work. However, there is often another way
to simulate such Markov chains. We have already seen one such example for
random walks.
1.4.2 Communication
It is very often the case that the distribution of Xn settles down to some
fixed value as n grows large. We saw this in example 1.4.2. In order to
talk about limiting behavior (and stationary distributions, which are closely
related) we need the transition matrix to posses certain properties. For this
reason, we introduce a number of definitions. We say that state i leads to
state j, written i → j, if
PICTURE HERE
Proof. We have
∞
X ∞ X
X x−1
EX = xP(X = x) = P(X = x)
x=1 x=1 i=0
X∞ ∞
X X∞
= P(X = x) = P(X > i),
i=0 x=i+1 i=0
Definition 1.4.14 (rth Passage Time). We define the rth passage time by
(0)
τei = 0 and
(r+1) (r)
τei = inf{n < τi : Xn = i} for r ≥ 0.
We also define a sequence of random variables that are not stopping times
but describe the times between visits to state i.
(r−1) (r)
Lemma 1.4.16. For r ≥ 2, conditional on τei < ∞, Si is independent
(r−1)
τei
of {Xn }n≥0 and
(r) (r−1)
P(Si = n | τei < ∞) = Pi (e
τi = n).
Proof. If we use the strong Markov property with the stopping time τ =
(r−1)
τei , we get that {Xτ +n }n≥0 is a (δi , P ) Markov property that is indepen-
(r)
dent of X0 , . . . , Xτ . Now, we can write Si as
(r)
Si = inf{n > 0 : Xτ +n = i},
(r)
so Si is the first passage time, including return, to state i for {Xτ +n }n≥0 .
1.4. MARKOV CHAINS 31
Proof.
∞
X ∞
X ∞
X ∞
X
n
E i Vi = E i I(Xn = i) = Ei I(Xn = i) = Pi (Xn = i) = Pi,i .
n=0 n=0 n=0 n=0
τi < ∞))r .
Lemma 1.4.18. For r ≥ 0, Pi (Vi > r) = (Pi (e
τi < ∞))r = 0,
Pi (Vi = ∞) = lim Pi (Vi > r) = lim (Pi (e
r→∞ r→∞
so i is transient. Now,
∞
X ∞
X ∞
X 1
n
Pi,i = E i Vi = Pi (Vi > r) = τi < ∞))r =
(Pi (e < ∞.
n=0 r=0 r=0
1 − Pi (e
τ < ∞)
as this only describes the probability of one possible path from i back to i
(such a path need not pass through j). Rearranging, we have
n+r+m
r
Pi,i
Pj,j ≤ n m.
Pi,j Pj,i
πP = π.
PICTURE HERE.
1.4.7 Reversibility
Stationary distributions play a number of very important roles in simula-
tion. In particular, we often wish to create a Markov chain that has a spec-
ified stationary distribution. One important tool for finding such a Markov
chain is to exploit a property called reversibility. Not all Markov chains are
reversible but, as we shall see, those that are have some nice properties.
Proof. We have
X X
(πP )i = πj Pj,i = πi Pi,j = πi .
j∈X j∈X
PICTURE HERE.
PICTURE HERE.
di
πi = P .
i∈X di
Proof. We just need to confirm that the detailed balance equations hold and
that the probabilities sum to 1. First, observe that
di 1 dj 1
P =P holds for all i, j ∈ X .
i∈X di di i∈X dj dj
P
Now, pretty clearly, i∈X πi = 1, so we are done.
1.4. MARKOV CHAINS 39
Example 1.4.42 (A random walk on a graph (cont.)). For the graph given
in example 1.4.40, we have
d1 + d2 + d3 + d4 = 2 + 3 + 3 + 2 = 10.
Thus,
π1 = 2/10, π2 = 3/10, π3 = 3/10, π4 = 2/10.
Theorem 1.4.44 (Ergodic Theorem). Let {Xn }n≥0 be Markov (λ, P ), where
P is an irreducible transition matrix and λ is an arbitrary initial distribution.
Then,
Vi (n) 1
P → as n → ∞ = 1.
n mi
If, in addition, P is positive recurrent, then for any bounded function f :
X → R, !
n−1
1X X
P f (Xk ) → πi f (i) as n → ∞ = 1,
n k=0 i∈X
where π is the stationary distribution of P .
40 CHAPTER 1. RANDOM WALKS ETC.
Proof.
Part 1. If P is transient, then the chain will only return to state i a finite
number of times. This means that
Vi (n) Vi 1
≤ →0= .
n n mi
Now, consider the recurrent case. For a given state i, we have P(e τi < ∞) = 1.
Using the strong Markov property, the Markov chain {Xτei +n }n≥0 is Markov
(δi , P ) and independent of X0 , . . . , Xτei . As the long run proportion of time
spend in i is the same for {Xn }n≥0 and {Xτei +n }n≥0 , we are safe to assume
that the chain starts in i.
Now, by time n − 1, the chain will have made at most V (n) visits to i.
It will certainly have made at least V (n) − 1 visits. The total length of time
required to make all these visits must be less than or equal to n − 1 (because,
by definition, all these visits occur within the first n − 1 steps). This means
that
(1) (V (n)−1)
Si + · · · + Si i ≤ n − 1.
By a similar argument,
(1) (Vi (n))
n ≤ Si + · · · + Si .
Using these bounds, we have
(1) (Vi (n)−1) (1) (Vi (n))
Si + · · · + Si n S + · · · + Si
≤ ≤ i .
Vi (n) Vi (n) Vi (n)
Now, we know the the excursion lengths are i.i.d. random variables (with
finite mean mi ), so, by the large of large numbers,
!
(1) (n)
Si + · · · + Si
P → mi as n → ∞ = 1.
n
Now, we know that P(Vi (n) → ∞ as n → ∞) = 1. So, letting n → ∞, we
squeeze n/Vi (n) to get
n
P → mi as n → ∞ = 1.
Vi (n)
This implies that
Vi (n) 1
P → as n → ∞ = 1.
n mi
Part 2. See [3].
1.5. EXTENDING THE RANDOM WALK MODEL 41
Now, in the case of a random walk, which is a sum of the {Zi }i≥1 random
variables, we know the distribution of Sn (we calculated this earlier). How-
ever, this is not always the case. Normally, in order to find the distribution
of a sum of n random variables, we have to calculate an n-fold convolution or
use either moment generating functions or characteristic functions and hope
that things work out nicely.
Recall, given two independent random variables, X and Y , the convolu-
tion of the distributions of X and Y is given by
∞
X
P(X + Y = z) = P(X = x)P(Y = z − x)
x=−∞
X∞
= P(X = z − y)P(Y = y)
y=−∞
in the discrete case and the convolution, h, of the density of X, f , and the
density of Y , g, is given by
Z ∞ Z ∞
h(z) = (f ∗ g)(z) = f (x)g(z − x)dx = f (z − y)g(y)dy
−∞ −∞
in the continuous case. It is easy to see that the calculations can be pretty
messy if lots of variables with different distributions are involved.
42 CHAPTER 1. RANDOM WALKS ETC.
Sometimes, things are nice. For example, the sum of independent normal
random variables is normally distributed and the sum of i.i.d. exponential
random variables is distributed according to a special case of the gamma
distribution (called the Erlang distribution). But most things are not so
nice. For example, try to work out the distribution of n exponential random
variables with parameters λ1 , . . . , λn .
There are various tools in mathematics that help us deal with sums of
independent random variables. For example, we have the Lindeberg central
limit theorem and a version of the strong law of large numbers. However,
these do not answer all the questions we might reasonably ask and there are
lots of random variables that do not satisfy the technical conditions of these
theorems. Simulation is a useful tool for solving problems in these settings.
We will consider a couple of examples that use normal random variables.
Recall that if Z ∼ N(0, 1) then X = µ + σZ ∼ N(µ, σ 2 ). This means we can
simulate a normal random variable with mean µ and variance σ 2 in Matlab
using the command
X = mu + sqrt(sigma_sqr) * randn;
6 for i = 1:N
7 Z = mu + sqrt(sigma_sqr) .* randn(1,5);
8 V = exp(Z);
9 V_max(i) = max(V);
10 S(i) = sum(V);
11 end
12
13 est_mean = mean(S)
14 actual_mean = sum(exp(mu + sigma_sqr/2))
15
16 est_var = var(S)
17 actual_var = sum((exp(sigma_sqr) - 1) .* exp(2 * mu + sigma_sqr))
18
19 ell_est = mean(S>threshold)
20 ell_RE = std(S>threshold) / (ell_est * sqrt(N))
21
est_mean = 5.6576
actual_mean = 5.6576
est_var = 1.9500
actual_var = 1.9511
ell_est = 2.3800e-06
ell_RE = 0.0917
44 CHAPTER 1. RANDOM WALKS ETC.
avg_max_v = 15.9229
avg_S = 21.5756
τS = inf{n ≥ 1 : Sn ≥ 1000}
τB = inf{n ≥ 1 : Sn ≤ −10000}.
5 for i = 1:N
6 S = 0; n = 0;
7 while S > low && S< up
8 S = S + (mu + sigma * randn);
9 n = n + 1;
10 end
11 sold(i) = S > up;
12 days(i) = n;
1.6. IMPORTANCE SAMPLING 45
13 end
14
15 ell_est = mean(sold)
16 est_RE = sqrt(sold) / (sqrt(N)*ell_est)
17
21 avg_days_if_sold = mean(days(event_occurs_index))
22 avg_days_if_bankrupt = mean(days(event_does_not_occur_index))
ell_est = 0.0145
ell_RE = 0.0026
avg_days_if_sold = 52.9701
avg_days_if_bankrupt = 501.5879
So N = O(1/P(X > γ)) which means N gets big very quickly as ℓ = P(X >
γ) → 0. This is a big problem in areas where events with small probabilities
are important. There are lots of fields where such events are important: for
example, physics, finance, telecommunication, nuclear engineering, chemistry
and biology. One of the most effective methods of estimating these probabil-
ities is called importance sampling.
46 CHAPTER 1. RANDOM WALKS ETC.
where X (1) , . . . , X (N ) are i.i.d. draws from the density f . Now, suppose
the expectation of S(X) is most influenced by a subset of values with low
probability. For example, if S(X) = I(X > γ) and P(X > γ) is small,
then this set of values would be {x ∈ X : S(x) > γ}. We want to find a
way to make this ‘important’ set of values happen more often. This is the
idea of importance sampling. The idea is to sample {X (i) }N i=1 according to
another density, g, that ascribes much higher probability to the important
set. Observe that, given a density g such that g(x) = 0 ⇒ f (x)S(x) = 0,
and being explicit about the density used to calculate the expectation,
Z ∞ Z ∞
g(x)
Ef S(X) = S(x) f (x) dx = S(x) f (x) dx
−∞ −∞ g(x)
Z ∞
f (x) f (X)
= S(x) g(x) dx = Eg S(X).
−∞ g(x) g(X)
We call f (x)/g(x) the likelihood ratio. This suggests, immediately, the im-
portance sampling estimator
Definition 1.6.1 (The Importance Sampling Estimator). The importance
sampling estimator, ℓbIS , of ℓ = ES(X) is given by
N
b 1 X f (X (i) )
ℓIS = (i)
S(X (i) ),
N i=1 g(X )
This gives a value of 2.87 × 10−7 which is more or less identical to the value
returned by our estimator.
Example 1.6.4 (A rare event for a random walk). Given a random walk,
{Xn }n≥0 , with x0 = 0 and p = 0.4, what is ℓ = P(X50 > 15)? We can
estimate this in Matlab using standard Monte Carlo.
Listing 1.19: Matlab code
1 N = 10^5; threshold = 15;
2 n = 50; p = 0.4; X_0 = 0;
3 X_50 = zeros(N,1);
4
5 for i = 1:N
6 X = X_0;
7 for j = 1:n
8 Y = rand <= p;
9 X = X + 2*Y - 1;
10 end
11 X_50(i) = X;
12 end
13 ell_est = mean(X_50 > threshold)
14 RE_est = std(X_50 > threshold) / (sqrt(N) * ell_est)
then, the original random walk is simulated by generating the {Zi }i≥1 ac-
cording to the probability mass function p I(Z = 1) + (1 − p) I(Z = −1).
Generating the new random walk means generating the {Zi }i≥1 according to
50 CHAPTER 1. RANDOM WALKS ETC.
the probability mass function q I(Z = 1) + (1 − q) I(Z = −1). This then gives
a likelihood ratio of the form
Yn n
p I(Zi = 1) + (1 − p) I(Zi = −1) Y p 1−p
= I(Zi = 1) + I(Zi = −1) .
i=1
q I(Zi = 1) + (1 − q) I(Zi = −1) i=1
q 1−q
5 for i = 1:N
6 X = X_0; LR = 1;
7 for j = 1:n
8 Y = rand <= q;
9 LR = LR * (p/q * (Y == 1) + (1-p) / (1 - q) * (Y == 0));
10 X = X + 2*Y - 1;
11 end
12 LRs(i) = LR;
13 X_50(i) = X;
14 end
15 ell_est = mean(LRs .* (X_50 > threshold))
16 RE_est = std(LRs .* (X_50 > threshold)) / (sqrt(N) * ell_est)
M (θ) = EeθX .
The rules of thumb, which only apply when dealing with light-tailed ran-
dom variables, are as follows.
• For stopping time problems, e.g., P(τA < τB ) or P(τA < ∞), where
the process is drifting away from A, the set of interest, choose g so
that the drift of the stochastic
Pn process is reversed. For example, if
A = {10, 11, . . .} and Sn = i=1 Yi , with Yi ∼ N(−1, 1), then choose g
so that Eg Z1 = 1.
h(x)
f (x) = ,
Z
R
where Z is the normalizing constant (that is Z = h(x) dx). In many
realistic applications, we do not know Z, even if we do know h and have a
way of sampling from f (it is often possible to sample from a density without
knowing its normalizing constant). An obvious problem, then, is how we
should carry out importance sampling in such a setting.
Weighted importance sampling is one way of addressing this problem. The
normal importance sampling estimator is of the form
N
b 1 X f (X(i) )
ℓIS = (i)
S(X(i) ),
N i=1 g(X )
where X(1) , . . . , X(N ) is an i.i.d. sample from g. This returns a sample mean
that is weighted by the likelihood ratios
f (X(1) ) f (X(N ) )
, . . . , .
g(X(1) ) g(X(N ) )
52 CHAPTER 1. RANDOM WALKS ETC.
Note that this estimator is biased. However, the bias is O(1/n), so it is not
too bad in practice (and we don’t always have an alternative).
However, we can often write this in a more convenient form. Note that,
f (y1 , . . . , yn ) = f (y1 )f (y2 | y1 ) · · · f (yn | y1 , . . . , yn−1 ),
or, in Bayesian notation (which makes things a bit more compact),
f (y1:n ) = f (y1 )f (y2 | y1 ) · · · f (yn | y1:n−1 )
Likewise, we can write
g(y1:n ) = g(y1 )g(y2 | y1 ) · · · g(yn | y1:n−1 ).
If we know these conditional densities, then we can write the likelihood ratio
in the form
f (y1 )f (y2 | y1 ) · · · f (yn | y1:n−1 )
Wn (y1:n ) = .
g(y1 )g(y2 | y1 ) · · · g(yn | y1:n−1 )
If we write,
f (y1 )
W1 (y1 ) = ,
g(y1 )
then
f (y2 | y1) f (y1 ) f (y2 | y1)
W2 (y1:2 ) = = W1 (y1 ),
g(y2 | y1) g(y1 ) g(y2 | y1)
and, more generally,
f (yn | y1:n−1 )
Wn (y1:n ) = Wn−1 (y1:n−1 ).
g(yn | y1:n−1 )
In cases where the Markov property holds,
f (yn | yn−1 )
Wn (y1:n ) = Wn−1 (y1:n−1 ).
g(yn | yn−1 )
Using this formulation, we can update until a stopping time, then stop up-
dating. This formulation also allows for sophisticated methods, such as those
were certain low probability paths (i.e., paths with very small weights) are
randomly killed.
54 CHAPTER 1. RANDOM WALKS ETC.
Self-avoiding random walks are simply random walks that do not hit
themselves.
5 5
4 4
3 3
2 2
1 1
0 0
−1 −1
−2 −2
−3 −3
−4 −4
−5 −5
−5 −4 −3 −2 −1 0 1 2 3 4 5 −5 −4 −3 −2 −1 0 1 2 3 4 5
10 10
8 8
6 6
4 4
2 2
0 0
−2 −2
−4 −4
−6 −6
−8 −8
−10 −10
−10 −8 −6 −4 −2 0 2 4 6 8 10 −10 −8 −6 −4 −2 0 2 4 6 8 10
Self avoiding walks are useful as simple models of objects like polymers.
They capture some fundamental behavior of strings of molecules that cannot
be too close to one another, but otherwise have minimal interaction. They
also appear in mathematical objects like random graphs and percolation
clusters.
It is easy to generate a self-avoiding random walk of length n via Monte
Carlo if n is small. We simply simulate random walks of length n until one
of them is self-avoiding.
Listing 1.21: Matlab code
1.6. IMPORTANCE SAMPLING 55
1 n = 7; i = 1;
2
3 while(i ~= n)
4 X = 0; Y = 0;
5 lattice = zeros(2*n + 1, 2*n+1);
6 lattice(n+1, n+1) = 1;
7 path = [0 0];
8 for i = 1:n
9
10 U = rand;
11 if U < 1/2
12 X = X + 2 * (U < 1/4) - 1;
13 else
14 Y = Y + 2 * (U < 3/4) - 1;
15 end
16
17 path_addition = [X Y];
18 path = [path; path_addition];
19
20 lattice_x = n + 1 + X;
21 lattice_y = n + 1 + Y;
22
23 if lattice(lattice_x, lattice_y) == 1
24 i = 1; break;
25 else
26 lattice(lattice_x, lattice_y) = 1;
27 end
28 end
29 end
30
The problem is that for large n, it is very unlikely that a random walk
will be a self-avoiding random walk. To put this in perspective, there are 4n
possible random walks of length n on the 2D square lattice. In general, the
number of self-avoiding random walks for a given n is not known. However,
for small n, these have been calculated.
• For n = 5, there are 284 self-avoiding walks. So, the probability that a
56 CHAPTER 1. RANDOM WALKS ETC.
• For n = 10, there are 441000 self-avoiding random walks. So, the
probability is
44100 44100
10
= ≈ 0.0421.
4 1048576
This means we need to generate about 24 walks in order to get a self-
avoiding one.
PICTURE HERE
4 while(i ~= n)
5 X = 0; Y = 0;
6 lattice = zeros(2*(n+1) + 1, 2*(n+1)+1);
7 lattice(n+2, n+2) = 1;
1.6. IMPORTANCE SAMPLING 57
8 path = [0 0];
9 for i = 1:n
10 lattice_x = n + 2 + X; lattice_y = n + 2 + Y;
11
12 up = lattice(lattice_x,lattice_y + 1);
13 down = lattice(lattice_x,lattice_y - 1);
14 left = lattice(lattice_x-1,lattice_y);
15 right = lattice(lattice_x+1,lattice_y);
16 neighbors = [1 1 1 1] - [up down left right];
17
18 if sum(neighbors) == 0
19 i = 1; break;
20 end
21
22 direction = ...
23 min(find(rand<(cumsum(neighbors)/sum(neighbors))));
24 X = X + moves(direction,1);
25 Y = Y + moves(direction,2);
26
27 lattice_x = n + 2 + X; lattice_y = n + 2 + Y;
28 lattice(lattice_x,lattice_y) = 1;
29 path_addition = [X Y];
30 path = [path; path_addition];
31 end
32 end
33
This approach does not solve all our problems (it is still possible to a
path to die out early), however it significantly increases the length of the
self-avoiding walks we are able to generate in a reasonable amount of time.
Unfortunately, this approach does not generate self-avoiding walks of length
n uniformly. Consider the two self-avoiding random walks of length 5 shown
in figures 1.6.3 and 1.6.4. The first has probability 1/4×1/3×1/3×1/3×1/3
and the second has probability 1/4 × 1/3 × 1/3 × 1/3 × 1/2. Basically, the
algorithm is biased towards more compact configurations. You can also see
this in figure 1.6.5 and figure 1.6.5, which are less spread out than most self-
avoiding walks. The obvious way to try to fix this is importance sampling.
The probability mass function for self-avoiding walks starting at x0 =
58 CHAPTER 1. RANDOM WALKS ETC.
−5
−10
−15
−20
−25
−30
−30 −25 −20 −15 −10 −5 0 5
10
−5
−10
−15
−20
−10 −5 0 5 10 15 20 25 30
1
PN (i) (i) (i)
2
N i=1 d0 · · · dn−1 Xn
ℓbIS = PN (i) (i)
,
1
N i=1 d0 · · · dn−1
(1) (N )
where Xn , . . . , Xn are i.i.d. draws from q(x1 , . . . , xn ), and the values
(i) (i)
d1 , . . . , dn etc. are functions of the appropriate self-avoiding random walk.
An implementation of the standard Monte Carlo approach is
Listing 1.23: Matlab code
1 N = 10^5; n = 5;
2 square_extension = zeros(N,1);
3
18 lattice_x = n + 1 + X;
19 lattice_y = n + 1 + Y;
20
21 if lattice(lattice_x, lattice_y) == 1
1.6. IMPORTANCE SAMPLING 61
22 i = 1;
23 break;
24 else
25 lattice(lattice_x, lattice_y) = 1;
26 end
27 end
28 end
29
33 mean_square_extension = mean(square_extension)
18 if sum(neighbors) == 0
19 i = 1; break;
20 end
21 weight = weight * sum(neighbors);
22 direction = ...
23 min(find(rand<(cumsum(neighbors)/sum(neighbors))));
24 X = X + moves(direction,1);
25 Y = Y + moves(direction,2);
26 lattice_x = n + 2 + X; lattice_y = n + 2 + Y;
27 lattice(lattice_x,lattice_y) = 1;
28 end
62 CHAPTER 1. RANDOM WALKS ETC.
29 end
30 weights(step_i) = weight;
31 square_extension(step_i) = X^2 + Y^2;
32 end
33 mean_square_extension = ...
34 mean(weights’.*square_extension) / mean(weights)
Chapter 2
63
64 CHAPTER 2. POISSON PROCESSES AND CTMCS
We need the filtration to contain some information about {Xt }t≥0 (other-
wise, it is not very useful). We say {Xt }t≥0 is adapted to a filtration, {Ft }t≥0
if the filtration contains sufficient information about {Xt }t≥0 . More formally,
We can also define a continuous time general state space version of the
Markov property.
(iv) Has unit jumps. That is, Nt − Nt− ∈ 0, 1. Technically, a process where
only one jump can occur at a given time t is called a simple point
process.
PICTURE HERE
These three definitions of point processes suggest three possible ways to
simulate them.
(i) We can simulate the counting process {Nt }t≥0 (or its increments).
The key properties of a Poisson process (aside from being a point process)
are that it has stationary increments and independent increments.
Rearranging, we have
p0 (t + h) − p0 (t) o(h)
= −λp0 (t) + .
h h
2.2. THE POISSON PROCESS 69
Part 3. We show that (iii) implies (ii). This is just like the proof that (i)
implies (ii). Using the Markov property (which was based on the interarrivals
definition) we observe that Nt+h − Nt has the same distribution as Nh , so
and
P(Nt+h − Nt > 1) = P(S1 < h, S1 + S2 < h) ≤ P(S1 < h)P(S2 < h) = o(h).
Proof. We have
P X(1) ≤ x = 1 − P X(1) > x = 1 − P(X1 > x, . . . , Xn > x)
= 1 − P(X1 > x) · · · P(Xn > x) = 1 − (P(X > x))n = 1 − (1 − F (x))n .
Proof. We have
P X(n) ≤ x = P(X1 ≤ x, . . . , Xn ≤ x) = P(X ≤ x)n = F (x)n .
λn e−λt
f (t1 , . . . , tn ) = I(0 ≤ t1 ≤ · · · ≤ tn ≤ t)
(λt)n e−λt /n!
n!
= n I(0 ≤ t1 ≤ · · · ≤ tn ≤ t).
t
5 N(1) = 0;
6
7 for i = 2:length(mesh)
8 if rand < lambda * h
2.2. THE POISSON PROCESS 73
16 if isempty(jump_indices)==0
17 Ts = (jump_indices - 1)*h;
18 S(1) = Ts(1);
19 if length(jump_indices) > 1
20 for i = 2:length(jump_indices)
21 S(i) = Ts(i) - Ts(i-1);
22 end
23 end
24 end
The idea of this approach is to simulate the arrival times directly. Given
an interval [0, t], we know that we have a Poi(λt) random number of arrivals.
These are then distributed uniformly in [0, t].
3 T = [];
4 n = poissrnd(lambda * t);
5
6 if n~=0
7 T = sort(t * rand(n,1));
8 S = zeros(n,1);
9 S(1) = T(1);
10 if n > 1
11 for i = 2:n
12 S(i) = T(i) - T(i-1);
13 end
14 end
15 end
74 CHAPTER 2. POISSON PROCESSES AND CTMCS
3 s = 0;
4
5 S = []; Ts = [];
6
7 while s <= t
8 inter_time = - log(rand) / lambda;;
9 s = s + inter_time;
10 if s > t
11 break;
12 else
13 Ts = [Ts s];
14 S = [S inter_time];
15 end
16 end
(i) N0 = 0.
(iii) For each 0 ≤ t1 < t2 < · · · < tm , the random variables Nt1 , . . . , Ntm −
Ntm−1 are independent (that is, {Nt }t≥0 has independent increments).
Acceptance-Rejection
One way to simulate an inhomogenous Poisson process on an interval [0, t]
is to simulate a homogenous Poisson process with parameter
λ∗ = max{λ(s) : 0 ≤ s ≤ t}
then ‘thin’ this process by only accepting arrivals with a certain probability.
If an arrival / jump occurs at time Ti it should only be accepted with prob-
ability λ(T1 )/λ∗ . It is not hard to check that this method works using the
infinitesimal definition.
Listing 2.4: Matlab code
1 t = 10; lambda_star = 1;
2
3 T = [];
4 n = poissrnd(lambda_star * t);
5
6 if n~=0
7 point_count = 0;
8 for i = 1:n
9 T_temp = t * rand;
10 if rand < sin(T_temp)^2 / lambda_star
11 point_count = point_count + 1;
12 T(point_count) = T_temp;
76 CHAPTER 2. POISSON PROCESSES AND CTMCS
13 end
14 end
15 if point_count ~= 0
16 T = sort(T);
17 S = zeros(point_count,1);
18 S(1) = T(1);
19 if point_count > 1
20 for i = 2:point_count
21 S(i) = T(i) - T(i-1);
22 end
23 end
24 end
25 end
0.8
0.6
0.4
0.2
0
0 1 2 3 4 5 6 7 8 9 10
5 N(1) = 0;
6
7 for i = 2:length(mesh)
8 if rand < 3*sin(h*(i-1))^2 * h
9 jump_indices = [jump_indices i];
10 N(i) = N(i-1) + 1;
11 else
12 N(i) = N(i-1);
13 end
14 end
15
16 if isempty(jump_indices)==0
17 Ts = (jump_indices - 1)*h;
18 S(1) = Ts(1);
19 if length(jump_indices) > 1
20 for i = 2:length(jump_indices)
21 S(i) = Ts(i) - Ts(i-1);
22 end
23 end
24 end
Nt
X
Xt = Ji ,
i=1
is a compound Poisson process, where the jumps {Jn }n≥0 are i.i.d. draws
from the distribution G.
Example 2.2.17. A street musician plays the accordion in the main street
of Ulm for three hours. He hopes to earn enough for a beer, which costs
C3.50. Throughout the three hours, people give him coins at random. There
A
does not seem to be any pattern to when people give him money, so a Poisson
78 CHAPTER 2. POISSON PROCESSES AND CTMCS
process is a good model. The amount of money each person gives is random,
with distribution
C0.05) = 2/5
P(A
C0.10) = 2/5
P(A
C0.20) = 1/5.
P(A
On average, 5 people per hour give the street musician money. This implies
that the Poisson process has intensity λ = 5. What is the probability the
musician gets his beer? That is, what is ℓ = P(X3 ≥ 3.50). We can estimate
this easily using Monte Carlo.
Listing 2.6: Matlab code
1 t = 3; lambda = 5; N = 10^6;
2 beer = zeros(N,1); beer_price = 350;
3
4 for i = 1:N
5
6 n = poissrnd(lambda * t);
7
8 if n~=0
9 coins = zeros(n,1);
10 for j = 1:n
11 U = rand;
12 coins(j) = (U <= 2/5)*5 + ...
13 (U > 2/5 && U <= 4/5)*10 + (U > 4/5)*20;
14 end
15 end
16
20 ell_hat = mean(beer)
21 re_hat = std(beer) / (ell_hat * sqrt(N))
work with than discrete time Markov chains, because there are a number
of technical issues and strange / pathological things that can happen. This
behavior is mainly related to situations where an infinite number of jumps
can happen in a finite time. In this course, we will not consider chains where
such things happen. This is because these chains can not really be simulated
and considering a smaller subset of continuous time Markov chains will be
sufficient for modeling most real world phenomena we might be interested
in.
The chains we consider can be described in two different but equivalent
ways: transition functions and infinitesimal genertors. Warning: these de-
scriptions are not always equivalent or even valid when working with more
general classes of CTMCs.
PICTURE HERE
The jump chain {Yn }n≥0 is a discrete time Markov chain, so it can be de-
scribed by a transition matrix J (we do not use P in order to avoid confusion
with the transition function P ). As it turns out, J can be written in terms
of the Q-matrix.
2.3. CONTINUOUS TIME MARKOV CHAINS 81
PICTURE HERE
and the amount of time spent in state 1 is Exp(λ), the amount of time spent
in state 2 is Exp(λ + µ) and the amount of time spent in state 3 is Exp(µ).
Birth-Death Process
A Poisson process is sometimes called a pure birth process, as it models a
population that is constantly growing. More generally, birth-death processes
are simple models of populations where births and deaths happen at random.
A simple example is the following
PICTURE HERE
The Q-matrix for this chain is of the form
−λ λ 0 0 0 ···
µ −(µ + λ) λ 0 0 ···
Q= 0 µ −(µ + λ) λ 0 ··· .
.. ... ... ... ... ...
.
3 Q = [-9 2 3 4; 1 -4 3 0; 1 2 -7 4; 1 0 3 -4];
4 J = [0 2/9 3/9 4/9; 1/4 0 3/4 0; 1/7 2/7 0 4/7; 1/4 0 3/4 0];
5
9 while t <= T
10 t = t + log(rand) / Q(X,X);
11 if t > T
12 break;
13 else
14 jump_times = [jump_times t];
15 X = min(find(rand<cumsum(J(X,:))));
16 jump_chain = [jump_chain X];
17 end
18 end
PICTURE HERE
6 while t <= T
7 t = t - log(rand) / (lambda + X*mu);
8 if t > T
84 CHAPTER 2. POISSON PROCESSES AND CTMCS
9 break;
10 else
11 jump_times = [jump_times t];
12
P (t) = etQ
where etQ is the matrix exponential. It might at first be unclear how to define
a matrix exponential. However, if we remember the Taylor series definition
of the exponential, then we realise we can write something equivalent using
matrices. That is
X∞
(tQ)k
P (t) = .
k=0
k!
Warning! It is often very computationally challenging to compute a matrix
exponential. The answer the computer gives you might not always be correct.
In Matlab you need to use ‘expm’ rather than ‘exp’ if you wish to use the
matrix exponential.
We can calculate etQ easily using Matlab. For t = 0.01, 0.1, 1, 10, 100 we
have
Looking at the example, we see that the distribution of the chain seems
to converge to a stationary distribution.
Theorem 2.3.10. Consider a CTMC {Xt }t≥0 with Q-matrix Q and jump
chain {Yn }n≥0 . For distinct states i and j the following are equivalent
(i) i → j.
(iii) qi,k1 qk1 ,k2 · · · qkn ,j > 0 for some n > 0 and states k1 , . . . , kn .
Pi ({t ≥ 0 : Xt = i} is unbounded) = 1.
Pi ({t ≥ 0 : Xt = i} is unbounded) = 0.
Theorem 2.3.11. Consider a CTMC {Xt }t≥0 with jump chain {Yn }n≥0 .
µQ = 0.
Theorem 2.3.13. Given a CTMC {Xt }t≥0 with Q-matrix Q and jump ma-
trix J, the following are equivalent
Note that 1/qi is the expected holding time in state i, so µ has elements
µi = νi /qi and is thus a invariant measure for the jump chain reweighted
by the expected time spent in each state. Note that neither µ or ν is nec-
essarily a probability distribution. Furthermore, even if µ is a probability
distribution, the ν defined in respect to it will probably not be a probability
2.3. CONTINUOUS TIME MARKOV CHAINS 87
The only CTMCs that satisfy detailed balance are reversible ones.
89
90 CHAPTER 3. GAUSSIAN PROCESSES ETC.
INDEPENDENCE
There is nothing too difficult about dealing with the mean vector µ. How-
ever, the covariance matrix makes things pretty difficult, especially when we
wish to simulate a high dimensional random vector. In order to simulate
Gaussian processes effectively, we need to exploit as many properties of co-
variance matrices as possible.
(i) rank(A) = n.
Lemma 3.1.7 (Necessary and sufficient conditions for an SPD). The fol-
lowing are necessary and sufficient conditions for an n × n matrix A to be
SPD
x⊺ Ax ≥ 0 for all x 6= 0.
92 CHAPTER 3. GAUSSIAN PROCESSES ETC.
A = LL⊺ ,
though it is not necessarily unique and L may have zeroes on the diagonals.
Now this must be non-negative (as it is a variance). That is, it must be the
case that
x⊺ Var (Y) x ≥ 0,
µ(t) = EXt
r(s, t) = Cov(Xs , Xt ).
Using these, we can simulate the values of a Gaussian process at fixed times
t1 , . . . , tn by calculating µ where µi = µ(t1 ) and Σ, where Σi,j = r(ti , tj ) and
then simulating a multivariate normal vector.
In the following examples, we simulate the Gaussian processes at evenly
spaced times t1 = 1/h, t2 = 2/h, . . . , tn = 1.
13 for i = 1:n
14 for j = 1:n
15 Sigma(i,j) = min(t(i),t(j));
16 end
17 end
18
23 %Plot
24 plot(t,X);
0.2
−0.2
−0.4
−0.6
Xt
−0.8
−1
−1.2
−1.4
−1.6
−1.8
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
t
25 %Plot
26 plot(t,X);
2.5
1.5
1
Xt
0.5
−0.5
−1
−1.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
t
1
Xt
−1
−2
−3
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
t
where H ∈ (0, 1) is called the Hurst parameter. When H = 1/2, fBm re-
duces to standard Brownian motion. Brownian motion has independent in-
crements. In contrast, for H > 1/2 fBm has positively correlated increments
and for H < 1/2 fBm has negatively correlated increments.
Listing 3.5: Matlab code
1 %Hurst parameter
2 H = .9;
3
20 end
21 end
22
27 %Plot
28 plot(t,X);
1.5
0.5
Xt
−0.5
−1
−1.5
−2
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
t
0.2
0.1
−0.1
Xt
−0.2
−0.3
−0.4
−0.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
t
Lemma 3.1.17. Gaussian processes that are weak stationary are stationary.
Proof. We know from theorem 3.1.5 that Gaussian distributions are entirely
determined by their mean vector and covariance matrix. Since the mean and
covariance of a weakly stationary process do not change when the times are
all shifted by s, a weakly stationary Gaussian process is stationary.
σ0 σ1 σ2 · · · σn σn−1 σn−2 ··· σ2 σ1
σ1 σ0 σ1 · · · σn−1 σn σn−1 ··· σ3 σ2
...
σ2 σ1 σ0 σn−2 σn−1 σn ··· σ4 σ3
. ... ... ... ... ... ... ... ... ..
.. .
σ σn−1 σn−2 · · · σ0 σ1 σ2 · · · σn σn−1
Σ=
σ
n .
n−1 σn σn−1 · · · σ1 σ0 σ1 · · · σn−3 σn−2
σ · · · σ2 · · · σn−4 σn−3
n−2 σn−1 σn σ1 σ0
σ · · · σ3 · · · σn−5 σn−4
n−3 σn−2 σn−1 σ2 σ1
. ... ... ... ... ... ... ... ... ..
.. .
σ1 σ2 σ3 · · · σn−1 σn−2 σn−3 · · · σ1 σ0
This might not seem very useful, but the strength of this representation
comes from its link to the discrete Fourier transform and, through it, to that
wonder of numerical analysis: the Fast Fourier Transform (FFT).
Definition 3.1.20 (Discrete Fourier Transform). Given a complex valued
e =
vector x = (x0 , . . . , xn )⊺ , we define its discrete Fourier transform by x
(e
x0 , . . . , x
en−1 ) , where
⊺
n−1
X n−1
X
x
ej = e−(2πi/n)jk xk = ω jk xk
k=0 k=0
and p
E=F diag(λ/n),
then
E Ē ⊺ = F diag(λ)F̄ /n = F diag(λ)F −1 = B.
In other words E is the complex square-root of the matrix B.
Let B be the covariance matrix of a zero-mean Gaussian process evaluated
at equidistant steps. Now, if we write E = E1 + iE2 then
Let
X1 = R(X) = E1 Z1 − E2 Z2
and
X2 = I(X) = E2 Z1 + E1 Z2 .
Then, clearly, EX1 = 0 and
The calculation for X2 is more or less identical. Note X1 and X2 are not
independent of one another.
This gives the following algorithm for generating a stationary Gaussian
process at equidistant intervals. Using the FFT, the algorithm is O(n log n).
and
Var(X2 | X1 ) = Σ22 − Σ21 Σ−1
11 Σ12 .
3.1. GAUSSIAN PROCESSES 105
16 %Interpolate
17 for level = 2:num_levels
18 %Make the additional mesh points
106 CHAPTER 3. GAUSSIAN PROCESSES ETC.
and
µi = EXti .
By theorem 3.1.24, we know that (Xti , Xti+1 )⊺ has a multivariate normal
distribution. In particular,
Xt i µi σi,i σi,i+1
∼N , .
Xti+1 µi+1 σi,i+1 σi+1,i+1
Using theorem 3.1.25, we have
2
σi,i+1 σi,i+1
Xti+1 | Xti = xi ∼ N µi + (xi − µi ) , σi+1,i+1 − .
σi, i σi,i
Algorithm 3.1.2 (Generating a Markovian Gaussian Process).
√
(i) Draw Z ∼ N(0, 1). Set Xt1 = µ1 + σi,i Z.
(ii) For i = 1, . . . , m − 1 draw Z ∼ N(0, 1) and set
s
2
σi,i+1 σi,i+1
Xti+1 = µi + (Xti − µi ) + σi+1,i+1 − Z.
σi, i σi,i
5 for i = 1:m-1
6 X(i+1) = X(i) + sqrt(h) * randn;
7 end
8
9 plot(h:h:1,X);
108 CHAPTER 3. GAUSSIAN PROCESSES ETC.
3 X = zeros(m,1); h = 1/m;
4 X(1) = randn;
5
6 for i = 1:m-1
7 X(i+1) = exp(-alpha * h / 2)*X(i)...
8 + sqrt(1 - exp(-alpha * h))*randn;
9 end
10
11 plot(h:h:1,X);
This definition implies that the increments of Brownian motion are nor-
mally distributed. Specifically, Wt+s − Wt ∼ N(0, s). This implies the follow-
ing simualtion scheme.
The first three parts of the definition of Brownian motion are equivalent to
saying Brownian motion is a Gaussian process with Cov(Xt , Xs ) = min(t, s)
and EXt = 0. However, the almost sure continuity of the paths of Brownian
motion does not follow from this.
Theorem 3.2.2. The following two statements are equivalent for a stochastic
process {Xt }t≥0 .
(i) {Xt }t≥0 has stationary independent increments and Xt ∼ N(0, t).
(ii) {Xt }t≥0 is a Gaussian process with µ(t) = EXt = 0 and r(s, t) =
Cov(Xt , Xs ) = min(t, s).
Proof.
Part 1. First, we show (i) implies (ii). In order to show this, we need to show
that (Xt1 , . . . , Xtn ) is multivariate normal for all choices of 0 ≤ t1 ≤ · · · ≤ tn
and n ≥ 1. In order to Xt1 , . . . , Xtn to be multivariate normal, we need
110 CHAPTER 3. GAUSSIAN PROCESSES ETC.
Pn
k=1 αk Xtk to be univariate normal (for all choices of n etc.). Now,
n
X n
X
α k Xt k = α 1 Xt 1 + α k Xt k
k=1 k=2
n k k−1
!
X X X
= α 1 Xt 1 + αk Xt j − Xt j
k=2 j=1 j=1
n k k
!
X X X
= α 1 Xt 1 + αk Xt j − Xtj−1
k=2 j=1 j=2
n
X n X
X k
= α k Xt 1 + αk Xtj − Xtj−1
k=1 k=2 j=2
n
! n n
!
X X X
= αk Xt 1 + αk Xtj − Xtj−1
k=1 j=2 k=j
n
X
= β1 Xt1 + βj Xtj − Xtj−1 .
j=2
Because Xt1 and Xt2 −Xt1 , Xt3 −Xt2 , . . . are independent random variables, it
follows that the final equation results in a univariate normal random variable
(sums of independent normals are normal). Now, we just need to check the
expectation and covariance. It is easy to see that EXt = 0. In order to
calculate the covariance, assume that s < t. We have that,
Cov(Xs , Xt ) = EXs Xt − EXs EXt = EXs Xt ,
and
EXs Xt = EXs (Xt − Xs + Xs ) = EXs2 + EXs (Xt − Xs )
and, as the independent increments property implies EXs (Xt − Xs ) = 0,
Cov(Xs , Xt ) = EXs2 = s.
Repeating this with t ≥ s, we get Cov(Xs , Xt ) = min(s, t).
Part 2. We show that (ii) implies (i). It follows immediately from the
definition in (ii) that Xt ∼ N(0, t). It is also immediate that Xt+s − Xt
is univariate normal (as this is a linear combination of multivariate normal
random variables). We can thus show this increment is stationary by showing
that mean is constant and the variance only depends on s. Now, EXt+s −Xt =
0 and
Var(Xt+s − Xs ) = Var(Xt ) + Var(Xs ) − 2Cov(Xs , Xt ) = t + s − 2t = s.
3.2. BROWNIAN MOTION 111
Thus, the increments are stationary. Because the increments are multivariate
normal, we can show the increments of the process are independent if we can
show the covariance between increments is 0. So, take u < v ≤ s < t. Then,
Cov(Xv − Xu , Xt − Xs )
= Cov(Xv , Xt ) − Cov(Xv , Xs ) − Cov(Xu , Xt ) + Cov(Xu , Xs )
= min(v, t) − min(v, s) − min(u, t) + min(u, s)
= v − v − u + u = 0.
So, non-overlapping increments are independent.
3.2.1 Existence
Because it is a nice proof, we will show that Brownian motion exists. We
will do this constructively. Along the way, you might get some ideas about
certain ways you might simulate Brownian motion. Before we get to the
result itself, we need a couple of results. The first is a result that is often
useful.
Theorem 3.2.3. Let Z ∼ N(0, 1). Then, as x → ∞,
2
1 e−x /2
P(Z > x) ∼ √ ,
x 2π
and 2 2
x ex /2 1 e−x /2
√ < P(Z > x) < √ .
1 + x2 2π x 2π
The next result is a little more technical and uninteresting (but cleans up
the coming proof).
Lemma 3.2.4. Suppose we have two random variables Xs and Xt , with
t > s, defined on the same probability space such that Xt − Xs ∼ N(0, t − s).
Then, there exists a random variable X(t+s)/2 defined on the same space such
that
D
X(t+s)/2 − Xs = Xt − X(t+s)/2 ,
with X(t+s)/2 − Xs and Xt − X(t+s)/2 independent and identically distributed
with N(0, (t − s)/2) distributions. Also,
Xt + Xs 1
X(t+s)/2 − = |V |,
2 2
where V ∼ N(0, t − s).
112 CHAPTER 3. GAUSSIAN PROCESSES ETC.
Remember that the difficult thing to show for Brownian motion is that it
is almost surely continuous. To show this, we are going to consider the space
C[0, 1], which is the space of continuous functions on [0, 1] with the norm
kf k = max0≤t≤1 |f (t)|. Because we want to say something about convergence,
we need to recall a couple of definitions.
Definition 3.2.5 (Cauchy Sequence). We say a sequence (xn ) is a normed
space is a Cauchy sequence if kxn − xm k → 0 as n, m → ∞. That is, for all
ǫ > 0, there is an integer N (ǫ) such that kxn − xm k < ǫ for all m, n > N (ǫ).
3.2. BROWNIAN MOTION 113
{Vk/2n : k = 1, 2, . . . , 2n , n ≥ 1},
{Xk/2n , 0 ≤ k ≤ 2n , n ≥ 1},
such that
X 2k+1
n+1
− X kn and X k+1
n
− X 2k+1
n+1
2 2 2 2
n+1
are independent and both have N(0, 1/2 ) distributions. Now, for each
(n)
n ≥ 1, define {Wt }t∈[0,1] by
(
(n) Xt (ω) for t ∈ { 2kn , 0 ≤ k ≤ 2n }
Wt (ω) = k k+1 ,
linear in each interval 2n , 2n / { 2kn , 0 ≤ k ≤ 2n }
for t ∈
Now,
(n) (n)
(n+1) (n)
Wk/2 + W(k+1)/2 (n+1)
max |Wt (ω) − Wt (ω)| = − W 2k+1
k
2n
≤t≤ k+1
2n
2 2n+1
Xk/2 + X(k+1)/2
= − X 2k+1
2 2n+1
1
△(n) (ω) = max V 2k+1 .
2 0≤k≤2n+1 2n+1
(n) (m)
sup Wt − Wt ≤ △(n) + · · · + △(m−1) → 0
0≤t≤1
Of course, it remains to check that the resulting process has the desired
properties. We will leave this as an exercise for the reader. If you are
interested, take a look at [4].
Theorem 3.2.10 (Donsker’s Theorem). Let {Xi }i≥0 be i.i.d. random vari-
ables with EX1 = 0 and EX12 = 1. Define the partials sums of these random
variables by
Sn = X1 + · · · Xn .
Let
S[nt]
Zn (t) = √ , 0 ≤ t ≤ 1.
n
D
Then, Zn ⇒ W , where W is a Brownian motion on [0, 1].
0 = t0 ≤ t1 ≤ · · · ≤ tk−1 ≤ tk = t.
dXt = µt dt + σt dWt .
Note that {µt }Tt=0 and {σt }Tt=0 can be functionals of the whole path up
until time t (i.e., {Xs }ts=0 ). However, we will usually consider processes of
the form µt = a(Xt , t) and σt = b(Xt , t).
Lemma 3.3.3 (Itô’s Lemma). Let {Xt }Tt=0 be an Itô process given by dXt =
µt dt + σt dWt and let g(t, x) ∈ C 2 ([0, ∞) × R). Then, {Yt }Tt=0 defined by
Yt = g(t, Xt ) is again an Itô process and
∂g ∂g 1 ∂ 2g
dYt = (t, Xt ) dt + (t, Xt ) dXt + (t, Xt )(dXt )2 ,
∂t ∂x 2 ∂x2
where (dXt )2 is computed according to the rules dt dt = 0, dt dWt = dWt dt =
0 and dWt dWt = dt.
schemes are not random, in the sense that, given a realization of a Brow-
nian motion and a set of parameters, there is no randomness involved. We
will consider the two most widely used schemes, the Euler method and the
Milstein method.
bt0 = X0 and
by X
√
bt = X
X bt + a(X
bt , tj ) h + b(X
bt , tj ) hZj ,
j+1 j j j
k−1
where the {Zj }j=0 are i.i.d. N(0, 1).
Example 3.3.4. Consider the SDE for geometric Brownian motion. This is
given by
dXt = µXt dt + σXt dWt .
We can simulate this using the Euler scheme as follows.
Listing 3.11: Matlab code
1 m = 10^3; h = 1/m;
2 mu = 0.1; sigma = 0.2; X_0 = 1;
3 X = zeros(1,m+1);
4 X(1) = X_0;
5 for i = 2:m+1
6 X(i) = X(i-1) + mu*X(i-1)*h + sigma*X(i-1)*sqrt(h)*randn;
7 end
8 plot(0:h:1,X)
120 CHAPTER 3. GAUSSIAN PROCESSES ETC.
Milstein’s Method
The idea of Milstein’s method is to improve on the approximation
Z t+h Z t+h
b(Xu , u) dWu ≈ b(Xt , t) dWu .
t t
To do this, we use Itô’s lemma to get an expression for b(Xt , t) that allows
us to get a better approximation. The SDE we wish to solve is
1
db(Xt , t) = bt (Xt , t) dt + bx (Xt , t) dXt + bxx (Xt , t)(dXt )2
2
= bt (Xt , t) dt + bx (Xt , t) [a(Xt , t) dt + b(Xt , t) dWt ]
1
+ bxx (Xt , t) b(Xt , t)2 dt.
2
Writing this in integral form with s > t, we have
Z s Z s
b(Xs , s) =b(Xt , t) + bt (Xu , u)du + bx (Xu , u) a(Xu , u) du
t t
Z s Z
1 s
+ bx (Xu , u) b(Xu , u) dWu + bxx (Xu , u) b(Xu , u)2 du.
t 2 t
Thus,
Z t+h Z t+h Z s Z s
b(Xs , s) dWs = b(Xt , t) + bt (Xu , u) du + bx (Xu , u) a(Xu , u) du
t t t t
Z s Z
1 s 2
+ bx (Xu , u) b(Xu , u) dWu + bxx (Xu , u) b(Xu , u) du dWs
t 2 t
bt0 = X0 and
by X
√
bt = X
X bt + a(X
bt , tj ) h + b(X
bt , tj ) hZj + bx (X bt , tj ) h (Zj2 − 1),
bt , tj )b(X
j+1 j j j j j
2
k−1
where the {Zj }j=0 are i.i.d. N(0, 1).
Example 3.3.5. Consider again the SDE for geometric Brownian motion.
That is,
dXt = µXt dt + σXt dWt .
In order to simulate this using the Milstein scheme, we need to find bx (x, t).
Now, b(x, t) = σx, so bx (x, t) = σ.
dXt = Yt dt
dYt = Xt (α − Xt2 ) − Yt dt + σXt dWt .
4 X = zeros(T*m+1,1); Y = zeros(T*m+1,1);
5
8 for k = 1:T*m
9 X(k+1) = X(k) + Y(k) * h;
10 Y(k+1) = Y(k) + (X(k) * (alpha - X(k)^2) - Y(k))*h...
11 + sigma*X(k)*sqrt(h)*randn;
12 end
13
14 figure(1),plot(h:100*h:T,X(1:100:T*m))
15 figure(2),plot(h:100*h:T,Y(1:100:T*m))
16 figure(3),plot(X,Y)
1.5
0.5
Yt
−0.5
−1
−1.5
−2
−2.5 −2 −1.5 −1 −0.5 0 0.5 1 1.5 2
Xt
Figure 3.3.1: Plot of {Xt }t≥0 against {Yt }t≥0 for the simplified Duffing-Van
der Pol oscillator.
3.4. EXISTENCE AND UNIQUENESS RESULT 123
2 2
1.5
1
1
0 0.5
Xt
Yt
0
−1
−0.5
−2
−1
−3 −1.5
0 100 200 300 400 500 600 700 800 900 1000
0 200 400 600 800 1000
t t
Figure 3.3.2: Plots of {Xt }t≥0 and {Yt }t≥0 for the simplified Duffing-Van der
Pol oscillator.
(ii) |a(x, t) − a(y, t)| + |B(x, t) − B(y, t)| ≤ D|x − y| for all x, y ∈ Rm and
t ∈ [0, T ] where D is a constant.
has a unique t-continuous solution {Xt (ω)}t∈[0,T ] that is adapted to the fil-
tration FtZ generated by Z and {Ws }s≤t and
Z T
E |Xt |2 dt < ∞.
0
124 CHAPTER 3. GAUSSIAN PROCESSES ETC.
b T,h ) ≤ C hβ ,
Eg(XT ) − Eg(X ∀h ∈ (0, h0 ).
b T,h ≤ C hγ ,
E XT − X ∀h ∈ (0, h0 ).
Under some technical conditions (see, e.g., ...) the Euler scheme has weak
order convergence rate β = 1 and strong order convergence rate γ = 0.5.
Under some different technical conditions (see, e.g., ...) the Milstein scheme
3.6. ERROR ANALYSIS FOR NUMERICAL SOLUTIONS OF SDES 125
has weak order convergence rate β = 1 and strong order convergence rate
γ = 1.
In general, in Monte Carlo we are interested in estimating expectations.
This means that weak order convergence is usually the relevant convergence
concept. It is important to bear this in mind. Although the Milstein scheme
appears better, it involves calculating derivatives (sometimes these can be
done by hand in advance, but sometimes they need to be done numerically).
This imposes an additional cost which may not be worth it if strong order
convergence is not important.
Example 3.6.3. Consider the SDE for geometric Brownian motion
dXt = µ Xt dt + σ Xt dWt .
4 Z = randn(m_max,1);
5
6 for l = 1:L
7 m = 2^l; h = 1/m;
8 Z_coarse = zeros(m,1);
9 X_eul = zeros(1,m+1); X_eul(1) = X_0;
10 X_mil = zeros(1,m+1); X_mil(1) = X_0;
11 X = zeros(1,m+1); X = X_0;
12
13 for k = 1:m
14 Z_coarse(k) = 1/sqrt(2^(L-l))...
15 *sum(Z((k-1)*2^(L - l)+1:k*2^(L - l)));
16 end
17 W_coarse = sqrt(h) * cumsum(Z_coarse);
18 for i = 2:m+1
126 CHAPTER 3. GAUSSIAN PROCESSES ETC.
1.8
Exact
Euler Approximation
1.7 Milstein Approximation
1.6
1.5
1.4
1.3
1.2
1.1
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Figure 3.6.1: Plots of the exact solution, Euler approximation and Mil-
stein approximation of geometric Brownian motion for a fixed realization
of {Wt }t∈[0,1] with mesh size h = 1/2
1.8
Exact
Euler Approximation
1.7 Milstein Approximation
1.6
1.5
1.4
1.3
1.2
1.1
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Figure 3.6.2: Plots of the exact solution, Euler approximation and Mil-
stein approximation of geometric Brownian motion for a fixed realization
of {Wt }t∈[0,1] with mesh size h = 1/4
1.8
Exact
Euler Approximation
1.7 Milstein Approximation
1.6
1.5
1.4
1.3
1.2
1.1
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Figure 3.6.3: Plots of the exact solution, Euler approximation and Mil-
stein approximation of geometric Brownian motion for a fixed realization
of {Wt }t∈[0,1] with mesh size h = 1/8
128 CHAPTER 3. GAUSSIAN PROCESSES ETC.
1.8
Exact
Euler Approximation
Milstein Approximation
1.6
1.4
1.2
Figure 3.6.4: Plots of the exact solution, Euler approximation and Mil-
stein approximation of geometric Brownian motion for a fixed realization
of {Wt }t∈[0,1] with mesh size h = 1/16
Carlo estimator
1 X (i)
N
b
ℓ= f XT,h ,
N i=1
(1) (N )
where XT,h , . . . , XT,h are iid copies of the numerical solution of with mesh
size h. In general, this estimator is biased. This is because both the Euler
and Milstein schemes are biased. This means that we should measure its
error using MSE. Remember that the MSE of an estimator is of the form
b = Var(ℓ)
MSE(ℓ) b + Bias(ℓ)
b 2.
The two parts of the MSE correspond to different types of error: statistical
error and approximation error. The statistical error, measured by the vari-
ance, comes from the fact that there are an uncountably infinite number of
paths of Brownian motion and we are only sampling a small number. The
approximation error, measured by the bias, comes from the fact that given
a realization of a Brownian path, we still only get an approximate solution
to our SDE.
If we think a little harder, we can write the MSE as
2
b = Var(X
MSE(ℓ) b T,h )
b T,h ) + Ef (XT ) − Ef (X .
3.7. MULTILEVEL MONTE CARLO 129
Note that the rate at which the second term on the right goes to zero is
measured by the order of weak convergence. When the order of weak conver-
gence is 1 and for large enough N and small enough h we can approximate
the MSE by
b ≈ C1 + C2 h2 ,
MSE(ℓ)
N
where C1 , C2 > 0 are constants.
Remember that we defined the work done by an estimator as
In our case, assuming work increases linearly in sample size and inversely in
step size, we can write
b ∝ N/h.
work(ℓ)
1 X
N0
b
EP0 ≈ Y0 = f Xb (i)
T,h(0)
N0 i=1
and, for l = 1, . . . , L,
Nl h i
b b 1 X b (i) b (i)
E(Pl − Pl−1 ) ≈ Yl = f X T,h(l) − f X T,h(l−1) ,
Nl i=1
We can write work done by this estimator in terms of the various sample
sizes and step sizes as
XL
Nl
work(Y (L)) ∝ .
l=0
h l
3.7. MULTILEVEL MONTE CARLO 131
XL XL
Vl O(hl )
Var(Y (L)) = = −2
= O(ǫ−2 ).
l=0
Nl l=1
O(ǫ Lhl )
If we then choose
log ǫ−1
L= + O(1)
log M
as ǫ → 0, then hL = O(ǫ). This implies that we have MSE = O(ǫ2 ) with
L
X L
X
Nl O(ǫ−2 Lhl )
work ∝ = = O(ǫ−2 L2 ) = O(ǫ−2 (log ǫ)2 ),
l=0
hl l=0
hl
for a given Brownian path {Wt }t≥0 and let Pbl denote the corresponding ap-
proximation using a numerical discretization with timestep h(l) = M −l T . If
there exist independent estimators Ybl based on Nl Monte Carlo samples and
positive constants α ≥ 1/2, β, c1 , c2 , c3 such that
Cl ≤ c3 Nl h−1
l ,
3.7. MULTILEVEL MONTE CARLO 133
then there exists a positive constant c4 such that for any ǫ > e−1 , there are
values L and Nl for which the multilevel estimator
L
X
Yb = Ybl
l=0
3.7.5 Implementation
6 for l = 1:L
7 N(l) = 10^(L+1-l);
8 end
9
10 m = 1; h = 1;
11 vals = zeros(N_0,1);
12
13 for i = 1:N_0
14 X = X_0;
15 for k = 1:m
16 X = X + mu*X*h + sigma*X*sqrt(h)*randn;
17 end
18 vals(i) = X;
19 end
20
21 Y_0 = mean(vals);
22
134 CHAPTER 3. GAUSSIAN PROCESSES ETC.
23 for l = 1:L
24 m_old = 2^(l-1); h_old = 1/m_old;
25 m_new = 2^l; h_new = 1/m_new;
26 vals = zeros(N(l),1);
27
28 for i = 1:N(l)
29 X_old = X_0; X_new = X_0;
30 for k = 1:m_old
31 Z_1 = sqrt(h_new)*randn; Z_2 = sqrt(h_new)*randn;
32 Z = Z_1 + Z_2;
33 X_old = X_old + mu*X_old*h_old + sigma*X_old*Z;
34 X_new = X_new + mu*X_new*h_new + sigma*X_new*Z_1;
35 X_new = X_new + mu*X_new*h_new + sigma*X_new*Z_2;
36 end
37 vals(i) = X_new - X_old;
38 end
39
40 Y(l) = mean(vals);
41 end
42
43 Y_0 + sum(Y)
Chapter 4
Spatial Processes
135
136 CHAPTER 4. SPATIAL PROCESSES
random vector. We can use the mean function and covariance function to
construct the mean vector, µ, and covariance matrix, Σ, of these points.
Using these functions, and treating a finite number of points of the ran-
dom field as a vector, we can generate a realization of the field
Example 4.1.3 (Gaussian White Noise). A trivial example of a Gaussian
random field is Gaussian white noise. On I = {1, . . . , m} × {1, . . . , m}, this
is the process, {Xi }i∈I with mean function
µ(i) = EXi = 0,
10
20
30
40
50
60
70
80
90
100
10 20 30 40 50 60 70 80 90 100
1.5
0.5
−0.5
1 1
0.8 0.8
0.6 0.6
0.4 0.4
0.2 0.2
0 0
3 n1 = length(x); n2 = length(y);
4
5 Sigma = zeros(n1*n2,n1*n2);
6
7 for i = 1:n2
8 for j = 1:n1
9 row_state = (i-1)*n2 + j;
10 for k = 1:n2
11 for l = 1:n1
12 column_state = (k-1)*n2 + l;
13 Sigma(row_state,column_state) = ...
138 CHAPTER 4. SPATIAL PROCESSES
14 min(x(j),x(l))*min(y(i),y(k));
15 end
16 end
17 end
18 end
19
20 A = chol(Sigma);
21 Y = randn(1,n1*n2) * A;
22
23 X = zeros(n1,n2);
24
25 for i = 1:n2
26 for j = 1:n1
27 X(i,j) = Y((i-1)*n2 + j);
28 end
29 end
30
31 surf(x,y,X)
Random fields are, in general, difficult to work with. For that reason, it
is nice to identify classes of random fields that are more tractable.
Definition 4.1.5 (Stationarity). We say a random field, {Xi }i∈I , is station-
ary if (Xi1 , . . . , Xin ) has the same distribtion as (Xi1 +s , . . . , Xin +s ) for all
n ≥ 1, (i1 , . . . , in ) ∈ I n and s ∈ I.
Weak stationary implies that the first two moments of the distributions
do not change.
Definition 4.1.6 (Wide sense (weak) stationarity). A random field, {Xi }i∈I
is wide-sense stationary if µ(i) = c for all i ∈ I and r(i, j) = r(|i − j|). That
is, the covariance function is simply a function of the displacement vector
between the points i and j.
Analogously to the case of Gaussian processes, Gaussian fields are station-
ary if they are weak stationary. When considering random fields, a different
type of invariance property is also useful. This is called isotropy. Basically,
this means the distribution of the object does not change when the object is
rotated. We will only consider a very special case of isotropy.
Definition 4.1.7 (Stationary wide sense isotropy). A stationary random
field is wide sense isotropic if r(i, j) = r(ki − jk). That is, the covariance
between points i and j only depends on the distance between them.
Note that non-stationary random fields can be isotropic.
4.1. RANDOM FIELDS 139
Example 4.1.13.
PICTURE HERE
This example encodes the dependency structure
PICTURE HERE
In Markov random fields, random variables are conditionally independent
of the rest of the graph given their immediate neighbors.
Ni = {j ∈ V : (i, j) ∈ E}.
10
−5
60
50
40 40
30
20 20
10
0 0
We will assume that the GRMFs we consider have densities. That is,
the covariance matrix of a finite number of points, Σ, will always be positive
definite. Recall that the pdf of a normal vector X is given by
−n/2 −1/2 1 ⊺ −1
f (x; µ, Σ) = (2π) |Σ| exp − (x − µ) Σ (x − µ) .
2
Q = Σ−1 .
We can rewrite the pdf of a normal vector in terms of its precision matrix
as
−n/2 1/2 1
f (x; µ, Q) = (2π) |Q| exp − (x − µ) Q(x − µ) .
⊺
2
The following result reveals the reason why precision matrices are so
appealing when working with GRMFs.
142 CHAPTER 4. SPATIAL PROCESSES
If you consider examples 4.1.12 and 4.1.13, then it is clear that this pdf can
only be factorized in the necessary way if Qi,j = Qj,i = 0.
Xi ⊥X−{i}∪Ni | XNi ∀i ∈ V.
XA ⊥XB | XC
and
Var µ + (C ⊺ )−1 Z = (C ⊺ )−1 Var(Z) (C)−1 = (CC ⊺ )−1 = Q−1 = Σ.
13 b(k+h)= ij2k(A(h,1),A(h,2),m);
14 if h==1
15 q(k+h) = d1;
16 else
17 q(k+h) = d2;
18 end
19 end
20 k = k+number_neighbours;
21 end
22 end
23 %construct the precision matrix
24 Q = sparse(a,b,q,m^2,m^2);
25 %calculate the Cholesky matrix
26 C = chol(Q,’lower’);
27 Z = randn(m^2,1);
28 % generate the Gaussian process
29 x = C\Z;
30 colormap gray, brighten(-0.2)
31 imagesc(reshape(x,m,m)) % plot the result
22 elseif j==m
23 A = [i,m;i,m-1;i+1,m;i-1,m];
24 else
25 A = [i,j;i,j-1;i,j+1;i+1,j;i-1,j];
26 end
27 end
28 end
50
100
150
200
20 40 60 80 100 120 140 160 180 200
3 X = zeros(n,2);
4
8 S = 200 * ones(n,1);
9 scatter(X(:,1),X(:,2),S,’fill’)
3 X = zeros(n,3);
4
9 S = 200 * ones(n,1);
10 scatter3(X(:,1),X(:,2),X(:,3),S,’fill’)
10
0
0 2 4 6 8 10
Figure 4.2.1: A realization of a binomial process on [0, 10] × [0, 10] with
n = 20 points.
148 CHAPTER 4. SPATIAL PROCESSES
10
0
10 10
8
5 6
4
2
0 0
Figure 4.2.2: A realization of a binomial process on [0, 10] × [0, 10] × [0, 10]
with n = 20 points.
for pairwise disjoint B1 , B2 , . . . ∈ B(Rd ), and ϕ(B) < ∞ for all bounded
B ∈ B(Rd ).
Let N be the smallest σ-algebra on N such that ϕ → ϕ(B) is (N , B(Rd ))-
measurable for all bounded B ∈ B(Rd ).
Definition 4.2.3 (Random Counting Measure). A random counting measure
N : Ω → N is a measurable mapping of the probability space (Ω, F, P) into
(N, N ). Intuitively, it is a random element of N.
Poisson Process
Definition 4.2.4 (Poisson Random Measure). Let B0 (Rd ) be the collection
of bounded Borel sets in Rd and µ : B(Rd ) → [0, ∞] a locally finite measure
4.2. SPATIAL POISSON PROCESSES 149
(i.e., µ(B) < ∞ for all B ∈ B0 (Rd )). We say {NB }B∈B(Rd ) is a Poisson
random measure with intensity measure µ if
(i) NB1 , NB2 , . . . are independent random variables for pairwise disjoint
B1 , B2 . . . ∈ B0 (Rd ).
If µ is proportion to νd (i.e., µ(B) = λνd (B) for all B ∈ B(Rd )), then
{NB }B∈B(Rd ) is said to be a homogenous Poisson counting measure with in-
tensity λ.
P(N (B) = k, N (W ) = n)
P(N (B) = k | N (W ) = n) =
P(N (W ) = n)
P(N (B) = k, N (W \ B) = n − k)
=
P(N (W ) = n)
P(N (B) = k)P(N (W \ B) = n − k)
=
P(N (W ) = n)
k n−k
\B))
e−λνd (B) (λνdk!(B)) e−λνd (W \B) (λνd (W
(n−k)!
= n
e−λνd (W ) (λνd n!
(W ))
k n−k
n νd (B) νd (B)
= 1− .
k νd (B) νd (B)
13 S = 200 * ones(N,1);
14 scatter(X(:,1),X(:,2),S,’fill’)
0.5
−0.5
−1
−1 −0.5 0 0.5 1
and work with than homogeneous Poisson processes. We will restrict our
attention to processes with measures that are absolutely continuous with
respect to d-dimensional Lebesgue measure. For such processes, there exists
a Borel measurable function λ : Rd → [0, ∞) such that
Z
µ(B) = λ(x) dx
B
for all B ∈ B(Rd ). This function is called the intensity function of the process
{NB }B∈B(Rd ) .
Theorem 4.2.7. Let λ1 , λ2 : Rd → [0, ∞) be two Borel measurable and
locally integrable functions such that
5 for i = 1:N_star
6 x = 5 * rand; y = 5 * rand;
7 if rand < (20*(sin(x)^2 + cos(y)^2) / lambda_star)
8 X = [X; x y];
9 end
10 end
11
12 x = 0 : .1 : 5; y = 0 : .1 : 5;
13 n = length(x); Z = zeros(n,n);
14
152 CHAPTER 4. SPATIAL PROCESSES
15 for i = 1:n
16 for j = 1:n
17 Z(j,i) = 20*(sin(x(i))^2 + cos(y(j))^2);
18 end
19 end
20
21 surf(x,y,Z);
22 hold on
23 colormap hot
24 S = 100 * ones(length(X),1);
25 scatter(X(:,1),X(:,2),S,’fill’)
Cox Process
A Cox process is a natural extension of a Poisson process where the
deterministic instensity measure is replaced by a random measure.
Definition 4.2.9 (Cox Process). Let {ΛB }B∈B(Rd ) be a random measure that
is locally finite with probability 1. The family of random counting measures
{NB }B∈B(Rd ) is called a Cox process with random intensity Λ if
n
! " n #
\ Y ΛkBi
P {NBi = ki } = E i
exp{−ΛBi } .
i=1 i=1
ki !
5 for i = 1:n2
6 for j = 1:n1
7 row_state = (i-1)*n2 + j;
8 for k = 1:n2
9 for l = 1:n1
10 column_state = (k-1)*n2 + l;
11 Sigma(row_state,column_state) = ...
12 min(x(j),x(l))*min(y(i),y(k));
13 end
14 end
4.2. SPATIAL POISSON PROCESSES 153
0
0 1 2 3 4 5
40
30
20
10
0
6
4 5
4
3
2 2
1
0 0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
1000
800
600
400
200
0
0
0.5
15 end
16 end
17
18 A = chol(Sigma); Y = randn(1,n1*n2) * A;
19 Lambda = reshape(300*Y.^2,n1,n2);
20 lambda_star = max(max(Lambda));
21 N = poissrnd(lambda_star)
22 X = [];
23
24 for i = 1:N
25 x_temp = rand;
26 y_temp = rand;
27 ix = ceil(100 * x_temp);
28 iy = ceil(100 * y_temp);
29
35 contour(x,y,Lambda)
36 hold on
37 S = 100 * ones(length(X),1);
38 scatter(X(:,1),X(:,2),S,’fill’)
39 colormap hot
156 CHAPTER 4. SPATIAL PROCESSES
Bibliography
157