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: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Thu, 30 Sep 2010 08:45:52 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=mjZQ2HhqqqyWlxBSVqYMr/nTxZa7sNXQJngqgQM67wk=; b=ZU9oXYnatMvwN4ENIODXpkFxXQkCX8szDZoM0YvtbDEcMoR0JGhXXz7NbFFIx9Eb1O C9cM6s1A8PVLmX9cPGG3FXRVunSUOXV4T7UjW+0yrMv1va1xAOSzORd+tCEf86l1Ph3f NPNPXz7bFB3qasgCccUg+QPEurPP1AK4Yjr1Y=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=xCb06PAdknugS6M4BKhkHp+COJfAl7NG3dUt4A3Zfub4BCg1t6cCtNVDVhZLUWIPO0 O6MqY1YXWOTwgRp2WF39CcDkEkUqW30Vaahpl8h10gtiq9JCDKwFQvpD/e+t3qIQhF+W bxfCAakEFIfTbpHlpYENdJRnqwdsw/ljEdHcE=
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
>
>
>