MATH 314 Exam 01

  1. Choose a Binomial distribution. Generate an appropriate amount of data from your Binomial distribution to make the following plot. Make one convergence plot that contains 100100 convergence paths, each one estimating the variance. Add a dashed black line to represent the true expectation value for the variance of your chosen distribution. The dashed black line should be on top of the convergence paths. Add axis labels, a title, and a lengend. No Python for-loops are allowed.
  2. Generate an appropriate amount of data from the Poisson distribution Poisson(λ=4)\text{Poisson}(\lambda = 4) to make the following plot. Make one convergence plot that contains 100100 convergence paths, each one estimating the probability that a random variable following your Poisson distribution is greater than 7: XPoisson(λ=4)X \sim \text{Poisson}(\lambda = 4), P[X7]\mathbb{P}[X \geq 7]. Add a dashed black line to represent the true expectation value for the probability of interest. The dashed black line should be on top of the convergence paths. Add axis labels, a title, and a lengend. No Python for-loops are allowed.
  3. Use the following "deck of cards" to estimate the probability of the poker hand, full house.
    face = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
    suit = ['C', 'D', 'H', 'S']
    cards = np.array([(f, s) for f in face for s in suit])
    
    Hint: consider the Numpy function unique.
  4. Uniform sampling from a stream of numbers, where you don't have the availability (memory or otherwise) to store more than one of the numbers at a time, is a clever trick.

    Write a Python class called OnlineUniformSampler, which implements the following API:

    ou = OnlineUniformSampler(95928)
    ou.update(1)
    ou.update(2)
    ou.update(3)
    ou.sample()
    ou.count()

    The class method sample() should return one, uniformly chosen, of the values input to the possibly many calls of update().

    The class method update() should implement an algorithm based on the following description. For the first value passed to update(), store it. For ii-th call to update(x_i), replace the stored value with the passed in value x_i with probability 1/i1/i. Not all calls to update() will successfully replace the stored value. To replace a stored value uu with the ii-th value of xx with a probability pp, use code like

    rng = np.random.default_rng(seed)
    if rng.uniform() <= p:
        u = x
    

    where the variable rng should be re-used within this class.

    As was requested in class today, the theory for this algorithm is explained (in my opinion) well on this blog post.

  5. In a chemical processing plant, a specific reactor is known to have a rare malfunction due to random impurities in the reactants. Over the past several years, data has shown that this malfunction occurs on average 1.5 times every 100 hours of operation. A new batch of reactant is being processed in this reactor for a continuous 48-hour run.
    1. What is the probability that there will be no malfunctions during this 48-hour run?
    2. What is the probability that there will be at least one malfunction during this 48-hour run?
    3. What is the probability that there will be more than two malfunctions during this 48-hour run?
  6. A major manufacturer of capacitors claims that their latest model, the UltraCap 3000, has an average lifetime of 5,000 hours before it fails. This lifetime is exponentially distributed. Capacitors that fail prematurely can cause significant issues in electrical circuits, so understanding their reliability is crucial.
    1. What is the probability that an UltraCap 3000 will last more than 7,000 hours before failing?
    2. What is the probability that an UltraCap 3000 will last less than 4,000 hours?
    3. What is the probability that an UltraCap 3000 will fail in somewhere between 1000 and 6000 hours?
  7. Test the class OnlineUniformSampler to show that it samples uniformly, e.g. demonstrate with code that the samples produced are uniform.
  8. Suppose you are in a class with the following grade distribution, and that you know you have the following scores: 93%93\% in Homework, 88%88\% in Quizzes, and 97%97\% on the first exam. What is the minimum score on the second exam necessary for you to get an A. Your solution should be in code, using Numpy, the formula for an expectation, and algebra.
    Component Percentage
    Homework 10%
    Quizzes 40%
    2x Live Coding Exams 25% each
  9. Expectations of random variables E[X]\mathbb{E}[X] and means of data are more closely related than you might at first think. Generate 10001000 random variables from a Binomial distribution of your choice. Calculate the mean of these data. Then estimate the probability of each value xx that your distribution could take on, P[X{x}]\mathbb{P}[X \in \{x\}] for all xSx \in S. Use these estimated probabilities, inplace of the density function, to "calculate" the expectation E[X]\mathbb{E}[X].
  10. The mode of a distribution is the value of xx at which the maximum of the density is achieved, if such a point exists. The mode of a dataset is the value of the dataset that shows up the most, is such a value exists. Write a class named OnlineMode() that implements the following API
    om = OnlineMode()
    om.update(1)
    om.update(2)
    om.update(1)
    om.mode() # returns 1 
    
    Generate random variables from the Binomial(10,0.75)\text{Binomial}(10, 0.75) distribution and make a convergence plot to show that your class works reasonably well.