Mock Exam | Discussion | Questions Mock Exam Question # Letusassume aprobability distribution forcount data .Which ofthe following type of… [616521]

Probabilistic Programming
Marius Popescu
[anonimizat]
2019 -2020

Mock Exam | Discussion | Questions

Mock Exam

Question #
Letusassume aprobability distribution forcount data .Which ofthe following type of
distribution wewould choose formodelling :
❑Bernoulli distribution
❑Exponential distribution
❑Poisson distribution

Problem #
Write two different PyMC stochastic variables that can represent a discrete random variable
X that takes value in {0, 1, 2, 3, 4, 5}. Which one is the must uninformative?
X = pm.DiscreteUniform (“X", lower = 0, upper = 5)
X = pm.Categorical (“X”, p = [0.1, 0.1, 0.1, 0.2, 0.2, 0.3])
DiscreteUniform (or both if the values of pare equal)

Question #
From the following distribution which one is a conjugate prior for the Bernoulli distribution:
❑Gamma distribution
❑Beta distribution
❑Uniform distribution on (0, 1)

Question #
The figure bellow isthe result of
pymc.Matplot.plot of a stochastic
variable alpha after MCMC .Did the
MCMC converged? Justify your answer .
TheMCMC hasconverged .Reasons :
Thetrace shows that after varying alot
at the beginning (1000–2000
iterations) thechain tends toward an
equilibrium value, with asmaller
variance .
The histogram of the posterior
distribution ofalpha isconcentrated in
asmall area (around 1)
The autocorrelation becomes and
remains small (after lag16–18)

Problem #import pymcas pm
import numpyas np
import matplotlib.pyplot as plt
true_coin_bias = 0.3 # The (unknown) bias of the coin
num_flips = 100
# The given data, the result of 100 coin flips
data = np.random.choice ([0, 1], p=[1 -true_coin_bias, true_coin_bias ], size= num_flips )
# We want to infer the bias, p. Since p is unknown, it is a random variable.
# The distribution we assign to it here is our prior distribution on p, uniform on the range [0, 1].
p = pm.Uniform ("p", lower=0, upper=1)
# We need another random variable for our observations.
# We give the relevant data to the value argument.
# The observed flag stops the value changing during MCMC exploration.
observations = pm.Bernoulli ("obs", p=p, value=data, observed=True)
model = pm.Model ([p, observations])
mcmc= pm.MCMC(model)
mcmc.sample (60000, 10000) # 60000 steps, with a burn in period of 10000
p_samples = mcmc.trace ("p")[:] # Samples from our posterior on p
print()
print(p_samples.mean ())
plt.hist (p_samples , bins=40, normed=True)
plt.axvline (x=true_coin_bias , c="k")
plt.xlabel ("p")
plt.title ("Approximate posterior of p")
plt.xlim (0,1);
plt.show ()Write aPyMC program that
infers thebias ofacoin given
100 observations ofthe coin
flips

Discussion | Questions

Similar Posts