Real-time/Online Bayesian Inference

Hello all,

I started to use Pystan last week for a state-space model.
My model has two stages: First, parameters estimation (offline inference using mcmc). Second, a real-time/online inference in order to forecast/predict the position of objects at each time t.

The offline inference stage is easy to implement (thanks to the community’s efforts). However, I have been looking for real-time inference functions but I didn’t find any existing one.
Could you please tell me if there is a real-time/online inference library (whether in Stan, Pystan or Rstan)

Thanks so much,

1 Like

Sorry, your question fell through a bit.

I don’t think I understand the details of your problem, but assuming you know how to make a prediction if you knew the exact parameter values, you can easily generalize to the Bayesian setting - you take N posterior samples from the offline model fit one by one, make a single prediction for each sample. This gives you N samples of the prediction which you can treat as a distribution of possible outcomes. (choosing N depends on how much precision you need, if you care about tail probabilities, you need more than if you just core about some central tendency).

Note however that this means you don’t use the data in the online phase to improve your future inferences (change your parameter estimates). To do that, you currently need to refit the whole model (I believe there are people working on how to avoid refitting the whole model, but is AFAIK an open research question with no satisfactory answers).

Most packages in R wrapping Stan models (e.g. brms) support predictions for new data out of the box. I know that ctsem supports some state-space models, but I am not sure about their support for predictions. In Python world, I have no idea at all.

Does that answer your question?