Eigen计算矩阵SVD分解报错

报错代码

MatrixXf m = MatrixXf::Random(3, 2);
JacobiSVD<MatrixXf, (ComputeThinU | ComputeThinV)> svd(m);

错误

/usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:666:3:   required from ‘Eigen::JacobiSVD<MatrixType, QRPreconditioner>& Eigen::JacobiSVD<MatrixType, QRPreconditioner>::compute(const MatrixType&, unsigned int) [with _MatrixType = Eigen::Matrix<float, -1, -1>; int QRPreconditioner = 40; Eigen::JacobiSVD<MatrixType, QRPreconditioner>::MatrixType = Eigen::Matrix<float, -1, -1>]/usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:548:7:   required from ‘Eigen::JacobiSVD<MatrixType, QRPreconditioner>::JacobiSVD(const MatrixType&, unsigned int) [with _MatrixType = Eigen::Matrix<float, -1, -1>; int QRPreconditioner = 40; Eigen::JacobiSVD<MatrixType, QRPreconditioner>::MatrixType = Eigen::Matrix<float, -1, -1>]/home/xu/school/usetools/src/use_eigen.cpp:18:62:   required from here
/usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:656:45: error:struct Eigen::internal::qr_preconditioner_impl<Eigen::Matrix<float, -1, -1>, 40, 0, true>has no member namedallocate656 |   if(m_cols>m_rows)   m_qr_precond_morecols.allocate(*this);
      |                       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~/usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:657:45: error:struct Eigen::internal::qr_preconditioner_impl<Eigen::Matrix<float, -1, -1>, 40, 1, true>has no member namedallocate657 |   if(m_rows>m_cols)   m_qr_precond_morerows.allocate(*this);
      |                       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
make[2]: *** [CMakeFiles/useEigen.dir/build.make:63: CMakeFiles/useEigen.dir/src/use_eigen.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/useEigen.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

解决方法

将构造与分解分开进行。

MatrixXf m = MatrixXf::Random(3, 2);
JacobiSVD<MatrixXf> svd;
svd.compute(m, ComputeThinU | ComputeThinV);
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用: "截止到这里为止,很多同学会有疑问了:你这不吃饱了撑得。好好的一个矩阵A,你这为毛要将他表示成三个矩阵。这三个矩阵的规模,一点也不比原来矩阵的规模小好么。而且还要做两次矩阵的乘法。要知道,矩阵乘法可是个复杂度为O(n^3)的运算。" 这个引用指的是在矩阵分解中,为什么要将一个矩阵表示成三个矩阵,并且进行两次矩阵乘法,因为矩阵乘法的复杂度是O(n^3)。 引用: "首先复习一下Cholesky(LLt)、QR和LU分解,一般来讲LLt分解可以理解成给矩阵开平方,类比于开平方一般针对正数而言,LLt分解则限定矩阵需为正定的Hermitian矩阵(自共轭矩阵,即对称的实数矩阵或对称元素共轭的复数矩阵)。LU分解则稍微放松一点,可用于一般的方阵。QR则可用于一般矩阵,结果也是最稳定的。分解算法的效率,三者都是O(n^3)的,具体系数三者大概是Cholesky:LU:QR=1:2:4。" 这个引用解释了Cholesky(LLt)、QR和LU分解的原理和应用范围,并指出它们的效率都是O(n^3),其中系数大致为Cholesky:LU:QR=1:2:4。 鉴于你提到了eigen稀疏矩阵svd,我将回答与此相关的问题。 Eigen是一个C++模板库,用于线性代数运算。Eigen提供了一种称为SVD(奇异值分解)的分解方法来处理稀疏矩阵SVD分解将一个矩阵分解为三个矩阵的乘积,其中两个矩阵是正交矩阵,第三个矩阵是对角矩阵,对角线上的元素称为奇异值。这种分解方法在处理稀疏矩阵时非常有效,因为它可以减少存储空间和计算复杂度。所以在使用Eigen处理稀疏矩阵时,可以使用SVD分解来获得矩阵的奇异值和相应的奇异向量。<span class="em">1</span><span class="em">2</span><span class="em">3</span>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值