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
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] How to compute the inverse of a sparse matrix? And how ist computeInverseWithCheck(..) used correctly?
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Sat, 2 Oct 2010 09:32:17 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=AkgvJ+WC0q9Hcvx7vVidTs2HvYpSWEm0/DMcC1OB6UI=; b=aPsvPc8gRf+ix4/SR9Cw6+mb7BNPLIpTI7eotYh1JzUDSEy3iZNFUW2OWpnG72wqpN KzVBT2LKlKwRpdXlFqxhUUyvu9k3Arzym418RVtX78DoMT7ZYvWCfmIVFlfST+FL/m3M XQ2OblHgLThAKpD89BF+3KkbhkNX0x54yk3G4=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=NIDLTQqfZTg1M70LXxQTHT9lgwnfMBNRIGOe81Yver3lbU8+xEiy5Zw7V7La+Frlfd SoyATjwsaJNvbCDrWDNgA/+yL0BjXKb4rmS3Dk/51gLPVNyJl73KoXzGbJy3+WZ/uAXq CWER+vX9F0BDii33czDvR/4LpCWjXzlfbDsK4=
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
>>
>>
>>
>
>
>