Re: [eigen] How to compute the inverse of a sparse matrix? And how ist computeInverseWithCheck(..) used correctly?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


2010/9/30 Mathias Goldau <math@xxxxxxxxxxxxxxxxxxxxxxxxx>:
> Is there a way in Eigen to compute the inverse of a sparse matrix?
>
> ATM I try to do that for dense matrix, and read the doc so I am aware that in
> case of non invertibility the result is undefined. So I looked into the repos
> and found: computeInverseWithCheck(..) function.

computeInverseWithCheck() is only for small fixed-size matrices. It
does a determinant-based check. That's useless for anything by very
small matrices.

For larger matrices, the only reasonable approach is to just compute
the inverse and if you want to check, multiply by the original matrix
and compare with Identity.

I don't know if we have any sparse inversion function but you can
always use any sparse solver (such as ours) with the identity matrix
as right-hand side.

Benoit

> But if I try to use it it aborts with:
>
> In file included from /usr/local/eigen/include/eigen3/Eigen/LU:27,
>                 from
> /home/math/repos/Wassermann/src/modules/detTract2GPConvert/WGaussProcess.cpp:25:
> /usr/local/eigen/include/eigen3/Eigen/src/LU/Inverse.h: In member function
> ‘void Eigen::MatrixBase<Derived>::computeInverseAndDetWithCheck(ResultType&,
> typename ResultType::Scalar&, bool&, const typename Eigen::NumTraits<typename
> Eigen::ei_traits<Derived>::Scalar>::Real&) const [with ResultType =
> Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001, 0,
> -0x00000000000000001, -0x00000000000000001>, Derived = Eigen::Matrix<double,
> -0x00000000000000001, -0x00000000000000001, 0, -0x00000000000000001,
> -0x00000000000000001>]’:
> /usr/local/eigen/include/eigen3/Eigen/src/LU/Inverse.h:400:   instantiated
> from ‘void Eigen::MatrixBase<Derived>::computeInverseWithCheck(ResultType&,
> bool&, const typename Eigen::NumTraits<typename
> Eigen::ei_traits<Derived>::Scalar>::Real&) const [with ResultType =
> Eigen::MatrixXd, Derived = Eigen::Matrix<double, -0x00000000000000001,
> -0x00000000000000001, 0, -0x00000000000000001, -0x00000000000000001>]’
> /home/math/repos/Wassermann/src/modules/detTract2GPConvert/WGaussProcess.cpp:53:
>  instantiated from here
> /usr/local/eigen/include/eigen3/Eigen/src/LU/Inverse.h:368: error: ‘run’ is
> not a member of
> ‘Eigen::ei_compute_inverse_and_det_with_check<Eigen::Matrix<double,
> -0x00000000000000001, -0x00000000000000001, 0, -0x00000000000000001,
> -0x00000000000000001>, Eigen::Matrix<double, -0x00000000000000001,
> -0x00000000000000001, 0, -0x00000000000000001, -0x00000000000000001>,
> -0x00000000000000001>’
>
> The calling code looks like this:
>
> Eigen::MatrixXd Cff( static_cast< int >( tract.size() ), static_cast< int >(
> tract.size() ) );
> size_t i = 0, j = 0;
> for( WFiber::const_iterator cit = tract.begin(); cit != tract.end(); ++cit, ++i )
> {
>    for( WFiber::const_iterator cit2 = tract.begin(); cit2 != tract.end();
> ++cit2, ++j )
>    {
>        Cff( i, j ) = cov( *cit, *cit2 );
>    }
> }
> bool isInvertible = false;
> Cff.computeInverseWithCheck( m_CffInverse, isInvertible );
>
> I want to use eigen for many covariance matrix which I assume to be sparse.
> But until I know how to compute the inverse of a spares matrix with eigen, I
> will use dense matrices at first...
>
> best regards
> Mathias
>
> --
> Institut für Informatik
> Universität Leipzig
> Johannisgasse 26, 04103 Leipzig
> Phone: +493419732283
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/