MLEs and MAPs

Joseph E. Gonzalez

Is it Learning...

In class we considered the problem of flipping a thumbtack.  Let's put some of the magic back into learning by playing a simple game.  I will place a coin in either my left or right hand.  If you guess the correct hand you get the coin.

Suppose you were designing a robot to play this game.  You would want it to learn which hand I favor.  If I charge you to play, you may also want to learn how much I favor one hand over the other. If we assume that my current choice of hand is independent of previous hand choices, you would likely want to solve the thumbtack problem discussed in class.

From time to time I will try to compose a Mathematica demonstration notebook for you to play with the graphs and concepts presented in class.

Likelihood

The following demonstration shows the plot of the data likelihood function with respect to the value of the parameter θ for different values of the data D={(Subscript[α, H]),(Subscript[α, T])}

n=20;
Manipulate[
Plot[(θ^h) (((1-θ))^t),{θ,0,1},AxesLabel-> {"θ","P(D|θ)"},PlotLabel->"((Subscript[α, H])="<>ToString[h]<>", (Subscript[α, T])=" <> ToString[t]<>")"],
{{h,3,"(Subscript[α, H])"},0,n,1},{{t,3,"(Subscript[α, T])"},0,n,1}]

Beta Distribution

In class we also introduced the Beta distribution which is the conjugate prior of the Bernoulli distribution.  Alternatively, if we treat the parameter θ as a random variable, then we typically assume that θ is drawn from a Beta distribution.  The Beta distribution is itself parameterized by two values (Subscript[β, H]) and (Subscript[β, T]).

Manipulate[
Plot[PDF[BetaDistribution[α,β],θ],{θ,0,1},AxesLabel-> {"θ","p(θ)"}, PlotRange->{{0,1},{0,Automatic}},
PlotLabel -> "((Subscript[β, H])="<>ToString[α]<>", (Subscript[β, T])="<>ToString[β]<>")"],
{{α,1,"(Subscript[β, H])"},0,4},{{β,1,"(Subscript[β, T])"},0,4}]

Being Bayesian

If we use a Beta((Subscript[β, H]),(Subscript[β, T])) prior on θ then we obtain the new likelihood.  The red line is proportional to the likelihood P(D|θ) used to compute the MLE and the blue line is proportional to the bayesian posterior P(θ|D) used to compute the MAP.

n=20;
Manipulate[
GraphicsGrid[{{
Plot[PDF[BetaDistribution[u,v],θ],{θ,0,1},AxesLabel-> {"θ","p(θ)"}, PlotRange->{{0,1},{0,Automatic}},
PlotLabel -> "Prior:((Subscript[β, H])="<>ToString[u]<>", (Subscript[β, T])="<>ToString[v]<>")"],
Plot[{(1/(((((h/(h+t))))^h) (((1-(h/(h+t))))^t)))(θ^h) (((1-θ))^t),
((PDF[BetaDistribution[u + h,v + t],θ])/(PDF[BetaDistribution[u + h,v + t],((h+u-1)/(h+u+t+v-2))]))},
{θ,0,1},
AxesLabel-> {"θ","∝P(θ|D),∝P(D|θ)"},PlotStyle-> {{Red,Thickness[.01]}, {Blue,Thickness[.01]}}, PlotLabel->"((Subscript[α, H])="<>ToString[h]<>", (Subscript[α, T])=" <> ToString[t]<>")",
PlotRange-> {{0,1},{0,1}}]}
}],
{{h,3,"(Subscript[α, H])"},0,n,1},{{t,3,"(Subscript[α, T])"},0,n,1},
{{u,1,"(Subscript[β, H])"},0,4},{{v,1,"(Subscript[β, T])"},0,4}]
Print["Red is MLE, Blue is Bayesian"]