MATH 314 Exam 01
- 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 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.
- Generate an appropriate amount of data from the Poisson distribution to make the following plot. Make one convergence plot that contains convergence paths, each one estimating the probability that a random variable following your Poisson distribution is greater than 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.
- 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. 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 ofupdate()
.The class method
update()
should implement an algorithm based on the following description. For the first value passed toupdate()
, store it. For -th call toupdate(x_i)
, replace the stored value with the passed in valuex_i
with probability . Not all calls toupdate()
will successfully replace the stored value. To replace a stored value with the -th value of with a probability , use code likerng = 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.
- 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.
- What is the probability that there will be no malfunctions during this 48-hour run?
- What is the probability that there will be at least one malfunction during this 48-hour run?
- What is the probability that there will be more than two malfunctions during this 48-hour run?
- 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.
- What is the probability that an UltraCap 3000 will last more than 7,000 hours before failing?
- What is the probability that an UltraCap 3000 will last less than 4,000 hours?
- What is the probability that an UltraCap 3000 will fail in somewhere between 1000 and 6000 hours?
- Test the class
OnlineUniformSampler
to show that it samples uniformly, e.g. demonstrate with code that the samples produced are uniform. - Suppose you are in a class with the following grade
distribution, and that you know you have the following
scores: in
Homework, in Quizzes, and 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 - Expectations of random variables and means of data are more closely related than you might at first think. Generate random variables from a Binomial distribution of your choice. Calculate the mean of these data. Then estimate the probability of each value that your distribution could take on, for all . Use these estimated probabilities, inplace of the density function, to "calculate" the expectation .
- The mode of a distribution is the value of 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 APIom = OnlineMode() om.update(1) om.update(2) om.update(1) om.mode() # returns 1
Generate random variables from the distribution and make a convergence plot to show that your class works reasonably well.