Week 11: November 9 - 13
Non-Uniform Random Numbers
The most interesting and useful probability distributions are not "uniform", although we do know their exact form. We would therefore like a way to generate samples from any probability distribution. This week we develop a way to do this through an appropriate transformation of a uniform random number.
Finding the "best" solution to a problem is a common requirement in engineering and in the natural and social sciences. We start by looking at ways to do this for functions of a single variable.
Week 11 Notebook
There will be no quiz this week.
Assignment 8: The Generation and Use of Random Numbers
- Exercise 1: Test the linear congruential generators in your rng and randu functions, and the generator in random.rand for (i) uniformity, and (ii) lack of (coarse-scale) successive pair correlation.
- Exercise 2: Use Monte Carlo integration to average the function mysteryf in the mystery module by random sampling using random.rand over the interval [0, 5].
- Exercise 3: Use Monte Carlo integration to estimate the area of the "flower", whose boundary has the equation r(θ) = 2 + cos(7θ) in polar coordinates.
- Exercise 4: Numerically estimate the probability of getting 29 hits in 100 swings in a baseball game if the probability of getting a hit on any one swing in 0.29 (and is independent of other swings).
- Exercise 5: Produce a histogram of the sums of pairs of uniformly distributed random numbers produced by random.rand.
- Produce histograms for the sums of M-tuples of uniform random numbers for values of M greater than 2.
- See if it is possible to shift and stretch the sums of M-tuples so that their distribution converges to something as M increases without bounds.
- Plot and analyze the sums of M-tuples of non-uniform random numbers.
- Exercise 6: Implement the simple stock market model defined in class. Use a value for μ of 0.0 and σ of 5% to find out what happens to an initial investment of 1 unit of money over 365 steps.
- Plot the changing price of several stocks over this period.
- Plot a histogram of final stock prices after 365 steps using a large number of trials.
- Estimate the "expected value" (average over all trials) of the investment after 1 year.
- Calculate the likelihood of losing money.
- Calculate the "most likely" value of the investment after 1 year, using an appropriate definition of "most likely".
- Draw some conclusions about investing, or on the value of money.
- Run another simulation using a more modest value for σ of 1%.