计算点 p 到高维高斯 (M, V) 的距离

发布于 2024-10-08 07:03:15 字数 132 浏览 4 评论 0原文

我有一个具有均值 M 和协方差矩阵 V 的高维高斯分布。我想计算从点 p 到 M 的距离,考虑到 V(我猜这是 p 与 M 的标准差的距离?)。

换个角度来说,我取一个距离 M 1 sigma 的椭圆,并想检查 p 是否在该椭圆内部。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

琉璃繁缕 2024-10-15 07:03:15

如果 V 是有效的高斯协方差矩阵,则它是对称正定的,因此定义了有效的标量积。顺便说一下,inv(V) 也是如此。

因此,假设 M 和 p 是列向量,您可以将距离定义为:

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

将 d2 重写为 Matlab 方式(可能是一些不必要的括号):

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

好处是,当 V 是单位矩阵时,那么d1==d2它对应于经典的欧几里得距离。确定是否必须使用 d1 还是 d2 留作练习(抱歉,我的工作之一是教学)。写出多维高斯公式并将其与一维情况进行比较,因为多维情况只是一维的特殊情况(或进行一些数值实验)。

注意:在非常高的维空间中或对于很多要测试的点,您可能会从 V 的特征向量和特征值(即椭球体的主轴及其相应的方差)中找到一种聪明/更快的方法。

希望这有帮助。

一个。

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.

烟火散人牵绊 2024-10-15 07:03:15

考虑计算给定正态分布的点的概率:

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)

函数 MVNPDF由统计工具箱提供

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

小嗷兮 2024-10-15 07:03:15

也许我完全不对劲,但这不就和问每个维度一样吗:我在西格玛内吗?

伪代码:

foreach(dimension d)
    (M(d) - sigma(d) < p(d) < M(d) + sigma(d)) ?

因为你想知道 p 是否在高斯的每个维度内。所以实际上,这只是一个空间问题,你的高斯不必对此做任何事情(除了 M 和 sigma,它们只是距离)。

在 MATLAB 中,您可以尝试类似的操作:

all(M - sigma < p < M + sigma)

到那个地方的距离可能是,我不知道欧几里得距离的函数。也许 dist 有效:

dist(M, p)

因为 M 只是空间中的一个点,p 也是。只有 2 个向量。
现在是最后一场。您想知道西格玛形式的距离:

% create a distance vector and divide it by sigma
M - p ./ sigma

我认为这可以解决问题。

Maybe I'm totally off, but isn't this the same as just asking for each dimension: Am I inside the sigma?

PSEUDOCODE:

foreach(dimension d)
    (M(d) - sigma(d) < p(d) < M(d) + sigma(d)) ?

Because you want to know if p is inside every dimension of your gaussian. So actually, this is just a space problem and your Gaussian hasn't have to do anything with it (except for M and sigma which are just distances).

In MATLAB you could try something like:

all(M - sigma < p < M + sigma)

A distance to that place could be, where I don't know the function for the Euclidean distance. Maybe dist works:

dist(M, p)

Because M is just a point in space and p as well. Just 2 vectors.
And now the final one. You want to know the distance in a form of sigma's:

% create a distance vector and divide it by sigma
M - p ./ sigma

I think that will do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文