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 ]


yes for sparse matrices you have to use one the solver but I also
strongly discourage you to compute the inverse explicitly since for a
sparse matrix its inverse can be very dense..... Actually there are in
practice almost no use cases for the inverse since in 99% of the case
you simply want to multiply this inverse matrix with another one that
is equivalent to a "solve" operation:

A^-1 * B

<=>

decomposion_of_A.solve(B);

where decomposion_of_A can be either a LU or LLT decomposition. (for
sparse matrices we don't offer other dec yet).

gael

On Thu, Sep 30, 2010 at 2:45 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
> 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/