Starting from:

$25

PML-Homework 2 Solved

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.

More products