Assignments | Class Photo | Course Home | Lab Hours/Tutoring | MATLAB info | Schedule | Submit

Saint Louis University

Computer Science 145
Scientific Programming

Michael Goldwasser

Spring 2009

Dept. of Math & Computer Science

Assignment 06

Random Processes


Contents:


Overview

Topic: Random Processes
Related Reading: various notes.
Due: Tuesday, 3 March 2009, 11:59pm


Collaboration Policy

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.


Problems to be Submitted (20 points)

  1. (5 points)
    The value of pi can be approximated using the following random process. We know that a circle with radius one centered at the origin has area pi, while the circumscribing square ranging from -1 to 1 along both axes has an area of 4. We can therefore estimate the value of pi by picking points uniformly at random in that square and then checking what percentage of those points also lie within the unit circle. That percentage should approach pi/4.

    Write a function with signature pi = approxPi(n) that approximates pi in this fashion based upon the analysis of n random points.


  2. (7 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

    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 collect(10, 2, 15) and that the random numbers ended up as follows
    Trial 1: 2 2 4 8 6 5 5 4 8 6 1 2 5 7 7
    Trial 2: 8 5 1 3 9 10 2 6 5 4 2 7
    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).


  3. (4 points)
    Use your function from Problem B to develop another function adhering to the following description.
          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 saveas(gcf, 'coverage30.jpg'). As an example, here is our plot for n=365.


  4. (4 points)
    Use your function from Problem B to develop another function adhering to the following description.
          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 saveas(gcf, 'partial30_300.jpg'). As an example, here is our plot for collecting the 792 baseball cards. You will notice that the plot on the bottom is not so crisp. We were only able to complete 100 trials for each experiment (even that took 47 minutes of computation time). As a result, counting the number of successful trials out of those 100 gets us a coarse approximation of the underlying probability.


Extra Credit (2 points)

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)


Michael Goldwasser
CSCI 145, Spring 2009
Last modified: Monday, 02 March 2009
Assignments | Class Photo | Course Home | Lab Hours/Tutoring | MATLAB info | Schedule | Submit