-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
The way neg_binomial_2_lpmf delegates to Poisson is broken #1496
Comments
It gets even more funny - the cutoff is implemented as
Note the |
That's just a flat-out bug. The conditional should have been at the top of the loop and have the rest of the body of the loop in the alternative branch. Thanks for tracking this down! |
On Dec 9, 2019, at 12:42 PM, Martin Modrák ***@***.***> wrote:
It gets even more funny - the cutoff is implemented as
// if phi is large we probably overflow, defer to Poisson:
if (phi__[i] > 1e5) {
logp = poisson_lpmf(n_vec[i], mu__[i]);
}
Note the =!!!
That's just a flat-out bug.
… So when a single element of a vector provokes cutoff, it overwrites the logp accumulator. Also, the way poisson_lpmf is called means that the propto information cannot be conserved and thus the final logp will wildly change around the cutoff under certain propto combinations. On the same branch I wrote a failing test for this behavior as well.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
One thing I discovered when working on this is that This would (probably) let us lower the threshold and use the simpler derivatives for smaller Does anybody have any opinion on this? I am slightly reluctant to add this as the current test coverage of the neg. binomial seems not really great... |
Update: tested with the additional term, doesn't allow me to reduce the cutoff. |
So I probably spent more time than I have with this, will probably be able to continue only after Christmas, maybe somebody else could look into it. It appears that the I also failed to get the finite differences test to pass, though I am not sure what could have triggered its failures, as it fails for |
1e-5 relative errors of autodiff relative to someone's else's numerical eval or to finite diffs? The latter should be fine.
… On Dec 10, 2019, at 10:01 AM, Martin Modrák ***@***.***> wrote:
So I probably spent more time than I have with this, will probably be able to continue only after Christmas, maybe somebody else could look into it.
It appears that the neg_binomial_2_lpmf is riddled with small numerical issues. I wrote more tests for the branch (as seen in the PR: #1497). There are some numerical differences between the values and derivatives as we compute them and what I get from Mathematica (the biggest relative errors are on the order of 10^-5, not sure if this can be ignored).
I also failed to get the finite differences test to pass, though I am not sure what could have triggered its failures, as it fails for phi values before cutoff where I didn't make big changes.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Moving the discussion from here to the PR #1497 - as it IMHO relates more to the code than to the issue. |
Description
The
neg_binomial_2_lpmf
delegates topoisson_lpmf
for large values of thephi
parameter. Currently the cutoff is set atphi > 1e5
. This introduces discontinuities into the function - I am nut sure whether this is because the cutoff is too optimistic or too pessimistic.Example
I've written a failing test for the cutoff at: develop...martinmodrak:bugfix/1496-poisson-phi-cutoff
Expected Output
Values at
cutoff - 1e-8
andcutoff + 1e-8
are almost constant, i.e. changes inphi
no longer influence the lpmf value and delegating to Poisson is safe.Current Version:
v3.0.0
The text was updated successfully, but these errors were encountered: