-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix broken negative binomial sampling #328
Conversation
Co-authored-by: bbbruce <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #328 +/- ##
==========================================
+ Coverage 94.40% 94.93% +0.52%
==========================================
Files 59 59
Lines 13432 13448 +16
==========================================
+ Hits 12681 12767 +86
+ Misses 751 681 -70 ☔ View full report in Codecov by Sentry. |
Thanks for catching this! |
@@ -487,4 +487,25 @@ mod tests { | |||
let sf = |arg: u64| move |x: NegativeBinomial| x.sf(arg); | |||
test_absolute(3.0, 0.5, 5.282409836586059e-28, 1e-28, sf(100)); | |||
} | |||
|
|||
#[test] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for seeding so we don't have a flaky test! Would you be able to wrap this test with a cfg
so that it only compiles with the rand
feature?
let theoretical_mean = dist.mean().unwrap(); | ||
let theoretical_variance = dist.variance().unwrap(); | ||
|
||
assert!(prec::almost_eq(sample_mean, theoretical_mean, tol)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an optional suggestion here, would you use the hypothesis testing module to verify this sampler? I'd use chi square GoF. If not, I was thinking of adding these kinds of tests for sampling over time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea - will keep in mind to add over time as possible
The only failing test is an unrelated one we're working on in #325, thanks for contributing a fix! |
Description
The negative binomial distribution sampler is not working because
gamma
is parameterized to sample usingrate
rather thanscale
. The original input was the scale as a function ofself.p
leading to incorrect samples for the specified distribution. Thesample_unchecked
is now supplied with the rate calculated fromself.p
and a test is provided to ensure behavior is in agreement with the theoretical mean and variance of the specified distribution.