Note

Maximum likelihood notes

· Updated May 2, 2026

This is a public fixture post (PUBLIC_KATEX_FIXTURE) used to check KaTeX, code overflow, and public-build inclusion.

Let x1,,xnRdx_1,\ldots,x_n \in \R^d be i.i.d. samples from N(μ,σ2I)\mathcal{N}(\mu,\sigma^2 I). The negative log-likelihood is

(μ,σ2)=nd2log(2πσ2)+12σ2i=1nxiμ2.\ell(\mu,\sigma^2) = \frac{nd}{2}\log(2\pi\sigma^2) + \frac{1}{2\sigma^2}\sum_{i=1}^n \norm{x_i - \mu}^2.

The MLE is the usual mean, μ^=arg maxμE[logpμ(x)]\hat\mu = \argmax_{\mu} \E[\log p_\mu(x)], which here reduces to μ^=n1ixi\hat\mu = n^{-1}\sum_i x_i. For two densities pp and qq, the gap between them is the KL divergence KL(pq)\kl(p\|q).

A useful scalar identity in one dimension is Var[X]=E[X2]E[X]2\Var[X] = \E[X^2] - \E[X]^2, with P(XA)=E[1A(X)]\P(X \in A) = \E[\ind_{A}(X)].

import numpy as np

def gaussian_nll(x, mu, sigma2):
    residual = x - mu
    return 0.5 * (np.log(2 * np.pi * sigma2) + (residual ** 2) / sigma2)

KaTeX is not TeX Live: macros such as \R and \norm are defined in src/lib/katex_macros.ts. Diagrams that need TikZ should be pre-rendered.