Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-295

MAP with Beta Prior

Problem

For a Bernoulli parameter with a Beta(alpha, beta) prior, the maximum a posteriori estimate after successes successes in trials trials is (alpha + successes - 1) / (alpha + beta + trials - 2). Return 0.5 when the denominator is zero and 0.0 for invalid arguments.

Hint

The Beta MAP behaves like the MLE after subtracting one pseudo-count from each prior parameter.

Test cases

case 1
in: [2,3,5,10]
expected: 0.46153846153846156
case 2
in: [1,1,3,10]
expected: 0.3
case 3
in: [1,1,0,0]
expected: 0.5
case 4
in: [3,2,0,4]
expected: 0.2857142857142857
case 5
in: [0,1,1,1]
expected: 0
Starter codePython
def beta_map_estimate(alpha, beta, successes, trials):
    # Your code here
    pass

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