pygae / clifford

Geometric Algebra for Python
http://clifford.rtfd.io
BSD 3-Clause "New" or "Revised" License
754 stars 72 forks source link

Pseudoinverse for multivectors #366

Open tBuLi opened 3 years ago

tBuLi commented 3 years ago

Would it be possible to add an option to use the matrix pseudoinverse instead of the normal matrix inverse into the method for computing inverses for multivectors? Having read the relevant chapter in Christian Perwass' book, he also mentions there that a pseudoinverse should work. I think it would be very nice to add an option to e.g. the .inv() method that allows something like

M.inv(pseudo=True)

given that in some situations this is still meaningful to do.

eric-wieser commented 3 years ago

I assume this is for degenerate basis vectors, when sometimes there is no inverse?

tBuLi commented 3 years ago

Yes that's one case, and another one I've found is when performing bivector splits: when the two bivectors in the split B = B_1 + B_2 start to become to similar. As they become more and more identical the real inverse gives a LinAlgError at some point, but the pseudoinverse returns B_1 = B_2 = B / 2. This is much friendlier ;).

*I should say that this is what I hope and strongly suspect it will return, because I replaced the inverse with a pseudoinverse in the algorithm as it was stated in geometric calculus and got this much nicer result.

eric-wieser commented 3 years ago

If you update to the development version of clifford, you should find that the linear algebra method is not used at all (edit: in small algebras).

hugohadfield commented 3 years ago

I think we still use it for algebras greater than dimension 6?

tBuLi commented 3 years ago

I've taken the liberty of making a PR for this with a slightly different API then suggested above: I added a .pinv() method to really make it easy to distinguish. Let me know if you like it or want to see some changes!