online Kalman and particle filter

20 views
Skip to first unread message

Krzysztof Rusek

unread,
Sep 28, 2022, 4:53:30 AMSep 28
to TensorFlow Probability
Hi,

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?

Regards
Krzysztof Rusek

Junpeng Lao

unread,
Sep 29, 2022, 1:21:25 AMSep 29
to TensorFlow Probability, kru...@gmail.com
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

unread,
Sep 29, 2022, 6:28:53 AMSep 29
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 <junpe...@gmail.com> w dniu 29.09.2022, o godz. 07:21:
Reply all
Reply to author
Forward
0 new messages