Skip to content
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

invIncompleteBeta fails for some (exotic) inputs #29

Open
Shimuuar opened this issue May 17, 2016 · 1 comment
Open

invIncompleteBeta fails for some (exotic) inputs #29

Shimuuar opened this issue May 17, 2016 · 1 comment
Labels

Comments

@Shimuuar
Copy link
Collaborator

*Numeric.SpecFunctions.Internal> invIncompleteBeta 9 2 1e-300
*** Exception: Numeric.SpecFunctions.incompletBeta_: x out of [0,1] range. p=9.0 q=2.0 x=NaN

It fails in Halley step when derivative of incomplete beta underflows and becomes zero so no next approximation could be computed, It happens for large a and small x.

@Shimuuar Shimuuar added the bug label May 18, 2016
@Shimuuar
Copy link
Collaborator Author

Shimuuar commented Jul 4, 2016

Problem is underflow in derivative of incomplete beta which becomes zero and next Halley correction becomes NaN. Naive solution is to revert to bisection. But convergence is slow so function gives answers which are several orders of magnitude off.

Attempted fix:

      -- When derivative is equal to zero (actually underflows since
      -- it's always positive) we cannot make Newton iteration so we
      -- have to switch to bisection
      | f' == 0                      = case () of
        _| f > 0                     -> loop (i+1) (x / 2)
         | f == 0                    -> x
         | otherwise                 -> loop (i+1) ((1 + x) / 2)
      -- When derivative becomes infinite we cannot continue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant