haskell / mwc-random

A very fast Haskell library for generating high quality pseudo-random numbers.
http://hackage.haskell.org/package/mwc-random
BSD 2-Clause "Simplified" License
55 stars 25 forks source link

Condensed table for Poisson distribution is broken for λ>=1923 #59

Closed Shimuuar closed 7 years ago

Shimuuar commented 7 years ago

tablePoisson can create table without problem if λ<1923. Otherwise it never finishes and consumes a LOT of memory

Shimuuar commented 7 years ago

Function hangs in tablePoisson. Double overflow(?) during calculations of pMax

cspollard commented 7 years ago

Can confirm. I have a switch to use a normal distribution for lambda > 1000.

Shimuuar commented 7 years ago

I've just pushed fix to master. It's not tested but should work. Could you test that it works for you please?

cspollard commented 7 years ago

I'm having some trouble building (likely just me being a novice!)

I needed to add a vector dependency in benchmarks/mwc-random-benchmarks.cabal, after which I get a lot of errors like

/mwc-random.git/benchmarks/Benchmark.hs:110:25: error:
        • Couldn't match expected type ‘Benchmarkable’
                      with actual type ‘IO Double’
        • In the second argument of ‘bench’, namely
            ‘(M.random mtg :: IO Double)’
          In the expression: bench "Double" (M.random mtg :: IO Double)
          In the second argument of ‘bgroup’, namely
            ‘[bench "Double" (M.random mtg :: IO Double),
              bench "Int" (M.random mtg :: IO Int)]’

Is there a way to disable the benchmarking while building?

Shimuuar commented 7 years ago

How do you build it? Cabal by default doesn't enable building of benchmarks.

One way is to add buildable: False to benchmarks field in cabal file

cspollard commented 7 years ago

Sorry I am new enough to haskell that I have only ever really built things with stack. The build works just fine if I check out the head and point stack to the local copy from another local package.

I can confirm that

print =<< (withSystemRandom . asGenIO . samples 100 $ poisson 5000)

is almost instant with the head and basically uses infinite memory (and time) in 0.13.5.0 (from lts-8.12).

Once again, thank you very much! If there are any novice-friendly bugs/improvements that you are looking for help with, please let me know. I am taking advantage of several of the libraries you maintain, so happy to give back as best I can.

Chris

Shimuuar commented 7 years ago

I finally got to testing fix. it's uploaded as 0.13.6.0

There're number of bugs for math-functions and statistics which are marked as "help needed". It means that I don't have time to implement new feature. It doesn't mean that they're easy though. Math-function' issues are complicated except one for completing benchmark. Ones from statistics should be relatively easy. And of course bug report and any other feedback is always welcom