TITLE: Simple example of "Maximum A Posteriori"
QUESTION [6 upvotes]: I've been immersing myself into Bayesian statistics in school and I'm having a very difficult time grasping argmax and maximum a posteriori.  A quick explanation of this can be found: https://www.cs.utah.edu/~suyash/Dissertation_html/node8.html 
Basically theta is a set of parameters and x is the data, P of theta given x (posterior) equals P of x given theta (likelihood term) multiplied by P of theta (prior term) and all of that divided by P of x (to normalize).  Not sure exactly how dividing by P(x) normalizes this but thats not my main question.

Then, you maximize the posterior with argmax

I believe your maximizing the set of parameters to get the most likely posterior ... 
Can someone please give a simple example of this so I can visualize what is happening?

REPLY [4 votes]: Consider flipping fair coins. The outcome of a flip is described by
the random variable $C$ that can take on the values heads (h) and
tails (t). The probability of heads is $P(C=h) = 0.5$ and the
probability of tails is $P(C=t) = 1 - P(C=h)$. Consider also
flipping a biased coin whose probability of turning up heads is
$P(C=h) = 0.7$ and tails $P(C=t) = 1 - P(C=h) = 0.3$. We can easily
solve problems such as calculating the probability of getting three
tails in a row.
We can make the model more general by introducing a parameter k to
describe the probability of getting heads. We write that as
$P(C=h)=k$ and $P(C=t)=1-k$. The model becomes more complicated, but
we can now describe coins with any bias!
We can now ask questions like "Given a coin with bias $k$, what is the
probability of getting 2 heads and 3 tails?" The answer is:
$$
P(C=h)P(C=h)P(C=t)P(C=t)P(C=t)
$$
which simplifies to
$$
P(C=h)^2P(C=t)^3 = k^2(1-k)^3
$$
Using this we can calculate the maximum likelihood estimate (MLE)
of the parameter $k$ given the flips we have observed. How do we do
that? Remember calculus and the method for finding stationary points?
Yes! We derive the expression and set it equal to 0:
$$
D\, k^2(1-k)^3 = 2k(1-k)^3 - 3k^2(1-k) = 0
$$
Solving for $k$ yields $k = 0.4$. So according to the MLE the
probability of gettings heads is 40%.
That's it for the MLE. Now let's tackle the maximum a posteriori
estimate (MAP). To compute it we need to think about the parameter
$k$. The idea behind MAP is that we have some rough idea about how
biased our coin is. Then we flip it a few times and update our rough
idea.
Our "rough idea" is called the prior, the coin flips the
observations, and our "rough idea," after considering the
obvervations, the posterior.
The big epiphany that brings us from MLE to MAP is that the parameter
$k$ should be thought of as a random variable! At first it seems
strange to think of a probability as a random variable, but it makes
perfect sense after a while. A priori, we don't know how biased the
coin is but our hunch could be that it is biased in favor of heads.
We therefore introduce the random variable $K$ and say that its values
are drawn from the Beta distribution: $P(K=k) =
\mathrm{Beta_K}[a,b]$. This is out prior. We won't explain how the
Beta distribution works because it is beyond the scope of this
answer. It suffices to know that it is perfect for modeling the bias
of coins. For the distribution's parameters we choose $a=6$ and $b=2$
which corresponds to a coin that is heavily biased in favor of
heads. So $P(K=k) = \mathrm{Beta_K}[6,2]$.
To get the posterior from the prior, we simply multiply it with
the observations:
$$
P(K=k|C=\{3t, 2h\}) = P(C=h,C=h,C=t,C=t,C=t|K=k)P(K=k)
$$
We simplify the right hand side the same way as we did for the
expression for the MLE
$$
k^2(1-k)^3\mathrm{Beta_K}[6,2]
$$
Wikipedia
tells us how to expand out the Beta distribution:
$$
k^2(1-k)^3\frac{1}{B(6,2)}k^{6-1}(1-k)^{2-1} = \frac{1}{B(6,2)}k^7(1-k)^4
$$
Notice how similar the posterior is to the prior... Perhaps it can be
turned into a Beta distribution itself?! But to get the MAP we don't
need that. All that is left is deriving the above expression and
setting it to 0, exactly as we did when computing the MLE:
$$
D\,k^7(1-k)^4 = 7k^6(1-k)^4 - 4k^7(1-k)^3 = 0
$$
The $\frac{1}{B(6,2)}$ factor is omitted because it is non-zero and
constant so it won't affect the maximum.
Solving for $k$ yields $k = 7/11$. So according to the MAP the
probability of gettings heads is about 64%.
TL;DR I think two things confused you. First, the argmax
syntax. My method of deriving to find the maximum of the parameter
analytically works in this example, but many times it doesn't. Then you
have to use other methods to find or approximate it.
Second, not only events but the parameters themselves can be thought
of as random variables drawn from fitting distributions. You are
uncertain of the outcome, whether a coin will land heads or tails, but
you are also uncertain of the coins fairness. That is a "higher level
of uncertainity" which is hard to grasp in the beginning.