1. Assume Y is a random sample from a standard normal distribution and U is a sample from a
standard uniform distribution on .0; 1/. What is the probability density function of the random
variable X D Y =U ?
Solution:
F .x/ D P .X x/ D P .Y =U x/ D P .Y xU /
U
Y=xU
Y
Z 1 Z xu
1
2
p e y =2 dy du
2
0
1
Z 0
Z 1
Z x
Z 1
1
1
y 2 =2
y 2 =2
D
dy
du C
dy
du
p e
p e
2
2
1
0
0
y=x
Z x
Z x
1
1
1
2
y 2 =2
D C
dy
ye y =2 dy
p e
p
2
2
x 2 0
0
Z x
ix
1 h
1
1
2
2
e y =2
D C
p
p e y =2 dy
0
2
2
x 2
0
Z x
1
1 1
y 2 =2
x 2 =2
D C
dy
1 e
:
p
p e
2
2
x 2
0
F .x/ D
Differentiating, we get
1
1
2
f .x/ D p e x =2 C p
1
2
x 2 2
1 1 x 2 =2
Dp
1
e
:
2 x 2
2
e x =2
1
2
p e x =2
2
2. Let Xk be independent, identically distributed exponential random variables with parameter
. Define
N
X
SN ´
Xk :
kD1
1. Show that the probability distribution function of SN is
fSN .x/ D
N x N 1 x
e
.N 1/Š
for x > 0 :
2. Let M be the integer satisfying SM C1 > 1 and SM 1. Show that this random variable
has a Poisson distribution.
1
Answer
1. Remembering that the distribution of a sum of random variables is the convolution of
their individual pdfs, with fS1 .x/ D e x ,
Z x
Z x
2
fS2 .x/ D
fS1 .t/fS1 .x t/ dt D e t e .x t / dt D 2 xe x :
0
0
Now let’s do induction. Assume it’s true for N D k. Then
Z x
Z x
kC1 x k x
k
k 1
t
.x t /
t
e e
dt D
e
;
FSkC1 D
fSk .t/fS1 .x t / dt D
.k 1/Š 0
kŠ
0
so it’s true for N D kC1.
2. OK, now we want to define M to be the integer satisfying SM C1 > 1 and SM 1 or, in
other words, for M to be equal to k, that means SkC1 > 1 and Sk 1. If SkC1 > 1 then
there are two alternatives: either Sk > 1 or Sk 1 and, of course,
P .SkC1 > 1/ D P .SkC1 > 1 & Sk > 1/ C P .SkC1 > 1 & Sk 1/
D P .Sk > 1/ C P .SkC1 > 1 & Pk 1/ ;
where we simplified the first term on the right since Sk > 1 automatically means that
SkC1 > 1. Therefore
P .SkC1 > 1 & Sk 1/ D P .SkC1 > 1/ P .Sk > 1/
Z 1 k k 1
Z 1 kC1 k
x
x
x
e
dx
e x dx :
D
kŠ
.k
1/Š
1
1
If we now integrate by parts the first integral, the resulting integral cancels the second
one on the right above, leaving only the contribution from x D 1,
P .M Dk/ D
k e ;
kŠ
i.e., the Poisson distribution.
Another way to get the same result is to realize that Sk 1 and SkC1 > 1 means that
Sk 1 and XkC1 > 1 Sk . It’s clear that XkC1 and Sk are independent random variables
and so their joint pdf is merely the product of their two individual pdfs,
k skk 1 sk
p.sk ; xkC1 / D p.sk / p.xkC1 / D
e
e xkC1 :
.k 1/Š
To get the required probability we merely integrate over the desired region, Sk 1 and
2
XkC1 > 1
Sk , i.e.,
k skk 1 sk
e
e xkC1 dxkC1 dsk
.k
1/Š
1 sk
Z 1Z 1
P .M Dk/ D
0
iˇxkC1 D1
k skk 1 sk h
ˇ
e
e xkC1 ˇ
dsk
xkC1 D1 sk
.k
1/Š
0
Z 1 k k 1
Z
sk
k e 1 k 1
sk
Csk
D
e
e
dsk D
s dsk
.k 1/Š 0 k
0 .k 1/Š
Z 1
D
D
k e :
kŠ
3. Find the transformation that converts standard U.0; 1/ random samples to samples from the
hyperbolic secant distribution
f .x/ D
1
1 1
2
1
sech x D
D
:
x
cosh x
e Ce x
Answer: We need
Z x
Z x
Z x
Z x
2
1
2 et
2 e
du
F .x/ D
f .t/ dt D
dt D
dt D
t
t
2t
2
C1
0 u C1
1
1 e Ce
1 e
D
2
tan 1 .e x / :
Therefore
F .X/ D
2
tan 1 .e X / D U
)
X D ln .tan U=2/ :
4. Suppose we want to generate samples from the standard normal
1
2
f .x/ D .x/ D p e x =2 ;
2
1 < x < 1:
by using samples from a Laplace distribution with mean 0 and scale b > 0:
g.xI b/ D
1
e jxj=b :
2b
Find the scale b that maximizes rejections, and give the corresponding acceptance rate.
Answer: We need the ratio
p
2
2
f .x/
e x =2 = 2
2b
x
jxj
D
Dp
exp
C
:
g.x/
e jxj=b =.2b/
2
b
2
3
This ratio is even in x, so it suffices to maximize over x 0. The exponent for x > 0 is
x
1
x2
1 2
1
C
)
x
C 2:
2
b
2
b
2b
so the maximum occurs at x D 1=b. Therefore,
2b
f .x/
1
p
:
exp
g.x/
2b 2
2
for all x. We therefore want to choose b to maximize
2b
1
1
log p
exp
D log b C 2 C constant:
2
2b
2b
2
Differentiating
1
b
1
D0
b3
At this value of b
f .x/
g.x/
)
r
b D 1:
2 1=2
e ;
which is the overall acceptance ratio.
5. Suppose you are asked to estimate
Z 1
2
e kx e x =2 dx
1
by drawing samples from the N(0,1) distribution but you want to use importance sampling
instead. What is the optimal importance sampling density p .x/ and how “optimal” is it?
Answer: The goal is to minimize
Z 1
p.X/
p.x/
D
Varp g.X/ g.x/ p .X/
p .x/
1
2
I
p .x/ dx :
The minimum is
p .x/ D
g.x/p.x/
2
2
2
/ e kx e x =2 D e .x k/ =2Ck =2 :
I
Normalizing this to a probability distribution, we must have
1
2
p .x/ D p e .x k/ =2 :
2
Using this biasing distribution the integral becomes
p
2
2e k =2
which is the exact answer. The result is perfectly optimal.
4
6. Suppose X has a negative binomial probability distribution
!
kCr 1
.kCr 1/Š
.k/ D Pr.X D k/ D
.1 p/r p k D
.1
kŠ.r 1/Š
k
p/r p k ;
k D 0; 1; 2; : : : ;
where p and r are parameters. The goal is to simulate this distribution by using Markov-chain
Monte-Carlo with a proposal transition distribution q.kC1jk/ D q.k 1jk/ D 1=2. What is
the Metroplis-Hastings acceptance probability for this method?
With a proposal distribution
1 j k/ D 21 ;
q.k C 1 j k/ D q.k
the Metropolis–Hastings acceptance probability is
.k 0 / q.k j k 0 /
0
˛.k; k / D min 1;
:
.k/ q.k 0 j k/
Because the proposal is symmetric,
0
0
q.k j k/ D q.k j k /
H)
q.k j k 0 /
D 1;
q.k 0 j k/
so the acceptance probability simplifies to
.k 0 /
:
˛.k; k / D min 1;
.k/
0
For the upward move, k ! k C 1, we get
kCr
.1 p/r p kC1
.k C 1/
kCr
kC1
D kCr 1
Dp
:
.k/
kC1
.1 p/r p k
k
Thus,
kCr
˛.k; k C 1/ D min 1; p
:
kC1
For the downward move, k ! k
1, we get for k > 0,
.k 1/
1
k
D .k/
p kCr
1
:
Thus,
˛.k; k
If k D 0, the proposal to k D
1/ D min 1;
k
p .k C r
1/
:
1 is invalid and is automatically rejected.
5
7. The Brusselator is a model of an autocatalytic reaction that produces a chemical oscillation. In
the simplest version, there are 2 chemicals, A and B, that are assumed to be so plentiful that
their concentrations remain constant, two chemicals X and Y that react with A and B, and two
products D and E that are the result of the reactions and which we don’t concern ourselves
with. The reactions are
kO1
A !X;
kO2
2X C Y ! 3X ;
kO3
B CX ! Y CD;
kO4
X !E:
(a) Describe how you would solve this problem numerically using a Gillespie algorithm.
Answer: Please see the course notes for this part.
(b) To make comparing different system sizes easier (i.e., different total number of X and Y
molecules), one can assume a characteristic total number of molecules N0 and work with
the fractions x D X=N0 and y D Y =N0 . In addition, the reaction rates need to be scaled
for system size by assuming
kO1 ŒA D k1 N0 ;
kO2 D k2 =N02 ;
kO3 ŒB D k3 ;
kO4 D k4 :
Note the first and third definitions absorb the concentrations of A and B (ŒA and ŒB)
into the rescaled reaction rates. Derive the deterministic set of ODEs for x.t/ and y.t/
that correspond to the system without fluctuations, i.e., what one gets if N0 ! 1.
Answer: The stoichiometric matrix and reaction velocity vector are
0
1
kO1 ŒA
B
C
"
#
B kO2 X 2 Y C
1
1
1
1
B
C
SD
;
vE D B
C:
B
C
O
0
1
1
0
k
ŒBX
@ 3
A
kO4 X
6
This gives the deterministic reaction equations
!
X
kO1 ŒA C kO2 X 2 Y kO3 ŒBX
d
D
dt
Y
kO2 X 2 Y C kO3 ŒBX
kO4 X
!
:
Now we rescale X D N0 x and Y D N0 y and replace the reaction constants as indicated,
and the above become
!
!
k1 C k2 x 2 y k3 x k4 x
x
d
D
:
dt y
k2 x 2 y C k 3 x
8. Consider the equation
d E D E d WE ;
(S)
(1)
with jE
.0/j D 1. Note that this represents an infinitesimal rotation, since (S) d E D E d WE
gives (S) E d E D 0 or (S) E E D const. D 1; note here we are using the Stratonovich form
so that we can do the vector calculus without worrying about Itô corrections.
(a) Suppose we forget momentarily that this equation is in Stratonovich form. Demonstrate
analytically that a naive Euler-Maruyama finite difference numerical solution of it, i.e.,
EnC1 D En C En WEn ;
doesn’t represent a random rotation since hjE
n j2 i grows with n.
Answer
i
i h
h
2
E
E
jE
nC1 j D EnC1 EnC1 D En C En Wn En C En Wn
D En En C En WEn En WEn
h
i
D jE
n j2 C En WEn En WEn
h
i
2
E
E
E
E
D jE
n j C En Wn Wn En
Wn En Wn
D jE
n j2 C 3tjE
n j2
tjE
n j2
D .1 C 2t/jE
n j2 ;
and clearly jE
n j2 grows with n.
(b) For the above (incorrect) Euler-Maruyama finite difference numerical solution determine
hjE
.z/j2 i as a function of z (in the limit t ! 0).
Answer: We have
jE
n j2 D .1 C 2t/n jE
0 j2 D .1 C 2t/t =t jE
0 j2 :
Taking the limit t ! 0, we have
jE
.t/j2 D jE
.0/j2 e 2t :
7
(c) Find the Itô version of Eq. (1) (i.e., determine and add the Itô correction). Show analytically from the Euler-Maruyama numerical solution of the (correct) Itô version of Eq. (1)
gives hjE
.z/j2 i D const. after taking the limit t ! 0.
Answer Version 1:
2
32
3
0
3 2
d W1
6
76
7
0
1 5 4 d W2 5 ;
E d WE D 4 3
2
1
0
d W3
so we can think of this as a matrix multiplying the vector d WE with
0
3
2
6
D ./ D 4 3
0
7
1 5 :
2
1
0
2
3
The Itô correction (without the dt) is
1 @ij
1 @ij
1 @ij
1 @ij
`j D
1j C
2j C
3j :
2 @`
2 @1
2 @2
2 @3
3
3
2
32
2
0 0 0
0
0
16
1 @ij
16
76
7
7
1 5 4 3 5 D
1j D 4 0 0
4 2 5 :
2 @1
2
2
2
3
0 1 0
Similarly,
2
0
0 1
32
3
3
2
3
1 @ij
16
76
7
2j D 4 0 0 0 5 4 0 5 D
2 @2
2
1 0 0
1
2
1
3
1
3
16
7
4 0 5
2
3
and
2
0
1 @ij
16
3j D 4 1
2 @3
2
0
1 0
32
0
76
0 54
7
1 5 D
0
0
0
2
16
7
4 2 5
2
0
Adding up these three contributions, the total is
2
1
3
6
7
4 2 5
3
and therefore the Itô version of the equation is
(I)
E dt C En d WEn :
d E D
8
Version 2: (using cartesian tensors can help with the calculations)
d i D i kj k d Wj D ij d Wj
(S)
with ij D i kj k . The Itô correction (converting from Stratonovich to Itô) is
C
1 @ij
1 i kj k
1
`j D
`mj m D ık` i kj `mj m :
2 @`
2 @`
2
But i kj `mj D ıi ` ıkm
ıi m ık` and so the above becomes
1
.ıi ` ıkm
2
ıi m ık` / ık` m D
1
.ıi m
2
3ıi m / m D
i :
Therefore, we get
(I)
E dt C En d WEn :
d E D
Regardless of how one gets here, the Euler-Maruyama solution is now
EnC1 D En En t C En WEn ;
and we have
h
jE
nC1 j2 D EnC1 EnC1 D .1
D .1
i h
i
t/E
n C En WEn .1 t/E
n C En WEn
t/2 En En C En WEn En WEn
h
i
2
2
E
E
t/ jE
n j C En Wn En Wn
i
h
WEn En WEn
t/2 jE
n j2 C En WEn WEn En
D .1
t/2 jE
n j2 C 3tjE
n j2
D .1
D .1
tjE
n j2
D .1 C t 2 /jE
n j2 :
Now we get
jE
n j2 D .1 C t 2 /n jE
0 j2 D .1 C t 2 /t =t jE
0 j2 :
Taking the limit t ! 0, we have
jE
.t/j2 D jE
.0/j2 :
9. Suppose you would like to simulate exactly the numerical solution of the stochastic differential
equation
dX D ˛X dt C d W
9
using time steps of size t. Is it possible to do this?
Answer: The solution is
X.t/ D X.0/e
˛t
Z t
C
e ˛.s t / d W .s/ :
0
and we know that the integral
Z t
e ˛.s t / d W .s/
0
is a mean zero Gaussian random variable with variance
Z t
1
1 2˛t
e 2˛.t s/ dt D e 2˛t
1 e 2˛t D
e
2˛
2˛
0
1 :
We can use this to produce an exact numerical simulation. If we take t D t as a step size,
and define X.nt/ D Xn , we can get the exact simulation method
XnC1 D Xn e ˛t C Zn ;
where Zn is a mean zero Gaussian random variable with variance
1 2˛t
e
2˛
10
1 :
Potentially useful formulas
Exponential distribution:
x
p.x/ D e
Normal distribution:
p.x/ D p
Z 1
I D Ep Œg.X/ D
1
;
x 0:
2
2 2
2
e .x / =.2 /
Z 1
p.x/ p.X/
g.x/ p .x/ dx D Ep g.X/ p .x/
p .X/
1
g.x/p.x/ dx D
1
2
Z 1
p.X/
p.x/
Varp g.X/ D
g.x/ I p .x/ dx
p .X/
p
.x/
1
Z 1
p.x/
D
g 2 .x/ p.x/ dx I 2 :
p
.x/
1
Z 1
n
x e
x 2 =2
.n 1/=2
Z 1
dx D 2
0
t .n 1/=2 e t dt D 2.n 1/=2
0
nC1 2
q.xj y/.y/
;1 :
˛.yj x/ D min
q.yj x/.x/
)
E t/ dt C ij .X;
E t/ d Wj and Yk D Uk .X;
E t/
dXi D bi .X;
@Uk
@Uk
1
@ 2 Uk
@Uk
d Yk D
C bm
C mj nj
dt C mj
d Wj
@t
@Xm
2
@Xm @Xn
@Xm
E dt C ij .X/
E d Wj
dXi D bi .X/
(I)
gives
(S)
E
dXi D bi .X/
1 @ij E
E dt C ij .X/
E d Wj :
.X/kj .X/
2 @Xk
11