查找协方差矩阵的特征向量以创建 3D 边界球

发布于 2024-09-27 03:08:36 字数 1438 浏览 8 评论 0原文

我目前正在编写一个函数来为 3D 空间中的一组点找到“精确”的边界球。我想到目前为止我对这个过程已经有了很好的理解,但我陷入了困境。

这是我正在处理的内容: A) 3D 空间中的点 B)存储在 4x4 矩阵类中的 3x3 协方差矩阵(由单元格 m0、m1、m2、m3、m4 等引用;而不是行和列)

我找到了点的协方差矩阵的 3 个特征值,并且我我们已经设置了一个函数,通过高斯消元法将矩阵转换为简化行梯形形式 (rref)。

我已经根据我在网上找到的示例中的数字测试了这两个函数,它们似乎工作正常。

下一步是使用以下方程找到特征向量: (M - λ*I)*V

... 其中 M 是协方差矩阵,λ 是特征值之一,I 是单位矩阵,V 是特征向量。

但是,在 rref 之前我似乎没有正确构建 4x3 矩阵,因为应计算特征向量分量的最右列在运行 rref 之前和之后均为 0。我理解为什么它们之后为零(没有任何常数,线性方程组的最简单的解决方案是所有系数为零),但我不知道该放什么。

到目前为止的函数如下:

Vect eigenVector(const Matrix &M, const float eval) {
   Matrix A = Matrix(M);
   A -= Matrix(IDENTITY)*eval;
   A.rref();
   return Vect(A[m3],A[m7],A[m11]);
}

3x3 协方差矩阵作为 M 传递,特征值作为 eval 传递。 Matrix(IDENTITY) 返回单位矩阵。 m3、m7 和 m11 对应于 4x3 矩阵的最右列。

这是我用来测试函数的 3x3 矩阵示例(存储在 4x4 矩阵类中):

Matrix(1.5f, 0.5f, 0.75f, 0,
       0.5f, 0.5f, 0.25f, 0,
      0.75f, 0.25f, 0.5f, 0,
          0,     0,    0, 0);

我正确地(?)从我的其他函数中获取了 2.097、0.3055、0.09756 的特征值。

上面的 eigenVector() 正确地从 rref() 之后的对角线 (0,0 1,1 2,2)

矩阵 A 中减去传递的特征值:

[(1, 0, 0, -0),
(-0, 1, 0, -0),
(-0, -0, 1, -0),
(0, 0, 0, -2.09694)]

对于 rref() 函数,我使用的是此处找到的翻译后的 python 函数: http://elonen.iki.fi/code/misc-notes /python-gaussj/index.html

我传递给 rref() 的矩阵应该是什么样子才能得到特征向量?

谢谢

I'm currently in the process of writing a function to find an "exact" bounding-sphere for a set of points in 3D space. I think I have a decent understanding of the process so far, but I've gotten stuck.

Here's what I'm working with:
A) Points in 3D space
B) 3x3 covariance matrix stored in a 4x4 matrix class (referenced by cells m0,m1,m2,m3,m4,ect; instead of rows and cols)

I've found the 3 eigenvalues for the covariance matrix of the points, and I've set up a function to convert a matrix to reduced row echelon form (rref) via Gaussian elimination.

I've tested both of those functions against figures in examples I've found online, and they appear to be working correctly.

The next step is to find the eigenvectors using the equation:
(M - λ*I)*V

... where M is the covariance matrix, λ is one of the eigenvalues, I is the identity matrix, and V is the eigenvector.

However, I don't seem to be constructing the 4x3 matrix correctly before rref'ing it, as the far right column where the eigenvector components should be calculated are 0 before and after running rref. I understand why they are zero after (without any constants, the simplest solution to a linear system of equations is all coefficients of zero), but I'm at a loss as to what to put there.

Here's the function so far:

Vect eigenVector(const Matrix &M, const float eval) {
   Matrix A = Matrix(M);
   A -= Matrix(IDENTITY)*eval;
   A.rref();
   return Vect(A[m3],A[m7],A[m11]);
}

The 3x3 covariance matrix is passed as M, and the eigenvalue as eval. Matrix(IDENTITY) returns an identity matrix. m3,m7, and m11 correspond to the far-right column of a 4x3 matrix.

Here's the example 3x3 matrix (stored in a 4x4 matrix class) I'm using to test the functions:

Matrix(1.5f, 0.5f, 0.75f, 0,
       0.5f, 0.5f, 0.25f, 0,
      0.75f, 0.25f, 0.5f, 0,
          0,     0,    0, 0);

I'm correctly (?) getting the eigenvalues of 2.097, 0.3055, 0.09756 from my other function.

eigenVector() above correctly subtracts the passed eigenvalue from the diagonal (0,0 1,1 2,2)

Matrix A after rref():

[(1, 0, 0, -0),
(-0, 1, 0, -0),
(-0, -0, 1, -0),
(0, 0, 0, -2.09694)]

For the rref() function, I'm using a translated python function found here:
http://elonen.iki.fi/code/misc-notes/python-gaussj/index.html

What should the matrix I pass to rref() look like to get an eigenvector out?

Thanks

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

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

发布评论

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

评论(2

只为一人 2024-10-04 03:08:36

(M - λI)V 不是一个方程,它只是一个表达式。然而,(M - λI)V = 0 是。这是将特征向量与特征值联系起来的方程。

因此,假设您的 rref 函数有效,我会想象您创建一个增广矩阵作为 [(M - λI) | 0],其中 0 表示零向量。这听起来像是您已经在做的事情,所以我不得不假设您的 rref 函数已损坏。或者,它不知道如何处理 4x4 矩阵(与 4x3 矩阵相反,这是它所期望的增广矩阵)。

(M - λI)V is not an equation, it's just an expression. However, (M - λI)V = 0 is. And it's the equation that relates eigenvectors to eigenvalues.

So assuming your rref function works, I would imagine that you create an augmented matrix as [(M - λI) | 0], where 0 denotes a zero-vector. This sounds like what you're doing already, so I would have to assume that your rref function is broken. Or alternatively, it doesn't know how to handle 4x4 matrices (as opposed to 4x3 matrices, which is what it would expect for an augmented matrix).

z祗昰~ 2024-10-04 03:08:36

啊,经过几个小时的艰苦研究,我终于解决了我的问题。

问题在于,不存在“一个”特征向量集,而是具有不同大小的无限数量。

我选择的方法是使用 REF(行阶梯形)而不是 RREF,在矩阵中留下足够的信息,以便我可以用任意值替换 z,并向后求解 y 和 x。然后,我对向量进行归一化以获得单位特征向量,这应该适合我的目的。

我的最终代码:

Vect eigenVector(const Matrix &M, const float eVal) {
   Matrix A = Matrix(M);
   A -= Matrix(IDENTITY)*eVal;
   A.ref();
   float K = 16; // Arbitrary value
   float J = -K*A[m6]; // Substitute in K to find J
   float I = -K*A[m2]-J*A[m1]; // Substitute in K and J to find I

   Vect eVec = Vect(I,J,K);
   eVec.norm(); // Normalize eigenvector

   return eVec;
}

唯一奇怪的是特征向量的方向与我预期的相反(它们被否定了!),但这是一个没有实际意义的问题。

Ah, with a few more hours of grueling research, I've managed to solve my problem.

The issue is that there is no "one" set of eigenvectors but rather an infinite number with varying magnitudes.

The method I chose was to use a REF (row echelon form) instead of RREF, leaving enough information in the matrix to allow me to substitute in an arbitrary value for z, and work backwards to solve for y and x. I then normalized the vector to get a unit eigenvector, which should work for my purposes.

My final code:

Vect eigenVector(const Matrix &M, const float eVal) {
   Matrix A = Matrix(M);
   A -= Matrix(IDENTITY)*eVal;
   A.ref();
   float K = 16; // Arbitrary value
   float J = -K*A[m6]; // Substitute in K to find J
   float I = -K*A[m2]-J*A[m1]; // Substitute in K and J to find I

   Vect eVec = Vect(I,J,K);
   eVec.norm(); // Normalize eigenvector

   return eVec;
}

The only oddity is that the eigenvectors come out facing in the opposite direction than I expected (they were negated!), but that's a moot problem.

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