Repository navigation
Preserve the triangular block in the tria JVP at rank deficiency - #288
Draft
AdrienCorenflos wants to merge 1 commit into
Draft
AdrienCorenflos wants to merge 1 commit into
AdrienCorenflos wants to merge 1 commit into
Conversation
The previous tangent satisfied dL L^T + L dL^T = dA A^T + A dA^T at any rank, but it was not lower triangular when A is rank deficient. The Kalman update reads the leading block of tria(A) as a triangular factor and ignores its upper-right block, so the gradients were wrong whenever a singular noise covariance rotates with a parameter (2.7% error in the added test). tria now takes a static `n_lower` argument giving the size of the leading block used as a triangular factor downstream. The tangent keeps that block lower triangular and the upper-right block zero, solves the off-diagonal block exactly, and uses the previous pseudoinverse/null-space tangent on the Schur-complement block. The default n_lower = 0 keeps the previous behaviour. It reduces to the classical QR rule at full rank. n_lower is set in the Kalman filter update, the associative filter and smoother elements, and the filtering operator.
This branch has not been deployed
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.
Problem
The current custom JVP of
tria(introduced in #213 for #211) returns a tangentdLthat satisfies the Gramian identitydL L^T + L dL^T = dA A^T + A dA^Tat any rank, so gradients of quantities that depend onLonly throughL L^Tare exact.At a rank-deficient input, however, this tangent is in general not lower triangular: its null-space term
(I - L L^+) dA Qhas entries above the diagonal.The Kalman update reads
tria(M)blockwise: it uses the leadingn_y x n_yblock as a triangular factor (solve_triangular, log-determinant from the diagonal) and never reads the upper-right block.Those entries of the tangent are therefore discarded, so the update is not a function of
L L^Talong that tangent, and the gradient is silently wrong.The filter values are unaffected.
This happens, for example, when the observation noise is singular and its column space rotates with a parameter (
chol_R = [[1, 0], [c, 0]], derivative with respect toc): the gradient of the log-likelihood frompredict/updateis off by a few percent, while the values match the covariance-form filter to machine precision.Fix
triagets a static argumentn_lower(default0) giving the size of the leading block that is used downstream as a triangular factor.With
A = L Q^T(thin QR ofA^T),G = dA Q, andphi(X) = tril(X) - diag(X) / 2, the tangent isdL11 = L11 phi(K11 + K11^T), withK11 = L11^{-1} G11(classical rule, lower triangular),dL12 = 0,dL21 = G21 - L21 W + L22 K12^T, withK12 = L11^{-1} G12andW = K11 - phi(K11 + K11^T)(skew-symmetric),dL22= the previous pseudoinverse/null-space tangent applied toL22andG22 - L21 K12.Each block of the Gramian identity holds exactly, at any rank of
L22.n_lower = 0is exactly the previous tangent, andn_lower = nwithLinvertible is the classical QR rule.L11 L11^Tmust be positive definite, as already required by the consumers (innovation covariance).n_loweris set where the leading block is read as a triangular factor:kalman.filtering.update(n_y),kalman.filtering.associative_params_single(ny) andfiltering_operator(nx, forXi),kalman.smoothing.updateandassociative_params_single(nx).The other call sites use their factor either through products or as a whole triangular factor that must be invertible anyway, for which the default already gives the classical lower-triangular tangent, so they are unchanged.
Tests
Added to
tests/cuthbertlib/linalg/test_tria.py:dL12 = 0,dL11lower triangular) for rank-deficient inputs and severaln_lower,predict/updateagainst a covariance-form Kalman filter for the rotating rank-onechol_Rabove.This test fails on
mainand passes here.For reference, on the model of #211 (
cuthbert.filter, sequential and parallel), the gradients with this change agree with the covariance-form filter to about1e-15.Note
filter/filtering_operatorstill cannot handle a singular filtering factor at the value level, becausecho_solve((U1, True), b1)invertsU1(for example with a singularchol_Rorchol_P0).That is independent of differentiation and not addressed here.