statistics
statistics copied to clipboard
Shouldn't be possible to create random variates from Poisson distribution?
Right now it seems not possible due to how DiscreteGen/ContGen typeclasses are defined.
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(λ)] = λ
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