All problems
Dirichlet-Multinomial Posterior
Problem
A Dirichlet(alphas) prior over category probabilities is updated with observed category counts. The conjugate posterior keeps the same form with parameters alphas[i] + counts[i]. Return the updated concentration vector, or an empty list when the lengths differ, any alpha is nonpositive, or any count is negative.
Hint
The posterior concentration is the prior concentration plus the observed counts.
Test cases
case 1
in: [[1,2,3],[4,5,6]]
expected: [5,7,9]
case 2
in: [[0.5,0.5],[3,1]]
expected: [3.5,1.5]
case 3
in: [[1,1],[0,0]]
expected: [1,1]
case 4
in: [[1,2],[3]]
expected: []
case 5
in: [[0,1],[1,1]]
expected: []
Starter codePython
def dirichlet_multinomial_posterior(alphas, counts):
# Your code here
pass5 test cases · run your code against them in the editor