Distributions and Maximum Likelihood

W02 · Part 1 — see it, sample it, fit it, sample from the fit

Uma Satyaranjan · Soma S Dhavala

Invalid Date

Where we are

  • W01: a generative model produces samples — and we saw a complete one on two data points
  • The loop of this module: distribution → samples → fitted distribution → new samples
  • Today we make the word fit precise: maximum likelihood

Tomorrow: KL divergence (how wrong is a fit?). Then: empirical risk minimization.

The cast of distributions

Family Support Knobs Natural habitat
Uniform(a,b)\mathrm{Uniform}(a,b) [a,b][a,b] endpoints total ignorance on an interval
𝒩(μ,σ2)\mathcal{N}(\mu,\sigma^2) ℝ\mathbb{R} center, width noise, sums of small effects
Gamma(k,θ)\mathrm{Gamma}(k,\theta) (0,∞)(0,\infty) shape, scale waiting times, positive skew
Beta(α,β)\mathrm{Beta}(\alpha,\beta) (0,1)(0,1) two shapes proportions, probabilities
Mixture ℝ\mathbb{R} weights + components multimodal data — clusters

Five shapes cover most of what this course needs — and the mixture is the star of the semester.

Playground: see it, sample it, fit it

What the histogram is telling you

  • Density-normalized histogram → as nn grows it hugs the pdf: samples carry the distribution
  • n=30n = 30 is ragged, n=3000n = 3000 is faithful — estimation error shrinks like 1/n1/\sqrt{n} (Module 1 will say this properly)
  • Fitting = choosing the family member that makes the observed samples most probable

PDF vs likelihood — the confusion, dissolved

One function, two readings

f(x;θ)f(x; \theta)

Fix Vary You get Area under curve
parameters θ\theta data xx pdf — a distribution over data =1=1, always
observed data xx parameters θ\theta likelihood — a score for fitting meaningless

The likelihood is not a probability distribution over θ\theta. Only its argmax — and its shape near the argmax — carries information.

Likelihood of a dataset

Independent observations multiply; logs turn products into sums:

L(θ)=∏if(xi;θ)⇒ℓ(θ)=∑ilogf(xi;θ)L(\theta) = \prod_{i} f(x_i; \theta) \qquad\Longrightarrow\qquad \ell(\theta) = \sum_{i} \log f(x_i; \theta)

  • The log changes nothing about where the maximum is (log is monotone)
  • …and everything about how pleasant the algebra is
  • Numerically: products of 3000 small numbers underflow; sums of logs do not

To the board: the Gaussian MLE

Maximize

ℓ(μ,σ2)=−n2log(2πσ2)−12σ2∑i(xi−μ)2\ell(\mu,\sigma^2) = -\frac{n}{2}\log(2\pi\sigma^2) - \frac{1}{2\sigma^2}\sum_i (x_i-\mu)^2

  • ∂ℓ/∂μ=0⟹μ̂=x‾\partial\ell/\partial\mu = 0 \implies \hat\mu = \bar x (the sample mean — for every σ\sigma)
  • ∂ℓ/∂σ2=0⟹σ̂2=1n∑i(xi−x‾)2\partial\ell/\partial\sigma^2 = 0 \implies \hat\sigma^2 = \frac{1}{n}\sum_i (x_i - \bar x)^2

Derivation on the board now — it is tonight’s Exercise if you want to redo it alone. Note the divisor nn, not n−1n-1: the MLE is (slightly) biased.

Honesty about the other families

Family How we fit it Why
Normal maximum likelihood closed form — you just derived it
Uniform maximum likelihood closed form: â=min\hat a = \min, b̂=max\hat b = \max (cute proof — exercise)
Gamma method of moments MLE has no closed form: match x‾\bar x and s2s^2 instead
Beta method of moments same story
Mixture …? stay tuned — this one needs real machinery (EM, later)

Method of moments: set the family’s mean and variance equal to the sample’s. Simple, honest, and a good estimator to know by itself.

The trap: right method, wrong family

  • In the playground: mixture data, 3000 samples, press Fit
  • The single best Normal — by maximum likelihood, done perfectly — puts its peak where the data is emptiest
  • Fitting well within the wrong family is still wrong

Needed: a way to measure the gap between the data distribution and the model. That measure is KL divergence — tomorrow.

The pdf and the likelihood are the same curve — you just walk along it in different directions.

Tonight: derive σ̂2\hat\sigma^2, prove Uniform’s MLE is (min, max), and play the mixture trap yourself.