All formulas

Probability distributions

Multivariate normal log density

prob.multivariate-normal-logpdfAlso called multivariate normal logpdf, mvn logpdf, gaussian log likelihood, multivariate gaussian log density

ln⁡p(x)=−12((x−μ)⊤Σ−1(x−μ)+ln⁡det⁡Σ+dln⁡(2π))\ln p(x) = -\frac{1}{2}\left((x - \mu)^\top \Sigma^{-1} (x - \mu) + \ln\det\Sigma + d\ln(2\pi)\right)

Natural log of the density of a d-dimensional normal distribution with mean μ and covariance Σ.

Notation

xx

the point

x ∈ ℝd

μ\mu

mean vector

μ ∈ ℝd

Σ\Sigma

covariance matrix, symmetric positive definite

Σ ∈ ℝd×d, symmetric positive definite

dd

dimension

Size, at least 1

ln⁡p(x)\ln p(x)

Result: the log density at x

scalar

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    x=[1],μ=[0],Σ=[[1]]x = [1], \mu = [0], \Sigma = \left[\left[1\right]\right]

    Result

    ln⁡p(x)=−log⁡(2π)2−12\displaystyle \ln p(x) = - \frac{\log{\left(2 \pi \right)}}{2} - \frac{1}{2}

    ≈ -1.4189385332

  2. Given

    x=[1,2],μ=[0,0],Σ=[[2,0],[0,1]]x = [1, 2], \mu = [0, 0], \Sigma = \left[\left[2, 0\right], \left[0, 1\right]\right]

    Result

    ln⁡p(x)=−94−log⁡(2π)−log⁡(2)2\displaystyle \ln p(x) = - \frac{9}{4} - \log{\left(2 \pi \right)} - \frac{\log{\left(2 \right)}}{2}

    ≈ -4.43445065669

  3. Given

    x=[1,0],μ=[0,0],Σ=[[2,1],[1,2]]x = [1, 0], \mu = [0, 0], \Sigma = \left[\left[2, 1\right], \left[1, 2\right]\right]

    Result

    ln⁡p(x)=−log⁡(2π)−log⁡(3)2−13\displaystyle \ln p(x) = - \log{\left(2 \pi \right)} - \frac{\log{\left(3 \right)}}{2} - \frac{1}{3}

    ≈ -2.72051654408

  4. Given

    x=[2,1],μ=[1,1],Σ=[[1,0],[0,4]]x = [2, 1], \mu = [1, 1], \Sigma = \left[\left[1, 0\right], \left[0, 4\right]\right]

    Result

    ln⁡p(x)=−log⁡(2π)−log⁡(2)−12\displaystyle \ln p(x) = - \log{\left(2 \pi \right)} - \log{\left(2 \right)} - \frac{1}{2}

    ≈ -3.03102424697

Common mistakes

  • Uses Σ where Σ−1 belongs

    The quadratic form multiplies by the covariance instead of its inverse.

    Fix: Solve Σv = (x − μ) and use (x − μ)Tv.

  • Omits the ln det Σ term

    The normalizing term −½ ln det Σ is missing.

    Fix: Subtract ½ ln det Σ.

  • Subtracts ln det Σ without the factor ½

    The determinant term is doubled, as when ln det of a Cholesky factor is confused with ln det Σ.

    Fix: Subtract ½ ln det Σ, which equals the sum of ln Lii for the Cholesky factor L.

Sources

  • Bishop 2006

    Bishop, Christopher M. Pattern Recognition and Machine Learning. Springer, 2006.

  • Murphy 2022

    Murphy, Kevin P. Probabilistic Machine Learning: An Introduction. MIT Press, 2022.