Numerical Problems MLE and MAP

 

๐Ÿ“˜ Numerical Problem: Binomial + Beta (MLE & MAP)

๐Ÿ“ Problem

A coin is tossed 10 times, and the number of heads observed is 7.

Assume:

  • XBinomial(n=10,p)X \sim \text{Binomial}(n=10, p)

Tasks:

  1. Find the MLE estimate of pp
  2. Assume prior: pBeta(ฮฑ=2,  ฮฒ=2)p \sim \text{Beta}(\alpha = 2,\; \beta = 2)
    Find the MAP estimate of pp
  3. Compare the results

✅ Step 1: MLE Estimate

For Binomial distribution:

p^MLE=kn\hat{p}_{MLE} = \frac{k}{n}

Where:

  • k=7k = 7n=10n = 10
p^MLE=710=0.7\hat{p}_{MLE} = \frac{7}{10} = 0.7

Var^=p^(1p^)=0.7*0.3=0.21\widehat{\text{Var}} = \hat{p}(1 - \hat{p})

✅ Step 2: MAP Estimate

๐Ÿ”น Formula (Very Important)

p^MAP=k+ฮฑ1n+ฮฑ+ฮฒ2\hat{p}_{MAP} = \frac{k + \alpha - 1}{n + \alpha + \beta - 2}

๐Ÿ”น Substitute values

  • k=7k = 7
  • n=10n = 10
  • ฮฑ=2\alpha = 2, ฮฒ=2\beta = 2
p^MAP=7+2110+2+22=812=0.667\hat{p}_{MAP} = \frac{7 + 2 - 1}{10 + 2 + 2 - 2} = \frac{8}{12} = 0.667

✅ Final Answers

Method    Estimate
MLE    0.7
MAP    0.667

๐Ÿ”ฅ Key Insight

MAP = MLE + Prior influence


๐Ÿ“Œ Modified Problem (Stronger Prior Effect)

Suppose:

  • ฮฑ=10,  ฮฒ=10\alpha = 10,\; \beta = 10

๐Ÿ”น Recompute MAP

p^MAP=7+10110+10+102=16280.571\hat{p}_{MAP} = \frac{7 + 10 - 1}{10 + 10 + 10 - 2} = \frac{16}{28} \approx 0.571

๐Ÿ”ฅ Comparison

Method    Value
MLE    0.7
MAP (weak prior)    0.667
MAP (strong prior)    0.571

๐Ÿ”น Insight

  • Strong prior → more influence
  • Estimate moves closer to 0.5

๐Ÿ“ Summary (Exam Ready)

  • MLE:
p^=kn\hat{p} = \frac{k}{n}
  • MAP:
p^=k+ฮฑ1n+ฮฑ+ฮฒ2\hat{p} = \frac{k + \alpha - 1}{n + \alpha + \beta - 2}

✅ Practice Question (Try Yourself)

A machine produces defective items. Out of 20 items, 6 are defective.

  • Find MLE of defect probability
  • Assume prior Beta(3,3)\text{Beta}(3,3), find MAP

๐Ÿ“˜ Numerical Problem: MLE vs MAP (Gaussian Mean)

๐Ÿ“ Problem

Given data:

x={2,  4,  6,  8}x = \{2,\;4,\;6,\;8\}

Assume:

  • Data follows N(ฮผ,ฯƒ2)\mathcal{N}(\mu, \sigma^2)
  • Variance ฯƒ2=4\sigma^2 = 4 (known)

Also given prior:

  • ฮผN(ฮผ0=5,  ฯ„2=1)

๐Ÿ”น Tasks

  1. Find MLE estimate of ฮผ\mu
  2. Find MAP estimate of ฮผ\mu
  3. Compare both results

✅ Step 1: Compute Sample Mean (MLE)

ฮผ^MLE=1nxi\hat{\mu}_{MLE} = \frac{1}{n}\sum x_i =2+4+6+84=204=5= \frac{2+4+6+8}{4} = \frac{20}{4} = 5

๐Ÿ‘‰ MLE = 5


✅ Step 2: Compute MAP Estimate

Formula:

ฮผ^MAP=nxห‰+ฮปฮผ0n+ฮป\hat{\mu}_{MAP} = \frac{n\bar{x} + \lambda \mu_0}{n + \lambda}

where:

ฮป=ฯƒ2ฯ„2\lambda = \frac{\sigma^2}{\tau^2}

๐Ÿ”น Calculate ฮป\lambda

ฮป=41=4\lambda = \frac{4}{1} = 4

๐Ÿ”น Substitute values

  • n=4n = 4
  • xห‰=5\bar{x} = 5
  • ฮผ0=5\mu_0 = 5
ฮผ^MAP=45+454+4=20+208=408=5\hat{\mu}_{MAP} = \frac{4 \cdot 5 + 4 \cdot 5}{4 + 4} = \frac{20 + 20}{8} = \frac{40}{8} = 5

✅ Final Answers

Method    Estimate
MLE    5
MAP    5

๐Ÿ”น  Interpretation

๐Ÿ‘‰ Both are same because:

  • Prior mean = data mean
  • No conflict between data and prior

๐Ÿ“Œ Modified Problem (More Interesting)

Let’s slightly change prior:

  • ฮผ0=0\mu_0 = 0 (strong prior away from data)

๐Ÿ”น Recompute MAP

ฮผ^MAP=45+408=208=2.5\hat{\mu}_{MAP} = \frac{4 \cdot 5 + 4 \cdot 0}{8} = \frac{20}{8} = 2.5

๐Ÿ”ฅ Comparison

Method    Value
MLE    5
MAP    2.5

๐Ÿ”น Insight

  • MLE depends only on data
  • MAP is pulled toward prior

๐Ÿ‘‰ This is called shrinkage effect


๐Ÿ“ Summary (Exam Ready)

  • MLE:
ฮผ^=xห‰\hat{\mu} = \bar{x}
  • MAP:
ฮผ^=nxห‰+ฮปฮผ0n+ฮป\hat{\mu} = \frac{n\bar{x} + \lambda \mu_0}{n + \lambda}

✅ Practice Question (Try Yourself)

Given:

  • Data: 3,5,7
  • ฯƒ2=1, ฯ„2=1, ฮผ0=0

๐Ÿ‘‰ Find MLE and MAP

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