[uBLAS] Matrix inversion

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

[uBLAS] Matrix inversion

Ryan McConnehey
I haven't found anywhere in the documentation for a method that does
matrix inversion.  Does such a method exist but isn't well documented?

Ryan


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Matwey V. Kornilov

`solve' does matrix inversion for triangular matrices. LU decomposition is
also present in lu.hpp

Ryan wrote:

> I haven't found anywhere in the documentation for a method that does
> matrix inversion.  Does such a method exist but isn't well documented?
>
> Ryan


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Marco Guazzone
On Wed, Mar 2, 2011 at 9:04 AM, Matwey V. Kornilov
<[hidden email]> wrote:
>
> `solve' does matrix inversion for triangular matrices. LU decomposition is
> also present in lu.hpp
>

Hi,

take a look here:
http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Effective_UBLAS

Best,

-- Marco

> Ryan wrote:
>
>> I haven't found anywhere in the documentation for a method that does
>> matrix inversion.  Does such a method exist but isn't well documented?
>>
>> Ryan
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Ryan McConnehey
In reply to this post by Matwey V. Kornilov
Matwey V. Kornilov wrote:
> `solve' does matrix inversion for triangular matrices. LU decomposition is
> also present in lu.hpp
>
>  
What is the difference between a triangular matrix and the plain matrix?

Ryan

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Ryan McConnehey
In reply to this post by Marco Guazzone
sguazt wrote:
> Hi,
>
> take a look here:
> http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Effective_UBLAS
>  
This is the matrix inversion that I've tried.  It is lacking in checks
and at that point I wanted to know if there was an inversion built into
uBLAS.  If there was an inversion built in then it would have the normal
quality checks that I've come to expect from Boost.

Was there a reason that an inversion method wasn't included in the uBLAS
library?  It seems a pretty basic matrix manipulation.  Is there a
complexity I'm not familiar with that would prohibit it's implementation?

Ryan
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Marco Guazzone
On Wed, Mar 2, 2011 at 2:08 PM, Ryan <[hidden email]> wrote:

> sguazt wrote:
>>
>> Hi,
>>
>> take a look here:
>>
>> http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Effective_UBLAS
>>
>
> This is the matrix inversion that I've tried.  It is lacking in checks and
> at that point I wanted to know if there was an inversion built into uBLAS.
>  If there was an inversion built in then it would have the normal quality
> checks that I've come to expect from Boost.
>

Sorry, but I don't understand why you can't use

http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?LU_Matrix_Inversion

It is based on LU factorization (which is part of uBLAS).

Apart from checking at the beginning if the input matrix is square,
what kind of other "checks" does it lack?

> Was there a reason that an inversion method wasn't included in the uBLAS
> library?  It seems a pretty basic matrix manipulation.  Is there a
> complexity I'm not familiar with that would prohibit it's implementation?
>

>From my little experience with the implementation of math problems,
you rarely use matrix inversion.
Anyway, don't know why this function has not been included yet.
Personally I use (a variant of) the one above, with the addition that
in case of a singular matrix, I return a matrix with all values set to
infinity (just like MATLAB does)

-- Marco

> Ryan
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Ryan McConnehey
On Wed, Mar 2, 2011 at 9:05 AM, sguazt <[hidden email]> wrote:
Sorry, but I don't understand why you can't use

http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?LU_Matrix_Inversion

It is based on LU factorization (which is part of uBLAS).
 
I am using this function.  It was my starting point.  I just wanted to use an "official" method if that was an option.
 
Apart from checking at the beginning if the input matrix is square,
what kind of other "checks" does it lack?
 
That is one of the checks I added.  I also check if the inverse matrix is the same size as the input matrix.  If the inverse is a different size I resize it to match the input matrix.  A try/catch was also needed around the lu_substitute if it failed.
  
Personally I use (a variant of) the one above,
 
This is what I wanted to avoid by using an "official" method.  I may not have caught everything in my variant of the function and would really like it not to give me problems.
 
Ryan

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Curtis Gehman-2
In reply to this post by Ryan McConnehey
I'm not a uBLAS developer, but I suspect that it isn't included simply because matrix inversion is not a common problem in practice.  More common is solving a linear system.  Computing the matrix inverse to solve a linear system is probably the worst way to solve it.


On Mar 02, 2011, at 05:08 AM, Ryan <[hidden email]> wrote:

sguazt wrote:
> Hi,
>
> take a look here:
> http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Effective_UBLAS
>
This is the matrix inversion that I've tried. It is lacking in checks
and at that point I wanted to know if there was an inversion built into
uBLAS. If there was an inversion built in then it would have the normal
quality checks that I've come to expect from Boost.

Was there a reason that an inversion method wasn't included in the uBLAS
library? It seems a pretty basic matrix manipulation. Is there a
complexity I'm not familiar with that would prohibit it's implementation?

Ryan
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Curtis Gehman-2
In reply to this post by Ryan McConnehey
On Mar 02, 2011, at 05:02 AM, Ryan <[hidden email]> wrote:

Matwey V. Kornilov wrote:
> `solve' does matrix inversion for triangular matrices. LU decomposition is
> also present in lu.hpp
>
>
What is the difference between a triangular matrix and the plain matrix?
 
