haskell / math-functions

Special mathematical functions
http://hackage.haskell.org/package/math-functions
BSD 2-Clause "Simplified" License
41 stars 28 forks source link

invIncompleteBeta throwing errors for valid inputs #68

Closed samstaton closed 3 years ago

samstaton commented 3 years ago

For example,

Haskell> invIncompleteBeta 1 0.5 0.3
0.5100000000000005
Haskell> invIncompleteBeta 1 0.3 0.3
*** Exception: Numeric.SpecFunctions.incompleteBeta_: x out of [0,1] range. p=1.0 q=0.3 x=1.0000000000000002
CallStack (from HasCallStack):
  error, called at ./Numeric/SpecFunctions/Internal.hs:1157:14 in math-functions-0.3.4.1-95MJpYGsyAREIaxHMcDvh3:Numeric.SpecFunctions.Internal
Haskell> invIncompleteBeta 1 0.1 0.3
*** Exception: Numeric.SpecFunctions.incompleteBeta_: x out of [0,1] range. p=1.0 q=0.1 x=2.9999999999999996
CallStack (from HasCallStack):
  error, called at ./Numeric/SpecFunctions/Internal.hs:1157:14 in math-functions-0.3.4.1-95MJpYGsyAREIaxHMcDvh3:Numeric.SpecFunctions.Internal

Sorry, I haven't yet figured out what is wrong with the implementation in SpecFunctions. But these are common arguments for invIncompleteBeta when used for sampling from the beta distribution (e.g. via Statistics.Distribution.Beta).

Shimuuar commented 3 years ago

Thanks for the report! Most likely it happens when solving equation and update takes solution out of [0,1] range. I'll look into it tomorrow

P.S. invIncompleteBeta is most troublesome function of all.

Shimuuar commented 3 years ago

0.3.4.2 with bugfix is on hackage.

P.S. It takes 1 hour to find bug and 3 days to fix CI..