Description
Exercise 1
Use the following lemma to generate samples from a distribution in pyro. Plot the resulting distribution
using sns.distplot function.
Lemma Let be independent random variables, then is a random variable with
distribution.
500 𝐵𝑖𝑛𝑜𝑚𝑖𝑎𝑙(30, 0.5)
𝑋1, … , 𝑋𝑛 𝐵𝑒𝑟𝑛𝑜𝑢𝑙𝑙𝑖(𝑝) 𝑋 = 𝑋1 + … + 𝑋𝑛
𝐵𝑖𝑛𝑜𝑚𝑖𝑎𝑙(𝑛, 𝑝)
Exercise 2
1. (theory) Consider the Gamma distribution with p.d.f.
and the Poisson distribution with p.m.f.
Given the generative model
prove that the Gamma distribution is a conjugate prior for the Poisson likelihood.
2. (code) Set the parameters of the Gamma distribution to and . Write the pyro code to sample and , extract
samples from the distributions of both random variables and plot their histograms.
3. (code) Suppose you observe some data . Plot samples from the posterior distribution of as the
number of observed data points from increases:
Section “Probability distributions” in notebook 01.
Section “Conjugate priors” in notebook 02.
1 Gamma(𝛼, 𝛽)
𝛽𝛼
Γ(𝛼)
𝑥𝛼−1𝑒−𝛽𝑥
Poisson(𝜆)
. 𝜆𝑘𝑒−𝜆
𝑘!
𝜆
𝑥
∼ Gamma(𝛼, 𝛽)
∼ Poisson(𝜆)
2
𝛼 = 1 𝛽 = 2 𝜆 𝑥 300
𝑥 = [3, 10, 2, 5, 6, 7] 300 𝜆
𝑥
𝑥
𝑥
𝑥
= [3, 10]
= [3, 10, 2, 5]
= [3, 10, 2, 5, 6, 7].
1
2

