Repository navigation
Guard inverse-CDF resampling endpoints and conditional references - #202
Open
THargreaves wants to merge 1 commit into
Open
THargreaves wants to merge 1 commit into
THargreaves wants to merge 1 commit into
Conversation
Systematic and stratified resampling scanned the scaled cumulative weights without an upper bound. When rounding put a threshold at or beyond the final cumulative weight, as with 4096 uniform Float32 weights, the @inbounds loop read past the array. Scans now stop at the last particle with positive weight, which also keeps trailing zero-weight particles from being selected. Conditional systematic and stratified resampling could lose the reference: a reference whose weight is below the resolution of the cumulative weights has a zero-width interval, and rounding in the reference offset can step past a narrow one. The reference slot is now assigned directly on CPU and GPU. This corrects rounding only; the law of the remaining slots is unchanged.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #202 +/- ##
==========================================
+ Coverage 71.95% 71.97% +0.02%
==========================================
Files 104 104
Lines 4136 4157 +21
==========================================
+ Hits 2976 2992 +16
- Misses 1160 1165 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Systematic and stratified resampling scan the scaled cumulative weights
vs = n * cumsum(w)withwhile vs[idx] <= uand no upper bound, inside@inbounds. When rounding puts a threshold at or beyondvs[end], the loop reads past the array. With 4096 exactly uniform Float32 weights andXoshiro(3459),--check-bounds=yesthrows aBoundsErrorat index 4097; without bounds checking the returned maximum ancestor was 4117.Probing the conditional variants found a related defect. They could return
idxs[1] != ref_idx, breaking the contract that conditional SMC relies on. With 64 particles and skewed weights (rand^4, normalised), the reference was lost in:Most losses are references whose weight is below the resolution of the cumulative weights, so their interval has zero width. The rest come from rounding in the reference offset, which can step past a narrow interval.
Changes:
vs .*= n).Tests added, independent of RNG stream:
1f-10between two halves, on CPU and GPU.All fail before the fix and pass after it. The full CPU suite passes locally (3351 tests), as does
test/components/resamplers.jlincluding GPU items on an RTX 4090.