Maximum A Posteriori (MAP) Estimation

 

📘 Maximum A Posteriori (MAP) Estimation

🔹 Definition

MAP estimation is a method for estimating model parameters by maximizing the posterior probability of the parameters given the observed data.

👉 In simple terms:
It finds parameters that are most probable after considering both data and prior knowledge.


🔹 Mathematical Formulation

Using Bayes’ theorem:

P(θD)=P(Dθ)P(θ)P(D)P(\theta\mid D)=\frac{P(D\mid \theta)P(\theta)}{P(D)}

👉 MAP estimate:

θ^MAP=argmaxθP(θD)\hat{\theta}_{MAP} = \arg\max_{\theta} P(\theta \mid D)

🔹Simplified Optimization Form

Since P(D)P(D) is constant:

θ^MAP=argmaxθP(Dθ)P(θ)\hat{\theta}_{MAP} = \arg\max_{\theta} P(D \mid \theta) \cdot P(\theta)

Taking log:

θ^MAP=argmaxθ[logP(Dθ)+logP(θ)]\hat{\theta}_{MAP} = \arg\max_{\theta} \left[ \log P(D \mid \theta) + \log P(\theta) \right]


🔹  Interpretation

MAP combines:

  • Likelihood → how well model fits data
  • Prior → what we believe before seeing data

👉 Final estimate balances both.


🔹 Intuition

👉 MAP answers:

“What is the most probable parameter value given both prior knowledge and observed data?”


📌 Real-life Analogy:

  • A doctor has prior knowledge about disease prevalence
  • Observes symptoms (data)
  • Updates belief accordingly

🔹 Difference Between MLE and MAP

FeatureMLEMAP
Uses prior        ❌ No        ✅ Yes
Objective        Maximize likelihood        Maximize posterior
Overfitting        More likely        Reduced
Data requirement        High        Can work with less data

🔹 Example: Bernoulli Distribution with Prior

📌 Problem:

  • Data: coin tosses
  • Prior belief: pBeta(α,β)

Likelihood:

P(Dp)=pk(1p)nkP(D \mid p) = p^k (1-p)^{n-k}

Prior:

P(p)=pα1(1p)β1P(p) = p^{\alpha-1}(1-p)^{\beta-1}

Posterior:

P(pD)pk+α1(1p)nk+β1P(p \mid D) \propto p^{k+\alpha-1}(1-p)^{n-k+\beta-1}


MAP Estimate:


Beta Distribution

The probability density function (PDF) of Beta distribution is:

f(p)=pα1(1p)β1,0<p<1f(p) = p^{\alpha - 1}(1 - p)^{\beta - 1}, \quad 0 < p < 1

Where:

  • α>0\alpha > 0, β>0\beta > 0

👉 Why Beta?

  • Conjugate prior for Bernoulli
  • Simplifies computation 

Goal

👉 Find the mode, i.e., the value of pp that maximizes f(p)f(p).

Take Log (Simplification Step)

Instead of maximizing f(p)f(p), maximize log:

(p)=logf(p)\ell(p) = \log f(p)(p)=(α1)logp+(β1)log(1p)\ell(p) = (\alpha - 1)\log p + (\beta - 1)\log(1 - p)

Differentiate w.r.t. pp

ddp=α1pβ11p\frac{d\ell}{dp} = \frac{\alpha - 1}{p} - \frac{\beta - 1}{1 - p}

Set Derivative = 0

Solve for pp

Cross-multiply:

Expand:

(α1)(α1)p=(β1)p(\alpha - 1) - (\alpha - 1)p = (\beta - 1)p

Rearrange:

α1=(α1)p+(β1)p\alpha - 1 = (\alpha - 1)p + (\beta - 1)p
α1=p[(α1)+(β1)]\alpha - 1 = p[(\alpha - 1) + (\beta - 1)]


Final Step:

p=α1α+β2p = \frac{\alpha - 1}{\alpha + \beta - 2}

p^=k+α1n+α+β2\hat{p} = \frac{k + \alpha - 1}{n + \alpha + \beta - 2}

📌 Special Case:

  • If α=1,β=1\alpha = 1, \beta = 1 (uniform prior):

👉 MAP = MLE


🔹Example: Gaussian Prior

 MAP Estimation of Mean (Gaussian Likelihood + Gaussian Prior)

🔹 Problem Setup

Assume:

  • Data: x1,x2,...,xnx_1, x_2, ..., x_n
  • Each xiN(μ,σ2)x_i \sim \mathcal{N}(\mu, \sigma^2)

👉 Known:

  • Variance σ2\sigma^2

👉 Unknown:

  • Mean μ\mu

🔹  Likelihood Function

P(Dμ)=i=1nN(xiμ,σ2)P(D \mid \mu) = \prod_{i=1}^{n} \mathcal{N}(x_i \mid \mu, \sigma^2)
exp(12σ2i=1n(xiμ)2)\propto \exp\left(-\frac{1}{2\sigma^2}\sum_{i=1}^{n}(x_i - \mu)^2\right)

🔹 Prior Distribution (Gaussian Prior)

Assume:

μN(μ0,τ2)\mu \sim \mathcal{N}(\mu_0, \tau^2)

👉 Prior:

