MLE & MAP estimation

Why loss functions exist — deriving them from probability

Why

MLE and MAP are the theoretical frameworks that explain why we minimise the losses we do. Most engineers use MSE and cross-entropy every day without knowing why — but understanding that they are maximum likelihood estimators is what separates someone who reasons from first principles from someone who follows recipes.

They also explain regularisation from a Bayesian perspective — L2 regularisation is exactly MAP estimation with a Gaussian prior.

Intuition

MLE asks: "What parameters make the data I observed most probable?" You find the parameters that best explain the data, with no assumptions about what the parameters should look like beforehand.

MAP asks the same question but with a twist: "What parameters make the data most probable, while also being themselves plausible given my prior beliefs?" It's MLE plus a prior — a regularised version of MLE that prevents extreme parameter values.

Explanation
Maximum Likelihood Estimation (MLE)

Given observed data D = {x₁, x₂, ..., xₙ} and a model with parameters θ, MLE finds the θ that maximises the probability of observing D:

θ_MLE = argmax_θ P(D | θ) = argmax_θ Π P(xᴵ | θ) (assuming i.i.d. samples)

In practice: take the log (monotonic, doesn't change argmax):

θ_MLE = argmax_θ log P(D | θ) = argmax_θ Σ log P(xᴵ | θ) Why log? Products of many small probabilities underflow to zero numerically. Log converts the product to a sum — stable and easier to differentiate.
MLE → MSE loss (linear regression derivation)

Assume: outputs = true value + Gaussian noise: y = θᵀx + ε, where ε ~ N(0, σ²)

P(yᴵ | xᴵ, θ) = N(θᵀxᴵ, σ²) log P(D|θ) = Σ [ -½log(2πσ²) - (yᴵ - θᵀxᴵ)² / (2σ²) ] Maximising log P(D|θ) w.r.t. θ ≡ minimising Σ(yᴵ - θᵀxᴵ)² ≡ minimising MSE loss ✓

The Gaussian noise assumption directly gives you MSE. It's not arbitrary — it's the statistically correct loss for Gaussian-distributed outputs.

MLE → Cross-entropy loss (logistic regression derivation)

Assume: outputs follow a Bernoulli distribution with p = σ(θᵀx)

P(yᴵ | xᴵ, θ) = σ(θᵀxᴵ)^yᴵ · (1 - σ(θᵀxᴵ))^(1-yᴵ) log P(D|θ) = Σ [ yᴵ·log(σ(θᵀxᴵ)) + (1-yᴵ)·log(1-σ(θᵀxᴵ)) ] Maximising log P(D|θ) ≡ minimising Binary Cross-Entropy: BCE = -Σ [ yᴵ·log(ŷᴵ) + (1-yᴵ)·log(1-ŷᴵ) ] ✓

The Bernoulli assumption directly gives binary cross-entropy. Extend to K classes with Categorical → get categorical cross-entropy.

Maximum A Posteriori (MAP) — MLE + prior

MAP adds a prior P(θ) — your belief about plausible parameter values before seeing data:

θ_MAP = argmax_θ P(θ | D) = argmax_θ P(D | θ) · P(θ) [by Bayes, ignoring P(D) constant] In log form: θ_MAP = argmax_θ [ log P(D|θ) + log P(θ) ] ↑ ↑ likelihood regulariser

The extra term log P(θ) acts as a regulariser — it penalises parameter values that are improbable under the prior.

L2 regularisation = MAP with Gaussian prior
If prior is Gaussian: P(θ) = N(0, σ²) log P(θ) = -θ² / (2σ²) + constant MAP objective: argmax_θ [ log P(D|θ) - θ²/(2σ²) ] ≡ argmin_θ [ NLL(D, θ) + λ·||θ||² ] where λ = 1/(2σ²) This is exactly L2 regularisation (Ridge / weight decay). ✓ Analogously: L1 regularisation = MAP with Laplace prior.

Regularisation is not an ad hoc trick — L2 (prefer small weights) corresponds to believing weights are normally distributed around zero before seeing any data. The strength λ is the inverse of the prior's variance — a tight prior (small σ²) gives strong regularisation.

MLE
No prior. Pure data — finds parameters that make the observed data most probable. Can overfit with little data. MSE and cross-entropy are both MLE objectives.
MAP
Prior + data. Regularised MLE. Gaussian prior → L2 regularisation. Laplace prior → L1. Always more conservative than MLE when data is scarce.