我正在尝试确定 Eigen 中稀疏数组的特征值和特征向量。由于我需要计算所有特征向量和特征值,并且我无法使用不受支持的 ArpackSupport 模块工作来完成此操作,因此我选择将系统转换为密集矩阵并使用 SelfAdjointEigenSolver 计算特征系统(我知道我的矩阵是真实的并且具有实特征值)。在我拥有大小为 1024*1024 的矩阵之前,此方法运行良好,但随后我开始与预期结果出现偏差。
根据我的理解,在该模块 ( https://eigen.tuxfamily.org/dox/classEigen_1_1SelfAdjointEigenSolver.html) 的文档中,可以更改最大迭代次数:
const int m_maxIterations static Maximum number of iterations.
The algorithm terminates if it does not converge within m_maxIterations * n iterations, where n denotes the size of the matrix. This value is currently set to 30 (copied from LAPACK).
但是,我不明白你是如何实现的,使用他们的例子:
SelfAdjointEigenSolver<Matrix4f> es;
Matrix4f X = Matrix4f::Random(4,4);
Matrix4f A = X + X.transpose();
es.compute(A);
cout << "The eigenvalues of A are: " << es.eigenvalues().transpose() << endl;
es.compute(A + Matrix4f::Identity(4,4)); // re-use es to compute eigenvalues of A+I
cout << "The eigenvalues of A+I are: " << es.eigenvalues().transpose() << endl
您将如何修改它以更改最大迭代次数?
此外,这会解决我的问题,还是我应该尝试寻找替代函数或算法来求解特征系统?
提前致谢。
最佳答案
增加迭代次数不太可能有帮助。另一方面,从 float
移动到 double
会有很大帮助!
如果这没有帮助,请更具体地说明“与预期结果的偏差”。
关于c++ - 在 Eigen 中提高 SelfAdjointEigenSolver 的精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39837808/