3

I'm working on a Kalman filter implementation in Go. After reading this thread, I decided to use biogo for matrix operations. However, it appears from the documentation that biogo doesn't provide a function to calculate the inverse of a matrix.

Does anyone know otherwise or know of an easy way to calculate the inverse using the functions that biogo does provide? Thanks!

Community
  • 1
  • 1
drautb
  • 505
  • 6
  • 12
  • Is your implementation open source? I am considering starting such a KF library in go as well. Thanks. – ChrisR Oct 27 '16 at 20:14

2 Answers2

3

If you're willing to switch to the github.com/gonum/matrix package, then it provides an Inverse function that you can use. The interfaces of the two packages appear similar.

From posts on the gonum-dev mailing list, it appears that gonum/matrix is the way forward (and will eventually replace biogo.matrix).

BurntSushi5
  • 13,917
  • 7
  • 52
  • 45
  • 1
    Gonum/matrix is primarily written by Dan Kortschak who also writes biogo, in fact, I'm pretty sure that gonum/matrix started as more or less a fork of biogo.matrix. You're right that the endgame is for gonum/matrix to replace it. – Linear Dec 13 '13 at 15:08
  • 1
    Dan suggested using gonum/matrix when I asked him on the biogo mailing list as well. Thanks! – drautb Dec 16 '13 at 14:49
1

You should check if you really need the inverse matrix or if everything you do with it is solving some linear system.

For instance, if your formula is x=AB^(-1)Cy, then you decompose it into the steps w=Cy, z=solve(B,w), x=Az, completely avoiding the inverse matrix. So if your application is vector in - vector out, chances are that the inverse is not needed.

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • this helped implement pseudo inverse using gonum. The linear regression solution w = (X'X)^(-1) X'y can be implemented using gonum as w.Solve(X'X, X'y). where X' is X transposed. – Cassiohg Oct 18 '18 at 01:22
  • As you have the Lapack functions available, it is numerically more stable to compute the QR decomposition of $X$ and then solve Rw=Q'y, w=solve(R, Q'y) with the reduced dimensions of R. Purists use the SVD of X to cover all possible cases. – Lutz Lehmann Oct 18 '18 at 05:54