Question

PYTHON: Using the function random.random_sample from numpy package write two functions: * poissonRV(seed, mean,n) that returns...

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.

Homework Answers

Answer #1

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]

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
USING MATLAB Write a MATLAB function that simulates a single roll of a n-sided die. The...
USING MATLAB Write a MATLAB function that simulates a single roll of a n-sided die. The inputsand outputs of the function are: Inputs: •The probabilities for each side, given as a vector p = [p1,p2...pn] Outputs: •The number onthe face of the die after a single roll, i.e.onenumber fromthe setof integers {1, 2 ,....n} Note: The sum p1+p2+.....pn must be equal to 1.0, otherwise the probability values are incorrect. Savethe function as: nsided_die(p) Test the functionwitha 5-sided die,where the probabilities...
Q2- Write a function solution that, given an integer N, returns the maximum possible value obtained...
Q2- Write a function solution that, given an integer N, returns the maximum possible value obtained by inserting one '5' digit inside the decimal representation of integer N. Examples: 1. Given N = 268, the function should return 5268. 2. Given N = 670, the function should return 6750. 3. Given N = 0, the function should return 50. 4. Given N = −999, the function should return −5999. Assume that: N is an integer within the range [−8,000..8,000].
Write a Python function count_bigger that takes two parameters, a nested list of objects and a...
Write a Python function count_bigger that takes two parameters, a nested list of objects and a threshold number. It returns an integer specifying how many of the objects anywhere in the nested list are numbers that are larger than the threshold. (For our purposes, "numbers" are either integers or floats.) There may be objects in the list other than numbers, in which case you would simply ignore them. Here are a couple of examples of how the function should behave...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n,...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n, a positive integer, it returns a list of n tuples corresponding to the numbers 1 through n (both inclusive): the tuple for the number k consists of k as the first component, and exactly one of the following strings as the second: • the string 'two!' if k is divisible by 2 • the string 'three!' if k is divisible by 3 • the...
In Python: This will require you to write several functions, and then use them in a...
In Python: This will require you to write several functions, and then use them in a program. Logical Calculator The logical calculator does math, but with logical operators. In logic, we represent a bit with 0 as false and a bit with 1 as true. The logical operators are NOT, AND and OR. Bitwise logical calculations operate on each bit of the input. The NOT operator works on just one three-bit argument. NOT 011 = 100 The AND operator works...
write a code in python Write the following functions below based on their comments. Note Pass...
write a code in python Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries. #!/usr/bin/python3 #(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are...
Poisson Distribution: p(x, λ)  =   λx  exp(-λ) /x!  ,  x = 0, 1, 2, ….. Find the moment generating function Mx(t)...
Poisson Distribution: p(x, λ)  =   λx  exp(-λ) /x!  ,  x = 0, 1, 2, ….. Find the moment generating function Mx(t) Find E(X) using the moment generating function 2. If X1 , X2 , X3  are independent and have means 4, 9, and 3, and variencesn3, 7, and 5. Given that Y = 2X1  -  3X2  + 4X3. find the mean of Y variance of  Y. 3. A safety engineer claims that 2 in 12 automobile accidents are due to driver fatigue. Using the formula for Binomial Distribution find the...
For this question, you may (where appropriate) write down an Excel formula using one of the...
For this question, you may (where appropriate) write down an Excel formula using one of the functions listed below instead of providing a numerical answer. However, you must specify clearly the value of each parameter in the Excel function (you may use the 2010 or the 2007 version). If you choose to provide a numerical answer, it should be accurate to 3 significant figures. (a) Let F denote the cumulative distribution function (cdf) of a uniformly distributed random variable X....
Question 1 Refer to the probability function given in the following table for a random variable...
Question 1 Refer to the probability function given in the following table for a random variable X that takes on the values 1,2,3 and 4 X 1 2 3 4 P(X=x) 0.4 0.3 0.2 0.1 a) Verify that the above table meet the conditions for being a discrete probability distribution b) Find P(X<2) c) Find P(X=1 and X=2) d) Graph P(X=x) e) Calculate the mean of the random variable X f) Calculate the standard deviation of the random variable X...
A Poisson distribution has λ = 4.7.   (a )[2] Use the Excel function POISSON.DIST() and 5...
A Poisson distribution has λ = 4.7.   (a )[2] Use the Excel function POISSON.DIST() and 5 decimals to fill in the following table: 4 x 0 1 2 3 4 5 6 7 8 9 10 11 12+ P(x) (b)[2] Use a column chart to visualize the probability distribution above. How is it skewed? (c)[1] Find P(x ≤ 3). [steps & result] (d)[1] Find P(x ≥ 7). [steps & result] (e)[2] Find P(5 < x ≤ 9). [steps & result]...