EMS-TU-Ilmenau / fastmat

A library to build up lazily evaluated expressions of linear transforms for efficient scientific computing.
https://fastmat.readthedocs.io
Apache License 2.0
24 stars 8 forks source link

Factories for Inverse and Pseudoinverse #61

Open SebastianSemper opened 5 years ago

SebastianSemper commented 5 years ago

It would be nice to finally have multiplication with the inverse matrix or the more general moore penrose inverse for rank deficient matrices at hand.

After putting some thoughts into it and how to address it and after thinking about adding a property to the matrix, I think we should proceed similar as in the Hermitian, conjugate and transpose case and add a factory, to provide A.inverse and A.pseudoInverse. For A.inverse the forward transform is simply solving a system of linear equations, using the now accessible methods from scipy with the linearOperator property. The backward transform is solving the system of equations using A.H, since A.H.inverse = A.inverse.H and in the real valued case A.T.inverse = A.inverse.T. Of course, we here have the identity A.inverse.inverse = A. The scipy method used here, would be bicgstab. It even allows to make use of a preconditioning matrix, which in some cases might be easy for us to provide, since we know the structure of the matrices.

In case of the moore penrose inverse, we don't solve a system of equations, but rather do what is suggested here. Essentially solving a least squares problem, which is also provided by scipy using their LinearOperator. For the backward transform, we can do the same thing as in the case of A.inverse, so A.pseudoInverse.H = A.H.pseudoInverse. Here we can use lsmr form the scipy side.

This would extend our use cases tremendously and also fits our philosophy well, since it makes building up inverses of matrices very easy and neatly integrated with the rest of the package.

I have added it to the 0.3 milestone, since it will require a huge amount of testing and polishing before it can be let out in the wild.