STATISTICS-92: TruncatedNormalDistribution rejection-sampler uses incorrect bounds for mirroring checl#125
Merged
aherbert merged 3 commits intoapache:masterfrom Mar 16, 2026
Conversation
Contributor
|
Thanks for the fix. I added some test files to the JIRA report that fail the current build. Can you add them to this PR please. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #125 +/- ##
============================================
+ Coverage 99.62% 99.70% +0.08%
+ Complexity 2441 647 -1794
============================================
Files 116 120 +4
Lines 6087 6403 +316
Branches 951 967 +16
============================================
+ Hits 6064 6384 +320
+ Misses 10 6 -4
Partials 13 13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Added, thanks @aherbert! |
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.
Fix for STATISTICS-92. This corrects the rejection sampler mirroring test in
TruncatedNormalDistributionto use the standard normal bounds rather than the original bounds.As is, when
mean > 0,lower > 0,lower < mean, andupper > mean, samples are only returned that are> mean. For example, here is the distribution for:ContinuousDistribution dist = TruncatedNormalDistribution.of(1, 0.1, 0.7, 1.3).createSampler(RandomSource.XO_RO_SHI_RO_128_PP.create(123456l));The black histogram is the current implementation and the orange histogram is with this fix.
And when
mean > 0,lower > 0,lower < mean, andupper < mean, the sampler gets stuck in an infinite loop.The same is true on the negative side, for example:
ContinuousDistribution dist = TruncatedNormalDistribution.of(-1, 0.1, -1.3, -0.7).createSampler(RandomSource.XO_RO_SHI_RO_128_PP.create(123456l));The fix is simple. I also added tests that detect the infinite loop cases with a timeout of 1 second; they fail with the current implementation, and pass with the fix. I could add tests for the other cases that don't trigger the infinite loop, for example, to ensure that values on either side of the mean are correctly sampled, but I'm not sure your policy on tests that rely on randomness (even with fixed seeds). The tests that I added demonstrate the issue and cannot suceed with the current implementation. Let me know if you would like any changes!