Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jarandaf opened this issue Aug 23, 2017 · 2 comments
Open

Comments

@jarandaf
Copy link

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

@jarandaf
Copy link
Author

jarandaf commented Aug 29, 2017

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(λ)] = λ

@Shimuuar
Copy link
Collaborator

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: haskell/mwc-random#27

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants