我试图实现这一点而不成功,我必须这样做,而不使用外部模块NUMPY等。在APP中有3个模块,我正在编码这个,Python和C**,C++,但是没有其他的标准库。在
在一个单独的应用程序中,我使用了numpy的svd,它非常准确地工作。所以我用它来匹配我的结果。我的方法是PCA,到目前为止一切都很好。但是在计算了对称协方差矩阵之后,我不知道如何找到最大的特征向量。在
数据集始终是三维点,x、y和z
vector center;
for(point p in points):
center += p;
center /= points.count;
sumxx = 0;
sumxy = 0;
sumxz = 0;
sumyy = 0;
sumyz = 0;
sumzz = 0;
for(point p in points):
vector s = p - center;
sumxx += s.x * s.x;
sumxy += s.x * s.y;
sumxz += s.x * s.z;
sumyy += s.y * s.y;
sumyz += s.y * s.z;
sumzz += s.z * s.z;
matrix3 mat = invert(matrix3(sumxx, sumxy, sumxz, sumxy, sumyy, sumyz, sumxz, sumyz, sumzz));
vector n;
if (determinant(mat) > 0)
normal = find_largest_eigenvalue
求特征值有不同的算法。有些是从最小到最大的,比如QR;另一些是从大到小,比如幂迭代或Jacobi-Davidson。在
也许你想换个算法。试试能量法,看看是否有用。在
{a1}
让我们回顾一下您的要求,以澄清:
mat
在这些非常具体的情况下,以下答案适用。然而,tmyklebu警告说,对于某些病理性矩阵,这种方法的数值不稳定性,特别是当
r
接近-1
时。在好吧,让我们从wikipedia's page on Characteristic polynomials开始读一点
等等,让我们直接跳到3x3 matrix section in the page on Eigenvalue algorithms。在
后面几行后面是(或多或少)这个伪代码,对于对称矩阵(如果我没弄错的话,您可能有复特征值):
所以第一种情况是
max(eig1,eig2,eig3)
,第二种情况是eig1
。让我们称e
这个最大的特征值。在对于特征向量,您现在只需求解
(A-e*I)x=0
相关问题 更多 >
编程相关推荐