Question

Gaussian random values. Experiment with the following function for generating random variables from the Gaussian distribution,...

Gaussian random values. Experiment with the following function for generating random variables from the Gaussian distribution, which is based on generating a random point in the unit circle and using a form of the Box-Muller formula (see Exercise 1.2.24)

def gaussian():
r = 0.0
while (r >= 1.0) or (r == 0.0):
x = -1.0 + 2.0 * random.random()
y = -1.0 + 2.0 * random.random()
r = x*x + y*y
return x * math.sqrt(-2.0 * math.log(r) / r)

Take a command-line argument n and generate n random numbers, using an array a [ ] of 20 integers to count the numbers generated that fall between i * .05 and (i+1) * .05 for i from 0 to 19. Then use stddraw to plot the values and to compare your result with the normal bell curve.

using the book site modules stdarray and stdio to implement the functions.  

Homework Answers

Answer #1

A Gaussian distribution with mean zero and standard deviation one, often known as
a “standard normal” distribution, has the probability density function (PDF):
φ(x) = 1


e−x2/2. (1)
A plot of φ(x) versus x gives the familiar bell-curve shape, but does not directly indicate
the probability of occurrence of any particular range of values of x.

from −∞ to x gives the cumulative distribution function (CDF):
(x) =
-
x
−∞
φ(x)dx = 1
2

1 + erf x

2
Algorithm 2. Monty Python
1: s ← 22U1 − 1 {Choose random sign (+1 or −1) for output sample}
2: x ← bU2 {Horizontal component of uniform 2D random sample}
3: if x < a then {Check if point is in area A}
4: return sx
5: end if
6: y ← U3/(2b) {Vertical component of uniform 2D random sample}
7: if y < φ(x) then {Check if point is under Gaussian PDF in area B}
8: return sx
9: end if
10: (x, y) ← fC(x, y) {Point is in region C
, transform it to region C}
11: if y < φ(x) then {Check if point is under Gaussian PDF in area C}
12: return sx
13: else
14: return Return x from the tails with |x| > b (see section 3)
15: end if

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
Find the moment generating function of each of the following random variables. Then, use it to...
Find the moment generating function of each of the following random variables. Then, use it to find the mean and variance of the random variable 1. Y, a discrete random variable with P(X = n) = (1-p)p^n, n >= 0, 0 < p < 1. 2. Z, a discrete random variable with P(Z = -1) = 1/5, P(Z = 0) = 2/5 and P(Z = 2) = 2/5.
A table of values is given for a function f(x, y) defined on R = [1,...
A table of values is given for a function f(x, y) defined on R = [1, 3] × [0, 4]. 0 1 2 3 4 1.0 2 0 -3 -6 -5 1.5 3 1 -4 -5 -6 2.0 4 3 0 -5 -8 2.5 5 4 3 -1 -4 3.0 7 8 6 3 0 Estimate f(x, y) dA R using the Midpoint Rule with m = n = 2 and estimate the double integral with m = n =...
Give the named probability distribution for each of the following random variables with specific parameter values....
Give the named probability distribution for each of the following random variables with specific parameter values. You should name the parameters, that is, write the parameter name in your answer (for example, Binomial(n=30,p=0.5)) (a) Nia has 6 cats. Each cat has a 25% chance of finishing their dinner. The cats eat independently of each other. What is the distribution of X: the total number of cats that finish their dinner? (b) Nia has a cat that meows a lot. The...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS...
# Parts to be completed are marked with '<<<<< COMPLETE' import random N = 8 MAXSTEPS = 5000 # generates a random n-queens board # representation: a list of length n the value at index i is # row that contains the ith queen; # exampe for 4-queens: [0,2,0,3] means that the queen in column 0 is # sitting in row 0, the queen in colum 1 is in row, the queen in column 2 # is in row 0,...
The following observations are obtained from a random sample of 10 individuals: Individual x y 1...
The following observations are obtained from a random sample of 10 individuals: Individual x y 1 9.08 5.25 2 4.23 3.58 3 6.88 4.75 4 10.3 5.38 5 8.09 4.27 6 10.6 5.79 7 4.50 3.41 8 8.32 5.75 9 7.17 4.74 10 9.45 5.43 Run a t-linear regression test on this data. (HINT: make sure you copy the numbers correctly!) What are the appropriate null and alternative hypotheses? H0:r=0H1:r≠0 H0:ρ=0H1:ρ<0 H0:ρ=0H1:ρ≠0 H0:r=0H1:r>0 H0:r=0H1:r<0 H0:ρ=0H1:ρ>0 What is the correlation coefficient?...
The following algorithm finds the initial substring of y that can be reversed and found in...
The following algorithm finds the initial substring of y that can be reversed and found in y. For example, longestInitialReverseSubstringLength(“aabaa”) = 5, because “aabaa” is the same string forwards and backwards, so the longest initial substring that can be reversed and found in the string is “aabaa”. Also, longestInitialReverseSubstringLength(“bbbbababbabbbbb”) is 6, because “babbbb” can be found in the string (see color-highlighted portions of the string), but no longer initial string exists reversed in any part of the string. longestInitialReverseSubstringLength(String y)...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT