$25
Exercise 1
Use the following lemma to generate 500 samples from a π΅πππππππ(30, 0.5) distribution in pyro. Plot the resulting distribution using sns.distplot function.
Lemma Let π1, … , ππ be independent π΅πππππ’πππ(π) random variables, then π = π1 + … + ππ is a random variable with
π΅πππππππ(π, π) distribution.
Exercise 2
1. (theory) Consider the Gamma distribution1 Gamma(πΌ, π½π½) with p.d.f.πΌ π₯πΌ−1π−π½π₯
Γ(πΌ)
and the Poisson distribution Poisson(π) with p.m.f.
πππ−π
π! .
Given the generative model
π ∼ Gamma(πΌ, π½) π₯ ∼ Poisson(π)
prove that the Gamma distribution is a conjugate prior2 for the Poisson likelihood.
2. (code) Set the parameters of the Gamma distribution to πΌ = 1 and π½ = 2. Write the pyro code to sample π and π₯, extract 300 samples from the distributions of both random variables and plot their histograms.
3. (code) Suppose you observe some data π₯ = [3, 10, 2, 5, 6, 7]. Plot 300 samples from the posterior distribution of π as the number of observed data points from π₯ increases:
π₯ = [3, 10] π₯ = [3, 10, 2, 5] π₯ = [3, 10, 2, 5, 6, 7].
1Section "Probability distributions" in notebook 01.
2Section "Conjugate priors" in notebook 02.