Let\'s consider a collection of n(t) cells, where cells are born with rate p and
ID: 3785868 • Letter: L
Question
Let's consider a collection of n(t) cells, where cells are born with rate p and die with rate n. In a given time interval At, the probabilities to observe a birth or a death are therefore Po AtB and P Atrn(t). The birth-death process can be considered a Poisson process, where each event occurs stochastic and independent from the other events. As discussed in class, the distribution of times between events follows an exponential probility density function, P (t) Rexp -tR], where R B+ n(t)r is the total rate for something (either birth or death) to happen. Note that this rate changes with time. (a) Write a computer program that creates a stochastic realization of the number cells n(t) as a function of time. This can be done by implementing the following "continuous time" (sometimes also called Gillespie) algorithm. At each timestep, Draw a time increment from the exponential distribution P(t) with rate R (recall the transformation rules for probabilities) The probability that a birth has occurred in that time increment reads B/R, while the probability for a death is 1 5. These quantities are sometimes called "relative propensities". Draw a (uniformly distributed) random number to decide which event has occured Update n(t) by adding or subtracting 1, depending on the outcome of the above, and update time t E t ot Repeat until t reaches tExplanation / Answer
import math
t=0
t_max=100
n=input()
B=float(input())
G=float(input())
R=B+n*G
P=R*math.exp(-t*R)
rate=0.01
while t<t_max:
eps=B/R
b_inc=eps
d_inc=1-eps
h=n*B*rate+n*G*rate
r = rand(2,1);
t_del=log(r(1))/h
flag = sum(r(2)*h <= 0.5);
if flag: n+=1
else: n-=1
t=t+t_del
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.