Compute the maximum a posteriori (MAP) estimate of a Bernoulli probability under a Beta(a,b) prior, given 0/1 observations.
Implement solve(x, a, b).
Returns. Return a float. The posterior mode is only interior when both posterior parameters exceed 1; use a,b≥1. Observations must be 0/1 and a,b≥1, otherwise ValueError is raised; with a=b=1 and no observations every value is equally likely, so that case raises ValueError too.
Example 1
Input:
solve([1, 1, 0, 1], 2.0, 2.0)
Output:
0.666667
Example 2
Input:
solve([0, 0], 2.0, 2.0)
Output:
0.25
No results yet
Run your code to check it against the examples, or submit to run every test.