Fix O(T²) backward trajectory, extend backward sampling to single-cluster models#82
Merged
osorensen merged 2 commits intobackward-samplingfrom Mar 26, 2026
Merged
Conversation
Closed
…, duplicate alpha_hat Co-authored-by: osorensen <21175639+osorensen@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add backward sampling option to set SMC options
Fix O(T²) backward trajectory, extend backward sampling to single-cluster models
Mar 15, 2026
osorensen
approved these changes
Mar 26, 2026
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.
Three issues remained open from the initial CPF-IBS review. This PR addresses all three.
Changes
O(T²) → O(T) trajectory assembly (
src/particle.cpp)assemble_backward_trajectorywas prepending to Armadillo matrices viainsert_cols/insert_rowson every iteration, shifting all existing data each time. Replaced with pre-allocated matrices (set_size(n_items, T+1)etc.) written directly at column indextin the backward loop.Backward sampling extended to single-cluster models (
src/rejuvenate.cpp)assemble_backward_trajectorywas only reachable inside theif (prior.n_clusters > 1)block, sobackward_sampling = TRUEwas silently a no-op for single-cluster models and the corresponding tests were not exercising the new code path. Two changes:stored_weightsis now also transferred during MH acceptance so the weights are always current.else if (options.backward_sampling)after the multi-cluster block to callassemble_backward_trajectoryfor single-cluster models.Duplicate
alpha_hatassignment removed (tests/testthat/test-compute_sequentially_complete.R)Redundant back-to-back identical assignment that overwrote itself.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.