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...
   Dice Game – Accumulator Pattern and Conditionals (40 pts) IN PYTHON Write a program dicegame.py...
   Dice Game – Accumulator Pattern and Conditionals (40 pts) IN PYTHON Write a program dicegame.py that has the following functions in the following order: in python Write a function roll that takes an int n and returns a random number between 1 and n inclusive. Note: This function represents a n sided die so it should produce pseudo random numbers. You can accomplish this using the random module built into python.         (3 pts) Write a function scoreRound that...
Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum...
Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at least...
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].
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...
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...
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...
Function name : matrixMultiplication Parameters : aMatrix (list), bMatrix (list) Returns Type: list of tuples Description...
Function name : matrixMultiplication Parameters : aMatrix (list), bMatrix (list) Returns Type: list of tuples Description : Write a function in PYTHON that takes in two matrices (list of tuples or list of lists) and multiplies the two matrices together. Assume that the given matrices will be valid, i.e. aMatrix will be n x m (n rows and m columns) and bMatrix will be m x ℓ (m rows and ℓ columns). *Assume elements of aMatrix & bMatrix will be...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT