Robust Automatic Differentiation of Square-Root Kalman Filters via Gramian Differentials

Adrien Corenflos

TL;DR

Square-root Kalman filters (SRKFs) are the gold standard for numerical stability in state estimation, but they are notoriously difficult to differentiate for gradient-based learning. This paper introduces a robust method for automatic differentiation (AD) of the SRKF's core "triangularization" step by differentiating the underlying Gramian identity ($LL^\top = MM^\top$) rather than the QR decomposition itself. This approach provides exact gradients even when the system is rank-deficient or has mismatched dimensions—scenarios where standard AD methods typically fail or diverge.

What Problem Does This Paper Address?

To learn the parameters of a state-space model (like the physics of a drone or a financial trend), researchers often use gradient-based optimization. This requires "differentiating through" the Kalman filter.

Square-root versions of these filters are preferred because they propagate the Cholesky factor ($L$) of the covariance matrix, ensuring it stays positive-definite despite rounding errors. However, the step that produces this factor—triangularization—poses two major hurdles for AD:

  1. Non-uniqueness: When the input matrix $M$ is "wide" (more columns than rows), there isn't a single unique triangular factor. Standard AD frameworks struggle to define a gradient for a non-unique mapping.
  2. Rank Deficiency: If the system has zero noise in some dimensions (rank deficiency), the standard formulas for differentiating matrix decompositions involve inverses that blow up (divide by zero), causing the algorithm to crash.

Methods

The author's key insight is that while the triangular factor $L$ might not be unique, the Gramian matrix ($MM^\top$) is. Since the final loss function (like the log-likelihood) only depends on the covariance, it only cares about the Gramian.

Instead of differentiating through the steps of a QR decomposition, the paper derives a surrogate tangent (a Jacobian-Vector Product or JVP) directly from the identity $LL^\top = MM^\top$.

The proposed method decomposes the tangent into two parts:

  • Column-space component: Handles perturbations within the range of the matrix using the Moore-Penrose pseudoinverse ($L^\dagger$). This replaces the standard inverse, making it robust to rank deficiency.
  • Null-space correction: Accounts for perturbations that fall outside the current column space of $L$.

Because this JVP is linear, the "Vector-Jacobian Product" (VJP) required for backpropagation can be obtained automatically through a process called "automatic transposition," making it easy to implement in modern frameworks like JAX or PyTorch.

Datasets

The paper validates the method using a synthetic Linear Gaussian State-Space Model (LGSSM).

  • Setup: A 4-dimensional state with 2-dimensional observations.
  • Test Case: The authors created a family of models where the observation noise covariance $V(\alpha)$ is controlled by a parameter $\alpha$. As $\alpha \to 0$, the matrix becomes rank-deficient.
  • Goal: Verify if the AD-computed gradient matches the actual slope of the log-marginal likelihood curve across the full range of $\alpha$.

Key Insights and Ideas

  • Gramian Sufficiency: You don't need a unique gradient for $L$ if your final output only depends on $LL^\top$. Any $dL$ that satisfies the differential of the Gramian identity will yield the correct gradient for the overall loss.
  • Bypassing the "Black Box": By focusing on the mathematical identity ($LL^\top = MM^\top$) rather than the algorithmic implementation (QR decomposition), the authors avoid the singularities inherent in the algorithm's internal steps.
  • Rank-Awareness: The use of the Moore-Penrose pseudoinverse allows the filter to handle "degenerate" cases (like perfectly noiseless sensors) that would normally break a differentiator.

Key Results

  • Accuracy: As shown in Figure 1, the gradients computed using the proposed method perfectly align with the log-marginal likelihood curve, even as the system approaches rank deficiency.
  • Robustness: The "classical" QR-based differentiation approach failed to return valid values in the test cases, whereas the new method remained stable.
  • Efficiency: The method provides a closed-form solution that is computationally efficient and doesn't require manual derivation of the adjoint (backward) pass.

Limitations and Future Work

  • Scope: The paper specifically addresses the triangularization primitive. While this is the "heart" of the SRKF, the experiments are limited to linear models (LGSSM).
  • Non-linear Extensions: While the logic should hold for Square-Root Unscented Kalman Filters (SR-UKF) or Extended Kalman Filters (SR-EKF), these are not explicitly tested in the paper.
  • Implementation: The author has provided an open-source implementation in JAX (the "cuthbert" library), but users of other frameworks would need to port the logic to benefit from these robust gradients.

Summary updated

Abstract

Square-root Kalman filters propagate state covariances in Cholesky-factor form for numerical stability, and are a natural target for gradient-based parameter learning in state-space models. Their core operation, triangularization of a matrix $M \in \mathbb{R}^{n \times m}$, is computed via a QR decomposition in practice, but naively differentiating through it causes two problems: the semi-orthogonal factor is non-unique when $m > n$, yielding undefined gradients; and the standard Jacobian formula involves inverses, which diverges when $M$ is rank-deficient. Both are resolved by the observation that all filter outputs relevant to learning depend on the input matrix only through the Gramian $MM^\top$, so the composite loss is smooth in $M$ even where the triangularization is not. We derive a closed-form chain-rule directly from the differential of this Gramian identity, prove it exact for the Kalman log-marginal likelihood and filtered moments, and extend it to rank-deficient inputs via a two-component decomposition: a column-space term based on the Moore--Penrose pseudoinverse, and a null-space correction for perturbations outside the column space of $M$.
BibTeX
@misc{corenflos2026robust,
  author = {Adrien Corenflos},
  title = {{Robust Automatic Differentiation of Square-Root Kalman Filters via Gramian Differentials}},
  year = {2026},
  eprint = {2603.13559},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.13559},
}
Figure