Speed improvements to inversion for large datasets#74
Conversation
…holesky solver over SVD and refactoring GTG_i/GTd_i.
|
A couple of comments. Strictly speaking, the requirement is that the system matrix is symmetric positive definite (SPD), not merely non-zero. Cholesky factorization can still succeed for an extremely ill-conditioned matrix, so success alone does not guarantee a well-conditioned solve. One could perform additional diagnostics on the factorization, but that is probably overkill here and would work against the goal of improving performance. An additional speed-up could be achieved by bypassing the computation of the posterior covariance. In most use cases, only the MAP/model estimate is required. As long as the Cholesky factorization is retained, the posterior covariance can be computed later if and when it is needed. This is essentially the approach used in nandir |
These changes make improvements to the speed of inversions when there is a lot of data.
I was running into slow inversion issues(?) in my use of Lompe for widebeam SuperDARN data. The inversion process (
model.run_inversion()) was by far the slowest part of the process, mainly because there was so much data in the inversion, making the SVD scipy solver alone take almost a full second per inversion.This PR makes two changes:
GTG_iandGTD_iso it does it via broadcasting rather than numpy math. Avoids constantly remaking the matrix.I have tested this on my FBI library for high-res SuperDARN measurements and noticed about a ~50% improvement in inversion speeds (~0.5 vs ~1s) from the previous formulation with bitwise-identical results. I have also tested in a more general Lompe use-case using an adapted version of
two_ways_to_calculate_FAC.py:This also gave identical results, albeit the speed improvement was more like ~10% due to the lower amount of data involved.
I do think this needs to be tested well if it's ever merged. I'm pretty confident it's a free speedup, but there could potentially be edge cases where a Cholesky solver gives different results to SVD (e.g., if
GGis wholly positive, but has very small values in it. I haven't found a case yet where the results aren't identical.