P(μ)exp(12τ2(μμ0)2)P(\mu) \propto \exp\left(-\frac{1}{2\tau^2}(\mu - \mu_0)^2\right)

🔹 Posterior Distribution

Using Bayes’ theorem:

P(μD)P(Dμ)P(μ)P(\mu \mid D) \propto P(D \mid \mu)\,P(\mu)
exp(12σ2(xiμ)2)exp(12τ2(μμ0)2)\propto \exp\left(-\frac{1}{2\sigma^2}\sum (x_i - \mu)^2\right) \cdot \exp\left(-\frac{1}{2\tau^2}(\mu - \mu_0)^2\right)

🔹 Log-Posterior

logP(μD)=12σ2(xiμ)212τ2(μμ0)2\log P(\mu \mid D) = -\frac{1}{2\sigma^2}\sum (x_i - \mu)^2 -\frac{1}{2\tau^2}(\mu - \mu_0)^2

🔹 MAP Objective

Maximize posterior
👉 Equivalent to minimizing:

(xiμ)2+λ(μμ0)2\sum (x_i - \mu)^2 + \lambda (\mu - \mu_0)^2

where:

λ=σ2τ2\lambda = \frac{\sigma^2}{\tau^2}

🔹 Differentiate w.r.t. μ\mu

Expand derivative:

ddμ[(xiμ)2+λ(μμ0)2]=0\frac{d}{d\mu} \left[ \sum (x_i - \mu)^2 + \lambda (\mu - \mu_0)^2 \right] = 0

Step-by-step:

ddμ(xiμ)2=2(xiμ)\frac{d}{d\mu} \sum (x_i - \mu)^2 = -2\sum (x_i - \mu)
ddμλ(μμ0)2=2λ(μμ0)\frac{d}{d\mu} \lambda (\mu - \mu_0)^2 = 2\lambda (\mu - \mu_0)

🔹Set derivative = 0

2(xiμ)+2λ(μμ0)=0-2\sum (x_i - \mu) + 2\lambda (\mu - \mu_0) = 0

Divide by 2:

(xiμ)+λ(μμ0)=0-\sum (x_i - \mu) + \lambda (\mu - \mu_0) = 0

🔹 Simplify

xinμ+λμλμ0=0\sum x_i - n\mu + \lambda \mu - \lambda \mu_0 = 0

🔹 Solve for μ



nμ+λμ=xi+λμ0n\mu + \lambda \mu = \sum x_i + \lambda \mu_0 μ(n+λ)=xi+λμ0\mu (n + \lambda) = \sum x_i + \lambda \mu_0

Final Result

μ^MAP=xi+λμ0n+λ\hat{\mu}_{MAP} = \frac{\sum x_i + \lambda \mu_0}{n + \lambda}

🔹 Alternative Form (Important)

Let:

xˉ=1nxi\bar{x} = \frac{1}{n}\sum x_i

Then:

μ^MAP=nxˉ+λμ0n+λ\hat{\mu}_{MAP} = \frac{n\bar{x} + \lambda \mu_0}{n + \lambda}

🔹 Interpretation

👉 MAP estimate is a weighted average:

  • Data mean xˉ\bar{x}
  • Prior mean μ0\mu_0

🔹  Intuition

  • If more data → rely on xˉ\bar{x}
  • If strong prior → rely on μ0\mu_0

🔹 Special Cases

📌 Case 1: No Prior (Flat Prior)

If λ=0\lambda = 0:

μ^=xˉ\hat{\mu} = \bar{x}

👉 MAP = MLE


📌 Case 2: Strong Prior

If λ\lambda is large:

μ^μ0\hat{\mu} \approx \mu_0

🔹 15. Key Insight

MAP = compromise between data and prior knowledge


📝 Summary (Quick Revision)

  • Likelihood → Gaussian
  • Prior → Gaussian
  • Posterior → Gaussian

Final Answer:

μ^=nxˉ+λμ0n+λ\hat{\mu} = \frac{n\bar{x} + \lambda \mu_0}{n + \lambda}

🔹Advantages of MAP

  • Incorporates prior knowledge
  • Reduces overfitting
  • Works well with small datasets
  • More robust than MLE

🔹Disadvantages

  • Requires prior selection
  • Wrong prior → poor results
  • More computationally complex

🔹 Applications

  • Bayesian Machine Learning
  • Regularized regression (Ridge, Lasso)
  • Naive Bayes classifier
  • Neural networks (weight regularization)

🔹 Key Concepts 

📌 Prior Distribution

  • Encodes initial belief

📌 Posterior Distribution

  • Updated belief after data

📌 Conjugate Priors

  • Makes computation easier
  • Example:
    • Bernoulli ↔ Beta
    • Gaussian ↔ Gaussian

📝 Summary 

  • MAP maximizes posterior probability
  • Combines:
    • Likelihood
    • Prior
  • Formula:
θ^=argmaxP(Dθ)P(θ)\hat{\theta} = \arg\max P(D \mid \theta)P(\theta)
  • More robust than MLE

Comments

Popular posts from this blog

Machine Learning PCCST503 Semester5 KTU CS 2024 Scheme - Dr Binu V P

Introduction to Machine Learning (ML)

Distinguishing Machine Learning from Traditional Programming