JHU 580.429 SB3
HW12: Stochastic dynamics
1. Consider our standard model for the dynamics of a single mRNA species with copy number
n, with transitions
n → n+1
n → n−1
and corresponding rates β and αn. Use parameter values β = 1/min and α = 0.1/min.
(a) What is average lifetime of a transcript in minutes? For stochastic dynamics at equilibrium, what are the theoretical values for the mean and variance of n?
Consider a single transcript which can only degrade with rate α. The time until degradation is distributed exponentially with parameter α (ie T ∼ exp(α)). The exponential
distribution is given by:
αeαt t ≥ 0
f (t) =
0
t <0
The average lifetime of a transcript is the expected value of the time until a single
transcript degrades. Therefore:
Z ∞
tAV G = E [T ] =
Z ∞
t f (t)dt =
−∞
0
tαeαt =
1
α
Therefore the average lifetime of a transcript is:
1
= 10 mins
α
At equilibrium, assume that Pn is the probability that there are n copies of transcripts.
Then ∑+∞
i=1 Pi = 1. And
P0 β
= P1 α
P1 β
= P2 (2α)
...
Pn−1 β
= Pn (nα)
...
We can solve the probability Pn
Pn =
1
n!
n
β
β
e− α
α
So the copy number n have a Poisson distribution, and The mean of n is
hni =
Version: 2016/11/16 13:50:27
β
= 10
α
1 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
And the variance of n is
Var(n) =
β
= 10
α
(b) Using the variable X to denote a continuous approximation to the particle number n,
what is the ODE corresponding to the stochastic dynamics? What is the steady-state
value of X, defined as hXi?
The ODE function is
dX
= β − αX
dt
X
dX
= 1−
dt
10
At steady-state, dX/dt = 0, so the value of X would be
hXi =
β
= 10
α
(c) Write a Gillespie simulation for this system and provide your source code. A code
framework will be available as a starting point. Perform a stochastic simulation for the
dynamics of n using your simulation software. Have the program output the value of n
at regular intervals of 1 minute. This takes some care because the random transitions
will not necessarily occur at these fixed intervals. You do not have to provide the
trajectory, just the source code.
The code is attached to the end of this key
(d) Start the simulation at n equal to the integer closest to hXi. Calculate and report the
mean µ and variance σ 2 of n over 10,000 minutes. Compare these to the theoretical
values.
2. Now consider the approach to equilibrium. The dynamical systems are the same, but the
initial conditions are X = 0 (ODE) and n = 0 (stochastic).
(a) What is the solution for X(t)?
Based on the ODE function we got in question 1(b) and the initial condition X = 0, we
can solve the response X(t) as
β
1 − e−αt
α
= 10 (1 − e−t/10 )
X(t) =
Version: 2016/11/16 13:50:27
2 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
(b) Run 1000 simulations (trajectories) of the first T = 100 minutes for the stochastic
system. Calculate the mean hn(t)i and the variance Var[n(t)] at 1 minute intervals.
Note: The mean hn(t)i here depends on time; it is computed by averaging over the
1000 trajectories at each time point. Similarly, the variance hn(t)2 i − hn(t)i2 is evaluated at 1 minute intervals over the 1000 simulations, computed separately for each
time t. It is not the variance over the 100 minute trajectory. You should find that
hn(0)i = Var[n(0)] = 0, hn(T )i = µ, and Var[n(T )] = σ 2 , where µ and σ 2 are from
the previous equilibrium simulation. Plot the mean (solid line) and ± one standard deviation error bars (dashed line, standard deviation computed simply as the square root
of the variance) for the 1000 trajectories, together with the ODE results for X(t) (thick
line).
The code is attached to the end the file.
(c) Suggest or derive an analytical expression for the variance as a function of time.
Version: 2016/11/16 13:50:27
3 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
We are considering the stochastic system with rate β for n → n + 1 and rate αn for
n → n − 1. We want to calculate Var(t) for t > 0..
First think about the boundary times. For t ≤ 0, n(t) = 0, and Var(t) = 0 as well. Our
answer should therefore have Var(t) = 0 at t = 0.
When we have reached equilibrium, we know that Var(n) = hni = β /α. Our expression
for Var(t) should have the same value in this limit.
We take the approach we took before for equilibrium. We divide time into intervals of
size ∆t so that the probability of making a particle in that interval is small, β ∆t 1.
Let the interval i be the interval ending at i∆t and containing (i − 1)∆t < t ≤ i∆t. For
convenience, define ti = i∆t. Given that a particle was made during interval i, the
probability that it survives until time t is exp(t −ti ). We define random variable ai to be
1 if a particle was made during interval i and survives until time t, and 0 otherwise. This
is a Bernoulli distribution or a binary probability distribution or a binomial probability
distribution for a single Bernoulli trial with success probability β ∆t exp[−α(t − ti )],
ai ∼ Binary β ∆t exp[−α(t − ti )] .
The number of particles present at time t is a sum of these random variables,
t/∆t
n(t) =
∑ ai .
i=1
The random variables are independent, which means that
t/∆t
hn(t)i =
∑ hai i,
i=1
t/∆t
Var[n(t)] =
∑ Var(ai )
i=1
For a binary random variable x ∼ Binary(p),
hxi = p · 1 + (1 − p) · 0 = p;
hx2 i − hxin = hxi − hxi2 = p − p2 = p(1 − p).
This may be the only time in the course that we don’t use a characteristic function to
generate the mean and variance. The identity hx2 i = hxi is true for variables that can
only take on values of 0 and 1, which are idempotent: xk = x for any integer k ≥ 1.
Note that the variance is symmetric for p and 1 − p.
Version: 2016/11/16 13:50:27
4 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
Back to the mean,
t/∆t
hn(t)i =
∑ β ∆t exp[−α(t − ti )]
i=1
Z t
=
0
dt 0 β e−α(t−t )
0
= β e−αt
Z t
0
dt 0 eαt
0
0
= β e−αt (1/α)eαt |t0
= (β /α)e−αt (eαt − 1)
= (β /α)(1 − e−αt ).
Of course we knew this from the ODE solution, but it gives us confidence in our math.
For the variance we follow the same procedure.
t/∆t
Var[n(t)] =
∑ β ∆t exp[−α(t − ti )] − (β ∆t)2 exp[−2α(t − ti )]
i=1
Z t
=
0
0
0
dt β exp[−α(t − t )] − β ∆t
Z t
0
dt 0 β exp[−2α(t − ti )]
= (β /α)[1 − e−αt ] − β ∆t(β /2α)(1 − e−2αt ).
We then notice that we can take β ∆t → 0. The remainder of the second term is finite,
which means that the product goes to 0 and can be ignored. We end with
Var[n(t)] = hn(t)i = (β /α)(1 − e−αt ).
As a final check, note that we have the correct limits, with variance equal to 0 at time 0
and equal to β /α at long times.
(d) Suppose that the initial conditions are that the initial number of particles is n0 but that
there is decay only, with the transition n → n − 1 having rate αn. The ODE solution
is n(t) = n0 exp−αt . Suggest (or derive) an analytical solution for the variance V (t) for
the corresponding stochastic system in which n(t) is a random variable and the timedependent variance V (t) = hn(t)2 i − [n0 e−αt ]2 . Solve for the time t when the variance
V (t) has its maximum value.
Again we use the idea of independent random variables. Here let ai be a random variable that is 1 if particle i ∈ [1, 2, . . . , n] survives until time t and 0 otherwise. The
survival probability is e−αt . These random variables are independent and identically
distributed,
ai ∼ Binary(e−αt ).
Version: 2016/11/16 13:50:27
5 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
We use a to denote a single random variable following this distribution. The mean
hn(t)i is
n
hn(t)i = ∑ hai i = nhai = ne−αt ,
i=1
which we knew from the ODE.
The variance is
n
Var[n(t)] = ∑ Var(ai ) = nVar(a) = n[e−αt − e−2αt ],
i=1
where we have noted that a random variable ∼ Binary(p) has mean p and variance
p − p2 (see the previous question or the text).
To determine the time with maximum variance, we resort to calculus:
0 = (d/dt)Var[n(t)] = n[−αe−αt + (2α)e−2αt ]
2e−2αt = e−αt
e−αt = 1/2
t = (1/α) ln 2.
The maximum variance occurs at the time when the survival probability is 1/2. This
follows from the general result that a binary random variable has maximum variance
for success probability 1/2.
3. Finally, consider a model with bursts of transcription with burst size 5. The stochastic transitions are
n → n+5
n → n−1
with corresponding rates β /5 and α.
(a) What is the corresponding ODE model? Does the ODE model depend on the burst
size?
dX
β
= · 5 − αX
dt
5
For the ODE solution there is no dependence on the burst size.
(b) Start a stochastic simulation with n equal to the closest integer to the steady-state value
for the ODE model, and generate a 10,000 minute trajectory, recording the state (the
value of n) at 1-minute intervals. Calculate and report the mean µ and variance σ 2 .
Version: 2016/11/16 13:50:27
6 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
Approximately:
µ̂ = 10.17
ˆ
σ 2 = 30.44
(c) How do the mean and variance compare to the results for the stochastic system with
burst size of 1? Do larger bursts correspond to smaller, equal, or larger mean and
variance? Can you provide a conjecture for the mathematical expression relating mean
and variance for bursts of size b generated at rate β /b, together with the rates β and α?
Running the simulation for different values of b you can compute the table:
b
1
5
7
9
10
σ2
≈ 10
≈ 30
≈ 40
≈ 50
≈ 55
By constructing the above table you will notice a pattern: the variance seems to be
linearly related to b. You might postulate that the relationship will have the form:
σ 2 = s · b + v where s is the slope and v is the intercept. Now consider the case b =
1. In that case you know that the analytical solution is: σ 2 = αβ . Using these facts a
reasonable conjecture for the variance in terms of parameters is:
σ2 =
Version: 2016/11/16 13:50:27
b+1 β
2 α
7 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
Matlab Source Code
Prob1.m
f u n c t i o n Prob1 ( )
global a b
a = . 1 ; % alpha
b = 1; % beta
n 0 = 10; % I n i t i a l count
n t = 1 ; % Number o f t r a j e c t o r i e s
t m a x = 1 0 ; %M i n u t e s f o r s i m u l a t i o n ( Approx ) .
G = c e l l ( nt , 2 ) ;
figure (1);
h o l d on
for i = 1: nt
[ T , N] = g e t t r a j e c t o r y ( n 0 , t m a x ) ;
G{ i , 1 } = T ;
G{ i , 2 } = N ;
s t a i r s (G{ i , 1 } ,G{ i , 2 } )
end
%h o l d o f f
%f i g u r e ( 2 ) ;
[ T i n t , N i n t ] = c o n s t i n t e r v a l s ( T , N, t max , 1 ) ;
plot ( T int , N int , ’ . ’ ) ;
end
f u n c t i o n [ T , N] = g e t t r a j e c t o r y ( n 0 , t m a x )
%T − t r a n s i t i o n t i m e s
%N − c o u n t s a t e a c h t r a n s i t i o n t i m e
global a b
t = 0;
j = 1;
T(1) = 0;
N( 1 ) = n 0 ;
while t < t max
j = j +1;
d t = ( − 1 / ( a ∗N( j −1) + b ) ) ∗ l o g ( rand ( 1 ) ) ;
t = t + dt ;
T( j ) = t ;
Version: 2016/11/16 13:50:27
8 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
i f rand ( 1 ) < b / ( b+a ∗N( j −1))
N( j ) = N( j −1) + 1 ;
else
N( j ) = N( j −1) − 1 ;
end
end
end
f u n c t i o n [ T i n t , N i n t ] = c o n s t i n t e r v a l s ( T , N, t max , d t i n t )
% T i n t − Times a t even i n t e r v a l s .
% N i n t − Count a t t i m e s c o r r e s p o n d i n g t o T i n t .
% T − Vector of t r a n s i t i o n times .
% N − Count o f mRNA c o r r e s p o n d i n g t o t i m e s g i v e n i n T .
% t m a x − maximum o f amount t i m e
% d t i n t − s i z e of time i n t e r v a l
T i n t = 0 : d t i n t : t max ;
N int = size ( T int ) ;
N int (1) = N( 1 ) ;
j = 1;
for i = 2: length ( T int )
while T( j ) < T i n t ( i )
j = j +1;
end
N i n t ( i ) = N( j − 1 ) ;
end
end
Version: 2016/11/16 13:50:27
9 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
Prob2.m
f u n c t i o n Prob2
global a b
a = . 1 ; % alpha
b = 1; % beta
n 0 = 0; % I n i t i a l count
n t = 1 0 0 0 ; % Number o f t r a j e c t o r i e s
t m a x = 1 0 0 ; %M i n u t e s f o r s i m u l a t i o n ( Approx ) .
G = c e l l ( nt , 2 ) ;
K = zeros ( nt , t max + 1 ) ;
V a r i n t = zeros ( 1 , t max + 1 ) ;
for i = 1: nt
[ T , N] = g e t t r a j e c t o r y ( n 0 , t m a x ) ;
G{ i , 1 } = T ;
G{ i , 2 } = N ;
[ T i n t , N i n t ] = c o n s t i n t e r v a l s ( T , N, t max , 1 ) ;
K( i , : ) = N i n t ;
end
M e a n i n t =mean (K ) ;
f o r j = 1 : t m a x +1
V a r i n t ( j ) = mean (K ( : , j ) . ˆ 2 ) − mean (K ( : , j ) ) ˆ 2 ;
end
X= ( b / a ) . ∗ ( 1 . − exp(−a . ∗ T i n t ) ) ;
figure
h o l d on
h1= p l o t ( T i n t , X ) ;
s e t ( h1 , ’ L i n e W i d t h ’ , 4 , ’ C o l o r ’ , ’ r e d ’ ) ;
h2= e r r o r b a r ( T i n t , M e a n i n t , s q r t ( V a r i n t ) ) ;
h 2 C h i l d r e n = g e t ( h2 , ’ c h i l d r e n ’ ) ;
s e t ( h 2 C h i l d r e n ( 2 ) , ’ l i n e s t y l e ’ , ’−− ’ )
xlim ( [ 0 , 1 0 5 ] )
l e g e n d ( ’ODE r e s u l t X( t ) ’ , ’ Mean <n ( t )> ’ )
x l a b e l ( ’ t ( min ) ’ )
[M, I ] =max ( V a r i n t )
end
Version: 2016/11/16 13:50:27
10 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
f u n c t i o n [ T , N] = g e t t r a j e c t o r y ( n 0 , t m a x )
%T − t r a n s i t i o n t i m e s
%N − c o u n t s a t e a c h t r a n s i t i o n t i m e
global a b
t = 0;
j = 1;
T(1) = 0;
N( 1 ) = n 0 ;
while t < t max
j = j +1;
d t = ( − 1 / ( a ∗N( j −1) + b ) ) ∗ l o g ( rand ( 1 ) ) ;
t = t + dt ;
T( j ) = t ;
i f rand ( 1 ) < b / ( b+a ∗N( j −1))
N( j ) = N( j −1) + 1 ;
else
N( j ) = N( j −1) − 1 ;
end
end
end
f u n c t i o n [ T i n t , N i n t ] = c o n s t i n t e r v a l s ( T , N, t max , d t i n t )
% T i n t − Times a t even i n t e r v a l s .
% N i n t − Count a t t i m e s c o r r e s p o n d i n g t o T i n t .
% T − Vector of t r a n s i t i o n times .
% N − Count o f mRNA c o r r e s p o n d i n g t o t i m e s g i v e n i n T .
% t m a x − maximum o f amount t i m e
% d t i n t − s i z e of time i n t e r v a l
T i n t = 0 : d t i n t : t max ;
N int = size ( T int ) ;
N int (1) = N( 1 ) ;
j = 1;
for i = 2: length ( T int )
while T( j ) < T i n t ( i )
j = j +1;
end
N i n t ( i ) = N( j − 1 ) ;
end
end
Version: 2016/11/16 13:50:27
11 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
Prob3.m
f u n c t i o n Prob3 ( )
global a rf burst
a = . 1 ; % alpha
burst = 5;
b = 1; % beta
r f = b / b u r s t ; %The f o r w a r d r a t e o f t h e r e a c t i o n . T h i s r e p l a c e s b e t a b e l o w .
n 0 = 1; % I n i t i a l count
n t = 1 ; % Number o f t r a j e c t o r i e s
t m a x = 1 0 0 0 0 ; %M i n u t e s f o r s i m u l a t i o n ( Approx ) .
G = c e l l ( nt , 2 ) ;
figure (1);
h o l d on
for i = 1: nt
[ T , N] = g e t t r a j e c t o r y ( n 0 , t m a x ) ;
G{ i , 1 } = T ;
G{ i , 2 } = N ;
s t a i r s (G{ i , 1 } ,G{ i , 2 } )
end
[ T i n t , N i n t ] = c o n s t i n t e r v a l s ( T , N, t max , 1 ) ;
mean ( N i n t )
var ( N int )
plot ( T int , N int , ’ . ’ ) ;
hold o f f
end
f u n c t i o n [ T , N] = g e t t r a j e c t o r y ( n 0 , t m a x )
% GET TRAJECTORY − Computes a s i n g l e G i l l e s p i e t r a j e c t o r y .
% Outputs :
% T − transition times
% N − c o u n t s a t each t r a n s i t i o n t i m e
% Inputs :
% n 0 − i n i t i a l number o f m o l e c u l e s .
% t max − l e n g t h of time of the s i m u l a t i o n .
global a rf burst
t = 0;
j = 1;
Version: 2016/11/16 13:50:27
12 of 13
JHU 580.429 SB3
HW12: Stochastic dynamics
T(1) = 0;
N( 1 ) = n 0 ;
while t < t max
j = j +1;
d t = ( − 1 / ( a ∗N( j −1) + r f ) ) ∗ l o g ( rand ( 1 ) ) ;
t = t + dt ;
T( j ) = t ;
i f rand ( 1 ) < r f / ( r f +a ∗N( j −1))
N( j ) = N( j −1) + b u r s t ;
else
N( j ) = N( j −1) − 1 ;
end
end
end
f u n c t i o n [ T i n t , N i n t ] = c o n s t i n t e r v a l s ( T , N, t max , d t i n t )
% CONST INTERVALS − T a k e s a t r a j e c t o r y a s i n p u t . Then c o m p u t e s t h e v a l u e o f
% n at even i n t e r v a l s .
%
%
%
%
%
%
%
%
Outputs :
T i n t − Times a t even i n t e r v a l s .
N i n t − Count a t t i m e s c o r r e s p o n d i n g t o T i n t .
Inputs :
T − Vector of t r a n s i t i o n times .
N − Count o f mRNA c o r r e s p o n d i n g t o t i m e s g i v e n i n T . A s i n g l e t r a j e c t o r y .
t m a x − maximum o f amount t i m e
d t i n t − s i z e of time i n t e r v a l
T i n t = 0 : d t i n t : t max ;
N int = size ( T int ) ;
N int (1) = N( 1 ) ;
j = 1;
for i = 2: length ( T int )
while T( j ) < T i n t ( i )
j = j +1;
end
N i n t ( i ) = N( j − 1 ) ;
end
end
Version: 2016/11/16 13:50:27
13 of 13
© Copyright 2026 Paperzz