-
Notifications
You must be signed in to change notification settings - Fork 7
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
Numeric fixes for extremely large shape parameters #305
Conversation
* Refactor DLMF15.8.3 to avoid cancellation * Match mean and variance as backup
I agree with the If an overly large shape parameter causes the routines to fail in a consistent way, perhaps we can catch that in an |
This is good to go @hyanwong |
Thanks. LGTM, from what I understand of how it all works. Happy to merge. |
P.s. do you think that it is worth mentioning in the error message that you can re-try with |
Hmm, with inferred tree sequences there will generally be some nodes that have funky updates and need the failsafe routine. But, there's no need to set max_shape in these cases -- really only when mpmath is invoked frequently and it requires lots of terms to converge. Two options are:
At some point (when we have a control dict implemented) there'll be a lot of flexibility wrt mpmath settings, as well as the homegrown 2F1. |
I went with the first option-- does the error blurb seem reasonable @hyanwong? |
SGTM. Merging. |
max_shape
) to a predetermined value of the shape parameter.The cap on the shape parameter basically says, "this approximation is extremely precise, but we'll only let it get this precise so that the distribution doesn't degenerate". This is akin to setting a minimum variance, except that the shape parameterization is scale invariant. By default,
max_shape
should be None, because if the shape parameters do get extremely large (e.g. the approximation degenerates) then that tells us that there's some inconsistency in the topology that makes dating difficult. For example, this can occur when there are unary nodes from tsinfer that span nearly the entire tree sequence (e.g. all root nodes would have to be older than these "global" unary nodes) which introduce very unnatural constraints. However, for debugging purposes it's nice to be able to cap the gamma shape so the program doesn't error out.