Constructing a fixed-lag smoothing particle filter to run PMCMC

92 views
Skip to first unread message

Joe Z

unread,
Aug 13, 2025, 10:33:19 AMAug 13
to nimble-users
Hello: there

I have been trying to build a fixed-lag smoothing particle filter using NIMBLE. This means the main change lies in the particle weight update step (as shown in the picture, the lag is L)  Initially, I implemented my own smoothing particle filter through a nimbleFunction, which performed well on some simple examples. Thanks to the flexibility of nimbleFunction, I was able to incorporate an ancestor tracking system into the particle filter—not just using Effective Sample Size (ESS), but tracking the number of unique ancestral particles. This information is very helpful in determining the lag length for the lagged PF. However, when I tried to apply this filter to my more complex model (which has multiple observation channels), because it is a custom nimbleFunction that requires rewriting the likelihood calculation, I kept encountering various errors for different reasons. Therefore, I switched to looking into modifying the source code of the BootstrapFilter here (https://github.com/nimble-dev/nimbleSMC/blob/devel/packages/nimbleSMC/R/BootstrapFilter.R) to implement the fixed-lag smoother, but I am still facing difficulties.
Any insight or experience about creating custom smoothing particle filters with NIMBLE would be greatly appreciated!



  1.png
Kind regards
Joe



Joe Z

unread,
Aug 13, 2025, 9:23:48 PMAug 13
to nimble-users
2.png
The correct notation should be this one, and i previously wrote it incorrectly.

Daniel Turek

unread,
Aug 19, 2025, 7:47:29 AMAug 19
to Joe Z, nimble-users
Joe, thanks for the detailed email.  Although I don't have any experience writing smoothing particle filters in nimble, if you have a firm idea about what you're trying to implement, but you're running into errors or barriers with the actual implementation in nimble, then I'm sure we can help you get past them.  Sometimes some of the nuances of writing algorithms as nimbleFunctions, as you're doing, can be a bit particular.

Anyway, maybe someone else has more experience with smoothing particle filters, but we could at least offer to help get your implementation working, if that's helpful.

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/nimble-users/8f801d40-00cb-4d63-ab04-1ad3a835d298n%40googlegroups.com.
Message has been deleted

Joe Z

unread,
Aug 24, 2025, 9:28:21 PMAug 24
to nimble-users
Hello:  Daniel

It always feels good to have someone who can help! We can start with a simple example, using both the standard buildBootstrapFilter and a custom fixed-lag filter implemented via nimbleFunction. Please see the attachment. My target model has already been implemented in POMP (expect PF smoothing ), but since it does not support custom filter designs, I switched to Nimble. If this approach is correct, I am considering posting a minimal runnable version here. For more on information about smoothing filters, refer to Chapter 15 of Särkkä, S., & Svensson, L. (2023). Bayesian Filtering and Smoothing (Vol. 17). Cambridge University Press.

One more question: if we use a custom filter implemented via nimbleFunction, do we need to write the resampling method ourselves? At least, that’s how I’ve done it here.  Thank you!

Kind regards
Joe
fix lag PF with PMCMC.R
buildBootstrapFilter PMCMC.R

Daniel Turek

unread,
Aug 26, 2025, 4:46:57 PMAug 26
to Joe Z, nimble-users
Joe, thanks so much for posting your questions.  Indeed, as before I don't have specific experience implementing smoothing particle filters in nimble, but if you're running into issues in the implementation, I could help diagnose them.

I saw both attachments, and was able to successfully execute both of them entirely.  I didn't encounter any errors along the way.  Furthermore, admitting an incomplete understanding of the method you're using, the results didn't appear to be obviously incorrect - but maybe I'm wrong about that.  So given that, I wasn't exactly sure what your first question was.

As for your second question ("if we use a custom filter implemented via nimbleFunction, do we need to write the resampling method ourselves?"), yes, as you've done, if you are writing a custom implementation of a filter (as a nimbleFunction), then yes, you would need to implement the resampling method yourself, as you have done here.  I'm not familiar with the reference you cited (Särkkä & Svensson, 2023) to comment on whether the implementation is correct, but perhaps doing some basic testing of the resampling method in R (using uncompiled execution) would be a reasonable place to start.  If you're not certain how to do this basic testing of uncompiled execution, please let me know.  But assuming so, I think a good first step would be to validate the implementation is operating as you intended.

I hope this helps you move in the right direction. Again, if you have specific questions about the implementation of the resampling method, or any other custom-written nimbleFunction, then I'll be happy to look at that and answer them.

Cheers,
Daniel




Reply all
Reply to author
Forward
0 new messages