3 ms·
Implementation tip - you don't need to invert that matrix! [1]. Whenever you see an equation of the form Ab = c and you want to find b, you should use a functio
by crntaylor 14y ago
Implementation tip - you don't need to invert that matrix! [1]. Whenever you see an equation of the form Ab = c and you want to find b, you should use a function equivalent to lu_solve (in the GNU Scientific Library) or the left-divide operator in Octave/Matlab (b = A\c), which will use the LU factorization algorithm [2] without ever computing A^(-1).
This is normally faster, more numerically stable and more space efficient. Even better, once you've computed the LU factorization of A once (which takes O(n^3) operations) you can then solve Ab = c for many different values of b and c in O(n^2) operations, by caching the factorization of A.
[1] http://www.johndcook.com/blog/2010/01/19/dont-invert-that-matrix http://www.johndcook.com/blog/2010/01/19/dont-invert-that-ma...
[2] http://en.wikipedia.org/wiki/LU_decomposition http://en.wikipedia.org/wiki/LU_decomposition
- deleted 14y ago[deleted]
- rohitarondekar 14y agoAccording to Wikipedia[1]Matrix Inversion is also O(n^3) and according to the note can be even better by inverting smaller matrices within and multiplying[2]. My linear algebra isn't very good so I'll have to look into LU Factorization but is there vast difference between the computational performance of the two operations? (Assuming you don't need solve Ab=c for different values of b and c) Also is LU Factorization used often in machine learning instead of inverse? [1]: http://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations#Matrix_algebra http://en.wikipedia.org/wiki/Computational_complexity_of_mat... [2]: Because of the possibility to blockwise invert a matrix, where an inversion of an n×n matrix requires inversion of two half-sized matrices and 6 mulitplications between two half-sized matrices, and since matrix multiplication has a lower bound of Ω(n2 log n) operations[17], it can be shown that a divide and conquer algorithm that uses blockwise inversion to invert a matrix runs with the same time complexity as the matrix multiplication algorithm that is used internally. source is [1]
- beagle3 14y agoThe reason you want to avoid matrix inversion is not computational performance - it is precision. You can generally "multiply by the inverse" without actually computing the inverse, in a way that needs less intermediate floating point precision. If your matrices have a large spread of eigenvalues, it makes a lot of difference - double precision often doesn't have enough precision for direct inversion in the real world. (And even if you do want to invert, it is more numerically stable to do that as a solution of Ax=e, for each 'e' a basis element, as long as you compute A^-1 \* e indirectly using a numerically stable method)
- rohitarondekar 14y agoThank you for explaining, I think I get it now. The ML course on Coursera is a little light on the Maths. As in the professor only explains as much is needed to perform the techniques. So I think I'll be watching Strangs Linear Algebra lectures on OCW soon. :)