Question: Please write in python.In this exercise, we will generate ( pseudo - ) random numbers using the inversion and accept - reject method. In order

Please write in python.In this exercise, we will generate (pseudo-)random numbers using the inversion and accept-reject method. In order to generate the random numbers you are
only allowed draw from the Uniform distribution and use
from random inport uniform
from scipy. special inport binon
from numpy import sqrt, pi, exp, tan, cunsum
from scipy.stats import probplot
import pandas as pd
inport natplotilb.pyplot as plt
Inversion method: Let F be a distribution function from which we want to draw. Define the quantile function F-1(u)=inf{x:F(x)u,0u1}. Then, if
UUnif[0,1],F-1(U) has distribution function F
Accept-reject: Let f be a density function from which we want to draw and there exists a density g from which we can draw (e.g., via the inversion method)
and for which there exists a constant c such that f(x)cg(x) for all x. The following algonithm generates a random variable x with density function f.
Generate a random variable x from density g
Generate a random variable UUnif{0,1](independent from x)
If Ucg(x)f(x), return x, otherwise repeat 1.-3.
The number of iterations needed to successfully generate x is itseif a random variable, which is geometrically distributed with the success (acceptance)
probabinty p=P(Ucg(x)f(x)). Hence, the expected number of iterations is 1p. Some calculations show that p=1c.
(b) Generate 10000 samples from the standard normal distribution using the accept-reject method with candidate density g(x)=(x(1+x2))-1 with
distribution funciton G(x)=tan-1x from the standard Cauchy distribution. To this end, (i) determine (mathematically or via simulation) the value of c1
closest to one so that f(x)cg(x) for all x.(ii) Obtain 10000 standard normal random variables using the accept-reject method, generating Cauchy
distributed random variables using inversion method. (iii) Compare estimated and theoretical acceptance probabilities. (iv) Generate a QQ-plot of the
generated sample.
 Please write in python.In this exercise, we will generate (pseudo-)random numbers

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!