PYTHON:
Using the function random.random_sample from numpy package write two functions:
* poissonRV(seed, mean,n) that returns for given seed a bunch of n Poisson distributed random numbers with the provided mean. You have to numerically calculate the inverse distribution function.
funnyDiceRV(seed,n) that returns for given seed a bunch of n random number which describe a biased die with distribution ℙ({1})=ℙ({2})=ℙ({3})=ℙ({4})=ℙ({5})=1/10P({1})=P({2})=P({3})=P({4})=P({5})=1/10 and ℙ({6})=1/2P({6})=1/2.
The Python code for generating Random numbers from the specified Poisson distribution and the specified Dice is given below:
from numpy import random import math def poissonRV(seed, mean,n): P = [] limit = math.exp(-mean) random.seed(seed) for i in range(n): prod = random.random_sample(1) p = 0 while (prod >= limit): prod *= random.random_sample(1) p += 1 P.append(p) return(P) def funnyDiceRV(seed,n): D = [] random.seed(seed) for i in range(n): r = random.random_sample(1) if(r<0.5): r1 = random.random_sample(1) if(r1<0.2): D.append(1) elif(0.2<=r1 and r1<0.4): D.append(2) elif(0.4<=r1 and r1<0.6): D.append(3) elif(0.6<=r1 and r1<0.8): D.append(4) elif(0.8<=r1 and r1<1): D.append(5) else: D.append(6) return(D) P = poissonRV(10900, 100,5) print("The Poisson RVs are : ", P) D = funnyDiceRV(900, 12) print("The Outcomes of the Dice are : ", D)
Sample output:
The Poisson RVs are : [94, 99, 104, 107, 79]
The Outcomes of the Dice are : [2, 6, 2, 6, 1, 2, 6, 6, 3, 2, 6,
5]
Get Answers For Free
Most questions answered within 1 hours.