Google "wiki triangular matrix".

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Bo Jensen-2
In reply to this post by Curtis Gehman-2
On Wed, Mar 2, 2011 at 7:52 PM, Curtis Gehman <[hidden email]> wrote:
> I'm not a uBLAS developer, but I suspect that it isn't included simply
> because matrix inversion is not a common problem in practice.  More common
> is solving a linear system.  Computing the matrix inverse to solve a linear
> system is probably the worst way to solve it.

Agree. I also noted about the headline in :

http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?LU_Matrix_Inversion

LU is a factorization of the matrix not a inverse...in real life
inverting the matrix is only for small examples.

>
>
> On Mar 02, 2011, at 05:08 AM, Ryan <[hidden email]> wrote:
>
> sguazt wrote:
>> Hi,
>>
>> take a look here:
>>
>> http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Effective_UBLAS
>>
> This is the matrix inversion that I've tried. It is lacking in checks
> and at that point I wanted to know if there was an inversion built into
> uBLAS. If there was an inversion built in then it would have the normal
> quality checks that I've come to expect from Boost.
>
> Was there a reason that an inversion method wasn't included in the uBLAS
> library? It seems a pretty basic matrix manipulation. Is there a
> complexity I'm not familiar with that would prohibit it's implementation?
>
> Ryan
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Matwey V. Kornilov
In reply to this post by Ryan McConnehey

A triangular matrix has zero elements below the diagonal (upper triangular)
or above the diagonal (lower triangular). This way a nonsingular triangular
matrix can be inverted in straightforward manner. LU decomposition allows to
produce two triangular matrices which product is your source matrix. A
matrix inversion can be implemented by means of these succeeding operations.

Ryan wrote:

> Matwey V. Kornilov wrote:
>> `solve' does matrix inversion for triangular matrices. LU decomposition
>> is also present in lu.hpp
>>
>>  
> What is the difference between a triangular matrix and the plain matrix?
>
> Ryan


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Bo Jensen-2
On Wed, Mar 2, 2011 at 8:07 PM, Matwey V. Kornilov
<[hidden email]> wrote:
>
> A triangular matrix has zero elements below the diagonal (upper triangular)
> or above the diagonal (lower triangular). This way a nonsingular triangular
> matrix can be inverted in straightforward manner. LU decomposition allows to
> produce two triangular matrices which product is your source matrix. A
> matrix inversion can be implemented by means of these succeeding operations.
>

Even the matrix is triangular, you still don't invert it, you use
forward and backward substitution to solve the linear system. I am
sorry to be a pain, but I think this thread needs to be concise about
the use of inverse.

> Ryan wrote:
>
>> Matwey V. Kornilov wrote:
>>> `solve' does matrix inversion for triangular matrices. LU decomposition
>>> is also present in lu.hpp
>>>
>>>
>> What is the difference between a triangular matrix and the plain matrix?
>>
>> Ryan
>
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Ryan McConnehey
In reply to this post by Bo Jensen-2
On Wed, Mar 2, 2011 at 2:06 PM, Bo Jensen <jensen.bo@gmail.com> wrote:
LU is a factorization of the matrix not a inverse...in real life
inverting the matrix is only for small examples.
 
