-
Notifications
You must be signed in to change notification settings - Fork 231
Prevent passing denormals in calculation. #1141
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
Conversation
when checking for small values.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1141 +/- ##
===========================================
+ Coverage 93.69% 93.71% +0.02%
===========================================
Files 772 774 +2
Lines 61168 61271 +103
===========================================
+ Hits 57311 57422 +111
+ Misses 3857 3849 -8
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Fix exp_sinh issues so that it does actually find the integral.
Lot's more tests, especially in the tails. Added Hypergeometric and Integration methods as fallbacks.
@jzmaddock : this looks impressive! One question for the addition to scipy. Do you have an external source for reference values for the noncentral T PDF? I did not check the complete (large) testing diff, might have missed it. If not, I would implement the formula currently used in scipy with the high precision mpmath python library. |
|
||
struct nc_t_pdf_gen | ||
{ | ||
mp_t operator()(mp_t v, mp_t mu, mp_t x) |
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.
Ah, this might be arbitrary precision implementation boost style that generates the test values after all?
Nod. I used the hypergeometric formula and multiprecision arithmetic for the new test values. One thing I should have mentioned: the integration method though accurate, is about 10x slower than the alternatives :( Other than truncation to zero, there really is no alternative though... as I'm typing though I'm just wondering if wolframalpha would generate a series for the integral... |
I'm not all that familiar with this function but I've recently been doing a lot of computer algebra for Series and Pade approximants in other projects. Does anyone have a link to representation of the integral mentioned? I coould try for an approximation. |
Cool, it's:
Which is the integral part of this formula https://wikimedia.org/api/rest_v1/media/math/render/svg/0059c7e6e3afb0e4496fecdcb3b85296c162f065 Ideally we need this whenever |
The first thing I tried is the exponent part alone without integrating over W-Alpha didn't do it. I needed a bit more power and I ended up doing this first try locally.
Note that we use Here is a picture of the input and its output. |
Actually, @jzmaddock I don't know if expanding at |
Since we're really interested in x < 0, I would say expansion either at x == 0 or x = -infinity would be better? I also note that the curve being integrated, is extremely "pointy" - all the area is located in a tiny area - so this might be getting out of hand, but a series around the maxima (for y) would be optimal I guess? If we fix the SciPy test case, with x = -1, v = 8 and mu=16 then https://www.wolframalpha.com/input?i=x%5E8+exp%28%28%28x+-+16+*+-1+%2F+sqrt%281+%2B+8%29%29%29%5E2+%2F+-2%29%3B shows the curve nicely, most of the peak in this case is outside of [0, INF] but that's not always the case. Interestingly, with all the variables fixed like this, wolfram alpha gives a simple(-ish) closed form for the integral, and for the summit of the curve. Does this help at all? Possibly not, since evaluating the definite integral in this case is the difference between two large values? The best way to sanity check the series would be against the integral itself:
Extracted from non_central_t.hpp. |
Hi John (@jzmaddock) OK I am getting closer. I just tried:
and received a closed form answer. |
There seems to be something wrong there if the answer depends only on x^2 ? |
I think it should have been |
Geez this is challenging. Like this then...
Whith the following answer. But I think there are some very large terms and this is numerically unstable. I haven't quite figured out what to do with that yet. I'll try off and onn. Does not seem to be critical. If I ever come up with something, I'll report. |
Well the good news is that 2.29e-9 is the correct answer ;) But yes, you've basically re-invented the hypergeometric approximation, and the cancellation is indeed terrible :( We might well be out of ideas at this point, but I appreciate the effort! |
I tried expanding in parameters - the first trick of asymptotics. Expanding in You know, this would be a great spot for the infamous Other than that, I'm out of ideas also. |
The issue with the hypergeomentrics is that when v is small, the largest term in the hypergeometric series is of the order |
Indeed. I even tried expansion in
Yes. Thanks John. I'll hang up my hat on this one now. |
Refs scipy/scipy#20693