Saint Louis University |
Computer Science 145
|
Dept. of Math & Computer Science |
Topic: Random Processes
Related Reading: various notes.
Due:
Tuesday, 3 March 2009, 11:59pm
For this assignment, you must work individually in regard to the design and implementation of your project.
Please make sure you adhere to the policies on academic integrity in this regard.
Write a function with signature pi = approxPi(n) that approximates pi in this fashion based upon the analysis of n random points.
With this problem, we explore a classic problem known as Coupon Collecting.
Assume that we repeatedly pick a random integer in a domain from 1 to n. Our interest is in how long it takes until all numbers have been picked at least once. Some natural questions we might ask are
For example, the 1987 set of Topps baseball cards has 792 distinct cards. The expected number of cards that must be purchased before collecting a complete set is approximately 5750.
For example, with a random group of 365 people, we expect to see approximately 231 distinct birthdays.
For example, after collecting 5750 random baseball cards mentioned above, the chance of having a complete set is only 57%
To help answers questions like this, we want you to implement a utility function that performs independent trials of such an experiment. Please adhere to the following documentation.
function [selections success coverage] = collect(n, trials, limit) % Pick random numbers from 1 to n, until each is selected or limit is reached. % USAGE: [selections success coverage] = collect(n, limit, trials) % % Input arguments: % n designates the number of distinct values to collect % (i.e., numbers from 1 to n) % % trials designates the number of independent trials to % simulate. If not specified, one trial will be performed. % % limit is the maximum number of selections to make before % considering a trial a failure. If not specified, then limit % is set to inf. % % Output arguments: % selections is the AVERAGE number of selections made per trial. % % success is the percentage of trials in which all values were % collected. Note that when limit=inf, success=1 by definition. % % coverage is the AVERAGE number of distinct values from % 1 to n that have been selected per trial. % Note that when limit=inf, coverage=n by definition.
As a concrete example, assume that we call
In this case, the output arguments should be selections=13.5
(the average of 15 and 12), success=0.5 (the average of 0 and
1), and coverage=8.5 (the average of 7 and 10).
function plotCoverageTime(n, trials) % Graphs the average number of selections needed to collect all k in 1:n. % USAGE: plotCoverageTime(n, trials) % % For each value k from 1 to n, this performs repeated % trials of the coupon collecting experiment. % % It produces a bar graph plotting the average number of % selections made per trial, relative to the value of k.
Submit your m-file plotCoverageTime.m as well as a
sample file coverage30.jpg that is produced when calling
your function with n=30 and trials=1000. You can save the most
recently drawn figure to a jpg file in MATLAB by using a command
such as
function plotPartialCoverage(n, s, trials) % Graphs statitics about s random selections from 1 to n. % USAGE: plotPartialCoverage(n, s, trials) % % For a fixed n and s, this explores what happens in a % typical experiment when collecting k items from 1 to n, % as k ranges from 1 to s. % % It produces a graph with two subplots. The first subplot % shows the average number of values that will be covered, % relative to the choice of k. The second subplot shows % the chance of having covered all values after k selections.
Submit your m-file plotPartialCoverage.m as well as a
sample file partial30_300.jpg that is produced when calling
your function with n=30, s=300, and trials=1000. You can save the most
recently drawn figure to a jpg file in MATLAB by using a command
such as
Separate out the gathering of data for the plots with the plotting itself. This way, we could change the style of the plot without having to recompute the raw data. (more specific details available upon request)