State Space Model Programming in Turing.jl
Tim Hargreaves 1 , Qing Li 1 , Charles Knipp 2 , Frederic Wantiez, Simon J. Godsill 1 , Hong Ge 1 · 2025
Read State Space Model Programming in Turing.jl by Tim Hargreaves 1 , Qing Li 1 , Charles Knipp 2 , Frederic Wantiez, Simon J. Godsill 1 , Hong Ge 1 (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2505-23302.txt.
Introduction
Tim Hargreaves and five co-authors bring state space models into the Turing.jl ecosystem in two thousand twenty-five. State space models are a strong class for time series in many fields. Past software for them lacks modular build and scale. That gap slows trials and blocks advanced inference.
Two new Julia packages fill the gap. One defines models in a shared, composable way. The other runs inference, from Kalman filters to particle filters and mixes. Code reuse cuts build time and lifts reliability. Memory care and graphics chip speed target large jobs. The work sits inside a known probabilistic programming system.
Catalog record
| CREATOR | Tim Hargreaves 1 , Qing Li 1 , Charles Knipp 2 , Frederic Wantiez, Simon J. Godsill 1 , Hong Ge 1 |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 38 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2505-23302
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
State Space Model Programming in Turing.jl Tim Hargreaves 1 , Qing Li 1 , Charles Knipp 2 , Frederic Wantiez, Simon J. Godsill 1 , Hong Ge 1 Abstract State space models (SSMs) are a powerful and widely-used class of probabilistic models for analysing time-series data across various fields, from econometrics to robotics. Despite their prevalence, existing software frameworks for SSMs often lack compositionality and scalability, hindering experimentation and making it difficult to leverage advanced inference techniques. This paper introduces SSMProblems.jl and GeneralisedFilters.jl , two Julia packages within the Turing.jl ecosystem, that address this challenge by providing a consistent, composable, and general framework for defining SSMs and performing inference on them. This unified interface allows researchers to easily define a wide range of SSMs and apply various inference algorithms, including Kalman filtering, particle filtering, and combinations thereof. By promoting code reuse and modularity, our packages reduce development time and improve the reliability of SSM implementations. We prioritise scalability through efficient memory management and GPU-acceleration, ensuring that our framework can handle large-scale inference tasks. I Introduction State space models (SSMs) [ 1 ] are a fundamental framework for analysing sequential data across various fields, including finance (e.g., modelling stock prices) [ 2 ] , ecology (e.g., analysing population dynamics) [ 3 ] , engineering (e.g., controlling robotic systems) [ 4 ] , and natural sciences (e.g., predicting weather patterns) [ 5 ] . An SSM models how a system changes over time by describing the evolution of an unobserved latent Markov chain, (x_{t})_{t=0}^{T} , and its relationship to (noisy) observations, (y_{t})_{t=1}^{T} . In its most general form, an SSM is defined by three distributions that may depend on static model parameters \theta : • p_{\theta}(x_{0}) — initialisation distribution • p_{\theta}(x_{t}|x_{t-1}) — transition distribution • p_{\theta}(y_{t}|x_{t}) — observation distribution for \;t=1,\ldots,T . Given these, the joint distribution of all x_{t} and y_{t} can be succinctly decomposed as, p_{\theta}(x_{0:T},y_{1:T})=p_{\theta}(x_{0})\prod_{t=1}^{T}p_{\theta}(x_{t}|x_{t-1})p_{\theta}(y_{t}|x_{t}). (1) This decomposition has two key characteristics. First, as x_{t} is a Markov chain, the distribution of the latent dynamics’ next state depends only on the current state. Secondly, after the latent state is conditioned, the observations are generated independently of each other. A common objective when analysing SSMs is Bayesian filtering, which infers the current latent state given all observations up to the current time. This involves studying the posterior distribution p_{\theta}(x_{t}|y_{1:t}) . A related task is Bayesian smoothing, which aims to infer the joint posterior of all latent states up to time t , p_{\theta}(x_{0:t}|y_{1:t}) . While general Markov Chain Monte Carlo (MCMC) frameworks like Metropolis-Hastings or Hamiltonian Monte Carlo [ 6 ] (provided by probabilistic programming languages such as Stan [ 7 ] or PyMC [ 8 ] ) might seem applicable, they are often inefficient for SSMs. The sequential nature of the data and increasing dimensionality with time lead to a high computational burden and slow convergence [ 9 ] . Instead, one should take advantage of the decomposition provided in Equation 1 , to generate the filtering (similarly, smoothing) distributions sequentially and recursively via a prediction step : p_{\theta}(x_{t}|y_{1:t-1})=\int p_{\theta}(x_{t}|x_{t-1})p_{\theta}(x_{t-1}|y_{1:t-1})dx_{t-1}, and update step (using Bayes’ rule): p_{\theta}(x_{t}|y_{1:t})\propto p_{\theta}(y_{t}|x_{t})p_{\theta}(x_{t}|y_{1:t-1}). For some models, these steps can be performed in closed-form, but in a general setting, sequential Monte Carlo (SMC) methods, such as the particle filter [ 10 ] , are typically employed. In addition, there may be settings where the model parameters \theta are unknown and must be inferred. This amounts to studying the joint posterior p(x_{1:T},\theta|y_{1:T}) , a task that can be accomplished using particle Markov chain Monte Carlo (PMCMC) methods [ 11 ] or SMC 2 [ 12 ] . This work introduces two software packages, SSMProblems.jl and GeneralisedFilters.jl , that provide a unified interface for defining various SSMs and their inference algorithms, respectively. These packages are part of the Turing.jl [ 13 ] ecosystem, but offer a specific focus on optimised inference for SSMs, including efficient implementations of Kalman filtering and SMC methods. This contrasts with the more general Bayesian modelling approach of the original Turing.jl package. Section II discusses our key design decisions and the advanced features our work supports compared to existing frameworks, before briefly introducing three case studies we include in the appendices, demonstrating our claims and providing practical use-cases of our framework. II State Space Model Programming II-A SSMProblems.jl : a minimal interface for specifying state-space models SSMProblems.jl provides a minimal yet powerful interface for specifying a wide range of state space models (SSMs). SSMs are defined in SSMProblems.jl as a composition of two types representing the latent dynamics and observation process of the model. Such types may implement a distribution method for the initialisation, transition, and observation distributions defined in Section I , returning a Distributions.jl object. Alternatively, one may define simulate and logdensity methods for simulating from and computing log-densities of these distributions directly (with default implementations using distribution ). As a simple example, non-linear Gaussian dynamics could be defined as follows. Definition of non-linear Gaussian dynamics Here, kwargs... is Julia specific nomenclature that we use as a convenient way of forwarding inference-time inputs, such as control or time variables, that enable time-inhomogeneous and controlled dynamics. Our interface is designed to be lightweight, providing only the minimal functionality required to define SSMs. Despite its minimal design, our interface remains general-purpose, with additional model properties implemented by extending this foundational form. For example, linear Gaussian latent dynamics have a transition distribution of the form p(x_{t}|x_{t-1})\sim\mathcal{N}(A_{t}x_{t}+b_{t},Q_{t}). It is vital that the matrices/vectors A_{t},b_{t},Q_{t} can be accessed directly so that closed-form inference using the Kalman filter can be performed. SSMProblems.jl makes these available by defining an abstract type, LinearGaussianLatentDynamics , that expects methods for calc_A , calc_b and calc_Q to be implemented, with signatures similar to that of distribution . These methods can then be used directly by the Kalman filter algorithm for exact inference, or as ingredients for particle filters. In this sense, our state-space modelling interface is unified—one can define a linear Gaussian SSM once and expect both efficient closed-form and generic (e.g. particle filter) inference algorithms to work without additional implementation effort. This is desirable when comparing multiple candidate models, as the most general form of particle filtering can be applied to all of them, providing a consistent benchmark. By splitting the SSM definition into latent dynamics and observation process components, the interface is modular, allowing the user to easily replace either component without redefining the entire model. This also allows for constructing complex hierarchical models that admit Rao-Blackwellisation [ 14 ] as detailed in Appendix A . Our modelling interface is also robust in that it is designed to enforce the consistency of latent states and observations’ numeric value types via Julia’s parametric types. This design makes models compatible with automatic differentiation [ 15 ] . It also allows for preallocation of particle storage, given that all types are known before running inference algorithms. These design choices ensure that SSMProblems.jl provides a flexible, robust, and efficient foundation for defining and working with SSMs. II-B GeneralisedFilters.jl : a general-purpose interface for filtering algorithms GeneralisedFilters.jl provides efficient implementations of various filtering algorithms using the standardised interface provided by SSMProblems.jl . Specifically, an inference algorithm is defined by writing predict and update methods that