In this Python problem we want to simulate the branching process Xn , n ? 0 with
ID: 3761949 • Letter: I
Question
In this Python problem we want to simulate the branching process Xn , n ? 0 with p0 =1/4=p1, p2 =1/2.First note that
where ?n,k represents the number of offspring of k -th individual in the n -th generation. Here {?n,k} are I.I.D. random variables with probability distribution P(?n,k = 0) = 1/4 = P(?n,k = 1), P(?n,k = 2) = 1/2.
(a) Write a code which generates the random variables ?n,k , k = 1, . . . , K given Xn = K .
(b) Generate the branching process Xn with the initial distribution X0 = 1 for n = 1,...,20.
(c) Simulate this branching process {Xn, 1 ? n ? 20} 1000 times, and estimate the prob-ability of extinction.
Explanation / Answer
(a)
params = [a1, a2, ..., ak]
sample = [random.gammavariate(a,1) for a in params]
sample = [v/sum(sample) for v in sample]
(b)
params = [a1, a2, ..., ak]
xs = [random.betavariate(params[0], sum(params[1:]))]
for j in range(1,len(params)-1):
phi = random.betavariate(params[j], sum(params[j+1:]))
xs.append((1-sum(xs)) * phi)
xs.append(1-sum(xs))