Collapse quadratic forms to a single triangular solve - #2373
Open
jessegrabowski wants to merge 2 commits into
Open
Collapse quadratic forms to a single triangular solve#2373jessegrabowski wants to merge 2 commits into
jessegrabowski wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Computing
b.T @ K^-1 @ bappliesK^-1with a forward and a back substitution, and then the surrounding dot contracts the result straight back to a scalar. WritingK = C C.T, the same quantity is||C^-1 b||^2, so one substitution does. The rewrite catchescho_solveand also a hand-written pair of transposed triangular solves, whose factor doesn't have to come from a Cholesky; the square-root Kalman filter gets its factor out of a QR.The first commit lifts the
b_ndim=2gate onpsd_solve_to_chol_solveso a positive-definite solve with a vector right-hand side reaches the same chain instead of staying one opaqueposvcall.given_factortimes the substitutions with the factor already available;with_choleskyfactorizes from the covariance matrix on every call, so one quadratic form has to amortize the wholeO(n^3)and only 6-8% is left, inside a standard deviation except at n=3000.