mwc-probability

Sampling function-based probability distributions.
Log | Files | Refs | README | LICENSE

commit aaeb8f599c1aa4c70c2971244ef4edd63e779344
parent 85e50c05844677201ae38e4ea66da2ffb306c15a
Author: Jared Tobin <jared@jtobin.ca>
Date:   Fri, 10 Apr 2015 14:18:58 +1200

Add poisson generator.

Diffstat:
Mmwc-probability.cabal | 2+-
Msrc/System/Random/MWC/Probability.hs | 7+++++++
2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/mwc-probability.cabal b/mwc-probability.cabal @@ -1,5 +1,5 @@ name: mwc-probability -version: 0.3.1.0 +version: 0.3.2.0 homepage: http://github.com/jtobin/mwc-probability license: MIT license-file: LICENSE diff --git a/src/System/Random/MWC/Probability.hs b/src/System/Random/MWC/Probability.hs @@ -21,6 +21,7 @@ module System.Random.MWC.Probability ( , multinomial , t , isoGauss + , poisson ) where import Control.Applicative @@ -31,6 +32,7 @@ import Data.List (findIndex) import System.Random.MWC as MWC hiding (uniform, uniformR) import qualified System.Random.MWC as QMWC import qualified System.Random.MWC.Distributions as MWC.Dist +import System.Random.MWC.CondensedTable newtype Prob m a = Prob { sample :: Gen (PrimState m) -> m a } @@ -142,3 +144,8 @@ isoGauss :: PrimMonad m => [Double] -> Double -> Prob m [Double] isoGauss ms sd = mapM (\m -> normal m sd) ms {-# INLINE isoGauss #-} +poisson :: PrimMonad m => Double -> Prob m Int +poisson l = Prob $ genFromTable table where + table = tablePoisson l +{-# INLINE poisson #-} +