Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-280

Gamma-Poisson Posterior Parameters

Problem

A Gamma(alpha, beta) prior on a Poisson rate is updated with a list of observed counts. The conjugate posterior is Gamma(alpha + sum(counts), beta + len(counts)). Return the posterior parameters as [shape, rate], or [0.0, 0.0] when alpha or beta is nonpositive or any count is negative.

Hint

Counts add to the shape and each observation adds one to the rate.

Test cases

case 1
in: [2,1,[3,4,5]]
expected: [14,4]
case 2
in: [0.5,0.5,[]]
expected: [0.5,0.5]
case 3
in: [1,2,[0,0]]
expected: [1,4]
case 4
in: [3,1,[2]]
expected: [5,2]
case 5
in: [-1,1,[1]]
expected: [0,0]
Starter codePython
def gamma_poisson_posterior_parameters(alpha, beta, counts):
    # Your code here
    pass

5 test cases · run your code against them in the editor