Premium problem122. MAP Estimate With a Beta Prior

Medium Locked

With a Beta(α,β)\mathrm{Beta}(\alpha, \beta) prior and observed heads and tails, return the MAP estimate of the success probability.

p^MAP=heads+α−1heads+tails+α+β−2\hat{p}_{\text{MAP}} = \frac{\text{heads} + \alpha - 1}{\text{heads} + \text{tails} + \alpha + \beta - 2}

The prior acts as pseudo-counts. With α=β=1\alpha = \beta = 1 it is flat and the MAP collapses to the MLE, which is why that choice is the "no opinion" prior.

Input

alpha = 2.0
beta = 2.0
heads = 7
tails = 3

Output

0.6666666666666666

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)