In the Python problem we want to simulate the branching proc

In the Python problem we want to simulate the branching process X_n, n Greaterthanorequalto 0 with p_0 = 1/5 = p_1, p_2 = 1/2, p_3 = 1/10. First note that X_n = sigma _k = 1^X_n -1 xi_n, k, where xi _n, k represents the number of offspring of k -th individual in the n - th generation. Here {xi _n, k} are I.I.D. random variables with probability distribution P(xi_n, k = 0) = 1/5 = P(xi_n, k = 1), P(xi _n, k = 2) = 1/2, P(xi _n, k = 3) = 1/10. Write a Python code as a function which generates the random variables xi_n, k, k = 1, ..., K given X_n - 1 = K.

Solution

from random import random

def generate_random_variables(K):
    random_variables = []
    for i in range(K):
        num = random()
        if num<0.2:
            random_variables.append(0)
        elif num<0.4:
            random_variables.append(1)
        elif num<0.9:
            random_variables.append(2)
        else:
            random_variables.append(3)
    return random_variables

print generate_random_variables(10)

 In the Python problem we want to simulate the branching process X_n, n Greaterthanorequalto 0 with p_0 = 1/5 = p_1, p_2 = 1/2, p_3 = 1/10. First note that X_n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site