Repository navigation
Fix indexing errors in particle smoothers - #282
Merged
SamDuffield merged 2 commits intoOct 2, 2026
Merged
Conversation
Resolves state-space-models#281. This fixes an indexing bug in the particle smoothers, which results in the incorrect smoothing distribution. Concretely, `state_2.model_inputs` was previously used as part of the `log_potential`: https://github.com/state-space-models/cuthbert/blob/ec53db22e17b6ab29975e41af8a0758a2a6ff665/cuthbert/smc/backward_sampler.py#L181-L188 But the `model_inputs` convention for particle smoothers differ from the rest of `cuthbert`, and `state_1.model_inputs` should be used accordingly: https://github.com/state-space-models/cuthbert/blob/ec53db22e17b6ab29975e41af8a0758a2a6ff665/cuthbert/smc/backward_sampler.py#L128-L137 The proper `state_2.model_inputs` is now properly used. This issue wasn't found by the tests because the model definition was wrong in tests: in particular, backward sampling smoothers require the joint log potential, but only the observation log potential was given. We now use the proper model definition, which would fail before but passes now. Finally, there was a key reshape that caused issues with typed keys. We now split with the correct shape directly, which makes this compatible with both JAX key types.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
An unused variable fails Ruff checks, and the increased particle count substantially expands quadratic test work.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Fixes particle-smoother input indexing and typed JAX key compatibility.
Changes:
- Uses the correct transition inputs during backward sampling.
- Corrects the smoothing test model.
- Splits MCMC keys directly into the required shape.
| File | Description |
|---|---|
cuthbert/smc/backward_sampler.py |
Corrects smoother input indexing. |
cuthbertlib/smc/smoothing/mcmc.py |
Supports typed and legacy keys. |
tests/cuthbert/smc/test_backward_sampler.py |
Updates the smoothing regression test. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Tightens the MSE threshold, and tests covs.
SamDuffield
approved these changes
Oct 2, 2026
SamDuffield
left a comment
Contributor
There was a problem hiding this comment.
Good catch and thanks a lot for the fix!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Resolves #281. This fixes an indexing bug in the particle smoothers, which results in the incorrect smoothing distribution. Concretely,
state_2.model_inputswas previously used as part of thelog_potential:cuthbert/cuthbert/smc/backward_sampler.py
Lines 181 to 188 in ec53db2
But the
model_inputsconvention for particle smoothers differ from the rest ofcuthbert, andstate_1.model_inputsshould be used accordingly:cuthbert/cuthbert/smc/backward_sampler.py
Lines 128 to 137 in ec53db2
The proper
state_1.model_inputsis now properly used.This issue wasn't found by the tests because the model definition was wrong in tests: in particular, backward sampling smoothers require the joint log potential, but only the observation log potential was given. We now use the proper model definition, which would fail before but passes now.
Finally, there was a key reshape that caused issues with typed keys. We now split with the correct shape directly, which makes this compatible with both JAX key types.