Qu

mvnpdf

Builtin index · Statistics & ML

result = mvnpdf(x, mu, Sigma)

Input: x, mu, Sigma · Output: result

What it is

Multivariate Gaussian density at a length-D point x, with a length-D mean vector mu and a (D, D) covariance matrix Sigma, evaluated through Sigma's Cholesky factor rather than an explicit matrix inverse (faster, and numerically stabler for a near-singular covariance).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = mvnpdf(x, mu, Sigma)
x vector or matrixnot documented yet
mu vector or matrixnot documented yet
Sigma vector or matrixnot documented yet
result number
Returns a single number.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

mu = [0, 0]
Sigma = [4, 0; 0, 9]
p = mvnpdf([2, 3], mu, Sigma)          # density at one point

ps = mvnpdf([0,0; 2,3; -2,-3], mu, Sigma)  # one density per row

from numerics-dsp

How it works

mvnpdf(x, mu, Sigma) — the multivariate Gaussian density at x (a single k-dimensional point, or a matrix whose rows are k-dimensional points) given a mean vector mu (length k) and a (k,k) covariance Sigma. Uses Sigma's Cholesky factor L for both the normalizing constant (det(Sigma) = det(L)^2, so log det(Sigma) = 2 * sum(log diag(L)) — never computed by literally expanding a determinant) and the quadratic form ((x-mu)^T Sigma^-1 (x-mu) = ||L^-1(x-mu)||^2 via forward substitution, never an explicit Sigma^-1) — the standard numerically-stable formulation, and the reason this needed chol before it could be built at all.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.