haskell / math-functions

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

Bad initial guess for invIncompleteBeta #35

Closed Shimuuar closed 8 years ago

Shimuuar commented 8 years ago

invIncompleteBeta 7 0.07 2.865e-7 fails to converge in 10 iterations and needs 39 to get correct answer. Approximation used:

      -- Otherwise we revert to approximation from AS64 derived from
      -- [AS64 2] when it's applicable.
      --
      -- It slightly reduces average number of iterations when `a' and
      -- `b' have different magnitudes.
      | chi2 > 0 && ratio > 1 = 1 - 2 / (ratio + 1)
Shimuuar commented 8 years ago

More thorough investigation shows that convergence problems are quite frequent and pervasive.

For a>1 and b>1 Carter approximation is used. Overall it behaves well but for big a and b≈1 it behaves poorly. Here is plot for maximum number of iterations needed for convergence for a,b:

download

download

Otherwise approximations from AS64 and numerical recipes are used. Both have areas where initial guess is very poor and large number of iterations is needed.

Shimuuar commented 8 years ago

Fixed in 8214bc3ddbb1ae01830f22d876409e9e662632c4, 4d8e69797304ea8620a5659331d6ed915fc94ceb, 378d6702999d4259fa1acea6b69b368f5e506bb5