haskell / statistics

A fast, high quality library for computing with statistics in Haskell.
http://hackage.haskell.org/package/statistics
BSD 2-Clause "Simplified" License
300 stars 68 forks source link

Test failure "Quantile is CDF inverse" #169

Closed sjakobi closed 2 years ago

sjakobi commented 4 years ago
      Quantile is CDF inverse:                                                               FAIL
        *** Failed! Falsified (after 20 tests):
        improperGammaDistr 8.078186019792698 9.877105048646426
        Double01 0.47842987214924804
        Quantile      = 75.04977575136812
        Probability   = 0.47842987214924804
        Probability'  = 0.47842987214925126
        Rel. error    = 6.72961066780661e-15
        Abs. error    = 3.219646771412954e-15
        Expected err. = 52.978171024074584
        Distance      = 58
        Err/est       = 1.094790531248113
        Use --quickcheck-replay=248001 to reproduce.

https://travis-ci.org/github/haskell-nix/hnix/jobs/707980815#L7818-L7830


EDIT: Hmm, maybe I shouldn't have restarted that Travis job. ;)

Version info:

Anton-Latukha commented 4 years ago

(I am also from the HNix project downstream): Obviously, the quickcheck seed is preserved, so most probably it can be tested/addressed even without preserved log.

Shimuuar commented 4 years ago

Here is plot for roundtrip error for gamma distribution:

image

Cumulative and quantile are basically incompleteGamme + its inverse. So it seems problem is in incompleteGamma function. My hunch we terminate series summation before it converges (or lose too much precision). Zig-zag pattern looks like we change parameter to incompleteGamma and add another term to expansion which pushes error down. Then it starts to decay again

Shimuuar commented 4 years ago

Most likely it's problem with incomplete gamma function from math-functions. I improved its precision quite a bit and will revisit this issue when I make new release.