Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 import uniform
from scipy.special import binom
from numpy import sqrt, pi, exp, tan, cumsum
from scipy.stats import probplot
import pandas as pd
import matplotlib.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
UU nif [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 algorithm 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 itself a random variable, which is geometrically distributed with the success (acceptance)
probability p=P(Ucg(x)f(x)). Hence, the expected number of iterations is 1p. Some calculations show that p=1c.
(a) Generate 10000 samples from Bin(10,0.4) using (i) the inversion method directly and (ii) using the inversion method to draw corresponding Bernoulli
distributed samples. (iii) Plot the resulting empirical distribution functions and add the theoretical distribution function in one figure.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions