1. The Principle of Maximum Likelihood
In parameter estimation, we assume data $\mathbf{x} = (x_1, x_2, \dots, x_n)$ was generated by a probability distribution with unknown parameters $\theta \in \Theta$.
Maximum Likelihood Estimation (MLE) asks: Which parameter value $\theta$ makes the observed data most probable?
text
2. Mathematical Formalism: Likelihood & Log-Likelihood
For independent and identically distributed (i.i.d.) observations $x_1, x_2, \dots, x_n$ drawn from density $f(x; \theta)$:
$$L(\theta; \mathbf{x}) = \prod_{i=1}^n f(x_i; \theta)$$
2.1 The Log-Likelihood Function $\ell(\theta)$
Because multiplying hundreds of probabilities between $0$ and $1$ causes catastrophic floating-point underflow ($10^{-300} \to 0$), we take the natural logarithm:
$$\ell(\theta) = \ln L(\theta; \mathbf{x}) = \sum_{i=1}^n \ln f(x_i; \theta)$$
Because the natural logarithm is a strictly monotonically increasing function, the parameter that maximizes $\ell(\theta)$ is identical to the parameter that maximizes $L(\theta)$:
$$\hat{\theta}{\text{MLE}} = \arg\max{\theta \in \Theta} L(\theta; \mathbf{x}) = \arg\max_{\theta \in \Theta} \ell(\theta)$$
3. Step-by-Step Analytical Derivations
3.1 Gaussian (Normal) Distribution MLE
Let $x_1, \dots, x_n \sim \mathcal{N}(\mu, \sigma^2)$ where $\theta = (\mu, \sigma^2)$.
- Joint Density Product: $$L(\mu, \sigma^2; \mathbf{x}) = \prod_{i=1}^n \frac{1}{\sqrt{2\pi \sigma^2}} \exp\left( -\frac{(x_i - \mu)^2}{2\sigma^2} \right) = (2\pi \sigma^2)^{-n/2} \exp\left( -\frac{1}{2\sigma^2} \sum_{i=1}^n (x_i - \mu)^2 \right)$$
- Log-Likelihood: $$\ell(\mu, \sigma^2) = -\frac{n}{2} \ln(2\pi) - \frac{n}{2} \ln(\sigma^2) - \frac{1}{2\sigma^2} \sum_{i=1}^n (x_i - \mu)^2$$
- Optimizing $\mu$: $$\frac{\partial \ell}{\partial \mu} = \frac{1}{\sigma^2} \sum_{i=1}^n (x_i - \mu) = 0 \implies \sum_{i=1}^n x_i - n\mu = 0 \implies \hat{\mu}{\text{MLE}} = \frac{1}{n} \sum{i=1}^n x_i = \bar{x}$$
- Optimizing $\sigma^2$: Let $v = \sigma^2$. Differentiating with respect to $v$: $$\frac{\partial \ell}{\partial v} = -\frac{n}{2v} + \frac{1}{2v^2} \sum_{i=1}^n (x_i - \mu)^2 = 0$$ Multiplying by $2v^2$: $$-nv + \sum_{i=1}^n (x_i - \mu)^2 = 0 \implies \hat{\sigma}^2_{\text{MLE}} = \frac{1}{n} \sum_{i=1}^n (x_i - \hat{\mu})^2$$
Key Insight: The MLE estimator for variance is the naive estimator with denominator $n$. MLE estimators are not guaranteed to be unbiased in finite samples ($E[\hat{\sigma}^2_{\text{MLE}}] = \frac{n-1}{n}\sigma^2$), but they are asymptotically unbiased ($n \to \infty$).
3.2 Bernoulli Distribution MLE
For binary outcomes $x_i \in {0, 1}$ with success parameter $p$:
$$\ell(p) = \sum_{i=1}^n \left[ x_i \ln p + (1 - x_i) \ln(1 - p) \right] = \left(\sum_{i=1}^n x_i\right) \ln p + \left(n - \sum_{i=1}^n x_i\right) \ln(1 - p)$$
Setting derivative to zero:
$$\frac{d\ell}{dp} = \frac{\sum x_i}{p} - \frac{n - \sum x_i}{1 - p} = 0 \implies \hat{p}{\text{MLE}} = \frac{1}{n} \sum{i=1}^n x_i$$
The MLE is the empirical sample proportion.
4. The Score Function & Fisher Information
4.1 The Score Function $S(\theta)$
The gradient of the log-likelihood:
$$S(\theta) = \nabla_\theta \ell(\theta)$$
Fundamental Lemma: Expected Score is Always Zero
$$E_{\mathbf{x}}[S(\theta)] = \mathbf{0}$$
4.2 Fisher Information $I(\theta)$
Measures the amount of information that observed data carries about unknown parameter $\theta$. It is the curvature (negative Hessian) of the log-likelihood:
$$I(\theta) = - E\left[ \frac{\partial^2 \ell(\theta)}{\partial \theta^2} \right] = \text{Var}(S(\theta))$$
text
5. The Cramér-Rao Lower Bound (CRLB)
How accurate can an unbiased estimator possibly be? Is there a theoretical floor on variance?
Theorem (Cramér-Rao)
Let $\hat{\theta}$ be any unbiased estimator of $\theta$ ($E[\hat{\theta}] = \theta$). Then:
$$\text{Var}(\hat{\theta}) \ge \frac{1}{I_n(\theta)}$$
where $I_n(\theta) = n I_1(\theta)$ is the Fisher Information of $n$ i.i.d. observations.
An estimator that achieves the Cramér-Rao Lower Bound is called efficient.
6. Asymptotic Properties of MLE
Under standard regularity conditions, as sample size $n \to \infty$:
- Consistency: $\hat{\theta}_{\text{MLE}} \xrightarrow{P} \theta_0$ (converges to the true parameter).
- Asymptotic Normality: $$\sqrt{n}\left(\hat{\theta}_{\text{MLE}} - \theta_0\right) \xrightarrow{d} \mathcal{N}\left(0, I_1(\theta_0)^{-1}\right)$$
- Asymptotic Efficiency: The MLE achieves the Cramér-Rao Lower Bound asymptotically: $$\lim_{n \to \infty} n \text{Var}(\hat{\theta}_{\text{MLE}}) = \frac{1}{I_1(\theta_0)}$$
No other consistent estimator has lower asymptotic variance than the MLE!
7. Deep Learning Connection: Negative Log-Likelihood (NLL)
In deep learning, training a neural network with parameters $\mathbf{w}$ to classify images into classes $y \in {1, \dots, C}$ is framed as minimizing Cross-Entropy Loss:
$$\mathcal{L}(\mathbf{w}) = - \sum_{i=1}^n \ln P(y_i \mid \mathbf{x}_i; \mathbf{w}) = \text{Negative Log-Likelihood (NLL)}$$
Minimizing NLL using Stochastic Gradient Descent (SGD) is mathematically identical to finding the Maximum Likelihood Estimator of the network weights!
8. Python Implementation: Numerical MLE via SciPy
python
9. Key Takeaways
- Log-Likelihood Transforms Products into Sums: Maximizing $\ell(\theta) = \sum \ln f(x_i)$ prevents underflow and simplifies gradients.
- Fisher Information Governs Variance: Curvature of the log-likelihood dictates estimator precision; sharper curvature means lower variance.
- Cramér-Rao Optimality: MLE asymptotically achieves the theoretical minimum possible variance ($\text{Var} \to 1/I(\theta)$).