Since I'm dealing with a Kalman Filter in my real life the inverse is needed.
 
Ryan

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Bo Jensen-2
On Thu, Mar 3, 2011 at 4:04 PM, Ryan <[hidden email]> wrote:
> On Wed, Mar 2, 2011 at 2:06 PM, Bo Jensen <[hidden email]> wrote:
>>
>> LU is a factorization of the matrix not a inverse...in real life
>> inverting the matrix is only for small examples.
>
>
> Since I'm dealing with a Kalman Filter in my real life the inverse is
> needed.

Sorry my mistake, I did not know of Kalman Filter. I work with high
performance linear algebra where inversion is a no no.

>
> Ryan
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

rpuri6

LU is a good method for Matrix Inverse (see Numerical Recipes). Been using it for quite a while. You can always calculate the determinant of the inverse and multiply it with the determinant of the original Matrix to determine how good the inversion is. Boost implements are available online somewhere - i copied them as is.

 

For Kalman filters, ensure that the matrices are stable ie Determinants are not near zero.

 

have fun

 


----- Original Message -----
From: "Bo Jensen" <[hidden email]>
To: [hidden email]
Sent: Thursday, March 3, 2011 10:16:11 AM
Subject: Re: [Boost-users] [uBLAS] Matrix inversion

On Thu, Mar 3, 2011 at 4:04 PM, Ryan <[hidden email]> wrote:
> On Wed, Mar 2, 2011 at 2:06 PM, Bo Jensen <[hidden email]> wrote:
>>
>> LU is a factorization of the matrix not a inverse...in real life
>> inverting the matrix is only for small examples.
>
>
> Since I'm dealing with a Kalman Filter in my real life the inverse is
> needed.

Sorry my mistake, I did not know of Kalman Filter. I work with high
performance linear algebra where inversion is a no no.

>
> Ryan
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Ryan McConnehey
In reply to this post by Bo Jensen-2
On Thu, Mar 3, 2011 at 1:16 PM, Bo Jensen <jensen.bo@gmail.com> wrote:
Sorry my mistake, I did not know of Kalman Filter. I work with high
performance linear algebra where inversion is a no no.
 
Not a problem.  I just figured that since matrix inversion was one of those basic things you learned in college Calculus it would be in the uBLAS matrix library.
 
Ryan

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Ryan McConnehey
In reply to this post by rpuri6
On Thu, Mar 3, 2011 at 1:36 PM, <[hidden email]> wrote:

LU is a good method for Matrix Inverse (see Numerical Recipes). 

Do you have a link to these "Numerical Recipes"?
 
Ryan

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

rpuri6

http://www.nr.com/


----- Original Message -----
From: "Ryan" <[hidden email]>
To: [hidden email]
Sent: Thursday, March 3, 2011 11:19:26 AM
Subject: Re: [Boost-users] [uBLAS] Matrix inversion

On Thu, Mar 3, 2011 at 1:36 PM, <[hidden email]> wrote:

LU is a good method for Matrix Inverse (see Numerical Recipes). 

Do you have a link to these "Numerical Recipes"?
 
Ryan

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

rpuri6
In reply to this post by Ryan McConnehey

http://www.anderswallin.net/2010/05/matrix-determinant-with-boostublas/

 

http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?LU_Matrix_Inversion

 

Ryan,

 

hope this helps. be aware of floating point limitations  on your system. It will impact the max Matrix size and its stability criterion

 


----- Original Message -----
From: "Ryan" <[hidden email]>
To: [hidden email]
Sent: Thursday, March 3, 2011 11:05:54 AM
Subject: Re: [Boost-users] [uBLAS] Matrix inversion

On Thu, Mar 3, 2011 at 1:16 PM, Bo Jensen <jensen.bo@gmail.com> wrote:
Sorry my mistake, I did not know of Kalman Filter. I work with high
performance linear algebra where inversion is a no no.
 
Not a problem.  I just figured that since matrix inversion was one of those basic things you learned in college Calculus it would be in the uBLAS matrix library.
 
Ryan

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [uBLAS] Matrix inversion

Ryan McConnehey
Thanks for the links.  They should help.
 
Ryan

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users