statistics icon indicating copy to clipboard operation
statistics copied to clipboard

Shouldn't be possible to create random variates from Poisson distribution?

Open jarandaf opened this issue 8 years ago • 2 comments

Right now it seems not possible due to how DiscreteGen/ContGen typeclasses are defined.

jarandaf avatar Aug 23 '17 17:08 jarandaf

Hi, I wanted to open a PR but I am not used to cabal but stack instead 😅. The following would be a possible solution although I am not sure about its performance.

import qualified Statistics.Distribution as D
import Statistics.Distribution.Poisson
import System.Random.MWC.CondensedTable (genFromTable, tablePoisson)

instance D.ContGen PoissonDistribution where
    genContVar p gen = fmap fromIntegral (genFromTable tPoisson gen)
      where poi = poissonLambda p
            tPoisson = tablePoisson poi

instance D.DiscreteGen PoissonDistribution where
    genDiscreteVar p gen = fmap round (D.genContVar p gen)

A simple test could be written since in average, E[X ~ Poisson(λ)] = λ

jarandaf avatar Aug 29 '17 17:08 jarandaf

Problem with this approach is performance. Table takes some time to build and it only worth it if a lot of sample are generated. There's issue in mwc-random for that: https://github.com/bos/mwc-random/issues/27

Also you can build statistics with stack just as well. There isn't stack.yaml in repo but that's all

Shimuuar avatar Sep 28 '17 13:09 Shimuuar