Fitting a Kalman Smoother to Data

Shane T. Barratt, Stephen P. BoydACC 2020

Abstract

Kalman filters and smoothers are fundamental tools in state estimation, yet their performance depends heavily on the precise tuning of system parameters—matrices representing dynamics, observation models, and noise covariances. Traditionally, these parameters are tuned manually, a process often described as a "black art." This paper presents an automated framework for tuning Kalman smoothers by treating the task as a machine learning problem. By formulating the smoother as a differentiable operator and employing a proximal gradient method, the authors enable data-driven parameter optimization that scales linearly with the length of the time series.

Introduction

In fields ranging from aerospace navigation to econometric forecasting, the Kalman smoother is the standard for estimating the state of a dynamical system from noisy observations. The model relies on four primary matrices: the dynamics matrix ($A$), the output or measurement matrix ($C$), the process noise covariance ($W$), and the sensor noise covariance ($V$).

Despite their ubiquity, finding the "right" values for these matrices is notoriously difficult. Engineers often resort to trial-and-error, frequently inflating noise parameters to ensure numerical stability or "practical robustness" at the expense of accuracy. This work addresses the need for a principled, automated approach to parameter estimation, particularly in scenarios where data may be missing or irregularly sampled.

Problem Formulation: Smoothing as Optimization

The authors depart from the traditional recursive Bayesian derivation of the Kalman filter, instead framing the smoother as the solution to a constrained least squares problem. In this view, the state estimates are found by minimizing a quadratic objective function that balances adherence to the physical model (dynamics) against fidelity to the observed data.

This optimization perspective offers a significant advantage: missing measurements are handled naturally. If a measurement at time $t$ is unavailable, the corresponding term is simply omitted from the objective function without requiring the complex logic often needed in recursive implementations.

The Auto-Tuning Algorithm

The core contribution of the paper is an efficient algorithm for learning the parameters $\theta = \{A, C, W, V\}$ directly from data. The process is structured as follows:

  1. Data Masking: A portion of the observed data (e.g., 20%) is withheld to serve as a validation set for the optimization process.
  2. Forward Pass: The smoothing problem is solved using the current estimate of the parameters to predict the values of the masked data points.
  3. Backward Pass (Differentiation): The algorithm computes the gradient of the prediction error with respect to the parameters. The authors demonstrate that because the smoother is the solution to a sparse, banded linear system (the KKT system), the gradient can be computed in $O(T)$ time, where $T$ is the number of time steps. This makes the method computationally feasible even for very long sequences.
  4. Proximal Gradient Update: The parameters are updated using a proximal gradient method. This allows for the inclusion of regularization terms, which can be used to enforce sparsity in the dynamics or to keep the matrices close to a physically motivated initial guess.

Experimental Evaluation

The effectiveness of the auto-tuning approach was demonstrated on two real-world datasets with distinct characteristics:

U.S. Population Dynamics

Using U.S. Census Bureau data from 1900 to 2018, the authors modeled the population counts of the 48 continental states. The goal was to learn the migration patterns (the $A$ matrix) between states. The automated tuning reduced prediction error by approximately 40% and test error on unseen data by 27%. Notably, the learned $A$ matrix reflected known demographic trends, such as significant migration flows into California.

Vehicle Telemetry

Data was collected from an iPhone mounted in a moving vehicle, capturing acceleration, attitude, and GPS coordinates at 100 Hz. With over 33,000 measurements, this high-frequency dataset tested the algorithm's scalability. The results were stark: the prediction error dropped from an initial 13.23 (using heuristic parameters) to 2.97. The tuned smoother produced a trajectory that was significantly more accurate and visually smoother than the initial guess, effectively balancing the high-frequency accelerometer data with the lower-frequency GPS updates.

Discussion and Insights

A key insight of this work is that the smoother is a differentiable operator. By "differentiating through the smoother," the authors bridge the gap between classical control theory and modern gradient-based optimization. They also note that for the noise matrices $W$ and $V$, the absolute values are less critical than their relative magnitudes; the auto-tuning algorithm effectively learns the optimal "trust" ratio between the internal model and the external sensors.

Limitations

While powerful, the method is not without challenges. The optimization problem for parameter tuning is generally non-convex, meaning the algorithm may converge to local minima. Consequently, the quality of the final parameters can depend on the initial starting point. Additionally, while the framework can be extended to robust smoothers (using non-Gaussian noise models), the primary focus of this study remained on the quadratic case.

Conclusion

This paper provides a robust, scalable framework for moving Kalman smoother tuning from a manual heuristic to a rigorous, data-driven optimization process. By leveraging the sparsity of the KKT system, the authors provide a tool that is both mathematically grounded and computationally efficient for large-scale applications. The provided open-source implementation, auto_ks, allows researchers to apply these techniques to a wide variety of dynamical systems.

Summary updated

BibTeX
@inproceedings{barratt2020fitting,
  author = {Shane T. Barratt and Stephen P. Boyd},
  title = {{Fitting a Kalman Smoother to Data}},
  booktitle = {ACC},
  year = {2020},
  doi = {10.23919/acc45564.2020.9147485},
}
Figure