Updating State Space Model after receiving new data?

Let’s say I have a state space model, whose parameter/model posteriors are relative to the current time step T.

Now, let’s say I receive a new observation at T+1. How do I update the model/posteriors relative to this new observation, without running the whole thing again?

I know if certain conditions hold (linearity, normal errors), then we have something akin to a Kalman filter, where we have an “update” step we can complete simply via some matrix algebra.

Here’s a toy example below:

data {
  int<lower=1> T;            // Number of time points
  real y[T];                 // Observations (T observations)
  real A;                    // State transition coefficient
  real B;                    // Observation model coefficient
}

parameters {
  real x0;                   // Initial state
  real<lower=0> sigma_state; // State noise standard deviation
  real<lower=0> sigma_obs;   // Observation noise standard deviation
  real x[T];                 // Latent states (T states)
}

model {
  // Prior distributions
  x0 ~ normal(0, 1);                      // Prior for the initial state
  sigma_state ~ normal(0, 1);              // Prior for state noise
  sigma_obs ~ normal(0, 1);                // Prior for observation noise
  
  // State transition model
  x[1] ~ normal(A * x0, sigma_state);      // Transition from x0 to x1
  for (t in 2:T) {
    x[t] ~ normal(A * x[t - 1], sigma_state);  // State evolution over time
  }

  // Observation model
  for (t in 1:T) {
    y[t] ~ normal(B * x[t], sigma_obs);    // Observation based on latent state
  }
}

How would one handle a new piece of information at y_{T+1}, in order to update our state variables x_{T+1}?

What if there is no clear “update” step?

As far as I know there is no way to do this in Stan. Because Stan’s output is a sample from the joint posterior of all parameters rather than point estimates, an additional observation x_{T+1} will affect the posterior of at least x_T, which will probably affect x_{T-1} and could conceivably affect the entire posterior. Characterizing these changes requires resampling all parameters, which is what happens when you refit the model with the new observation in Stan.

That said, your toy example is simple enough (linear transitions, normal observations and priors) that a Bayesian Kalman filter can find the posterior analytically and allow these kind of updates. I don’t think it generally possible once you introduce nonlinear state transitions or non-normal observation error.

1 Like