Answered step by step
Verified Expert Solution
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 pseudorandom numbers using the inversion and acceptreject 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 be a distribution function from which we want to draw. Define the quantile function inf: Then, if
nif has distribution function
Acceptreject: Let be a density function from which we want to draw and there exists a density from which we can draw eg via the inversion method
and for which there exists a constant such that for all The following algorithm generates a random variable with density function
Generate a random variable from density
Generate a random variable independent from
If Ucg return otherwise repeat
The number of iterations needed to successfully generate is itself a random variable, which is geometrically distributed with the success acceptance
probability Hence, the expected number of iterations is Some calculations show that
a Generate samples from Bin 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started