online Kalman and particle filter

Skip to first unread message

Krzysztof Rusek

Sep 28, 2022, 4:53:30 AM9/28/22
to TensorFlow Probability

I would like to perform online Kaman/particle filter instead of scanned version provided by tfp api like `tfp.experimental.mcmc.particle_filter` or `tfd.LinearGaussianStateSpaceModel.forward_filter`.

To be clear, TFP is designed for filtering a vector of observations, while I am receiving observations in the streaming fashion and I want to make a decision based on the current estimate of the hidden state.

What is the recommended way to do it in TFP, as the internals of the mentioned methods are not part of the public API.

One possibility I see is to run the scanned function for each observation and update the state prior for the next iteration. Is this the correct approach?

Krzysztof Rusek

Junpeng Lao

Sep 29, 2022, 1:21:25 AM9/29/22
to TensorFlow Probability,
One way you can try is to use the build_kalman_filter_step in tfd.LinearGaussianStateSpaceModel.forward_filter to build the one step function at time t:

Assuming you have transition/observation matrix/noise at each step, you can do something like:
kalman_onestep = tfd.linear_gaussian_ssm.build_kalman_filter_step(
    lambda _: transition_matrix,
    lambda _: transition_noise,
    lambda _: observation_matrix,
    lambda _: observation_noise,

kalman_onestep(state, observed_at_t)

Otherwise, you can copy and modify the internal of kalman_filter_step and turn it into a tensor in tensor out function

For particle filter it is easier as you can use sequential_monte_carlo_kernel.SequentialMonteCarlo, it is how particle filter one step is called.

How this helps.

Krzysztof Rusek

Sep 29, 2022, 6:28:53 AM9/29/22
to Junpeng Lao, TensorFlow Probability
Thank you, this helps a lot, however, ideally ` _particle_filter_propose_and_update_log_weights_fn` should be part of public API to fully embrace SequentialMonteCarlo without custom boilerplate.

> Wiadomość napisana przez Junpeng Lao <> w dniu 29.09.2022, o godz. 07:21:
Reply all
Reply to author
0 new messages