Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate distance from point p to high dimensional Gaussian (M, V)

I have a high dimensional Gaussian with mean M and covariance matrix V. I would like to calculate the distance from point p to M, taking V into consideration (I guess it's the distance in standard deviations of p from M?).

Phrased differentially, I take an ellipse one sigma away from M, and would like to check whether p is inside that ellipse.

like image 455
Elli Amir Avatar asked Dec 15 '10 21:12

Elli Amir


2 Answers

If V is a valid covariance matrix of a gaussian, it then is symmetric positive definite and therefore defines a valid scalar product. By the way inv(V) also does.

Therefore, assuming that M and p are column vectors, you could define distances as:

d1 = sqrt((M-p)'*V*(M-p));
d2 = sqrt((M-p)'*inv(V)*(M-p));

the Matlab way one would rewrite d2as (probably some unnecessary parentheses):

d2 = sqrt((M-p)'*(V\(M-p)));

The nice thing is that when V is the unit matrix, then d1==d2and it correspond to the classical euclidian distance. To find wether you have to use d1 or d2is left as an exercise (sorry, part of my job is teaching). Write the multi-dimensional gaussian formula and compare it to the 1D case, since the multidimensional case is only a particular case of the 1D (or perform some numerical experiment).

NB: in very high dimensional spaces or for very many points to test, you might find a clever / faster way from the eigenvectors and eigenvalues of V (i.e. the principal axes of the ellipsoid and their corresponding variance).

Hope this helps.

A.

like image 139
Adrien Avatar answered Oct 09 '22 05:10

Adrien


Consider computing the probability of the point given the normal distribution:

M = [1 -1];             %# mean vector
V = [.9 .4; .4 .3];     %# covariance matrix
p = [0.5 -1.5];         %# 2d-point
prob = mvnpdf(p,M,V);   %# probability P(p|mu,cov)

The function MVNPDF is provided by the Statistics Toolbox

like image 3
Amro Avatar answered Oct 09 '22 04:10

Amro