mwc-probability

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

commit e80786aabc984983e5fab3a5d5f38b28f26b2f81
parent 7610014d89306c99cb1ea9c8a866f83d71360405
Author: Jared Tobin <jared@jtobin.ca>
Date:   Tue,  6 Oct 2015 17:15:30 +1300

1.0 Update.

Diffstat:
MLICENSE | 2+-
Mmwc-probability.cabal | 2+-
Msrc/System/Random/MWC/Probability.hs | 13+++++++------
3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014 Jared Tobin +Copyright (c) 2014-2015 Jared Tobin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/mwc-probability.cabal b/mwc-probability.cabal @@ -1,5 +1,5 @@ name: mwc-probability -version: 0.3.4.0 +version: 1.0.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 @@ -22,7 +22,7 @@ module System.Random.MWC.Probability ( , bernoulli , binomial , multinomial - , t + , student , isoGauss , poisson ) where @@ -40,8 +40,9 @@ import System.Random.MWC.CondensedTable -- | A probability distribution characterized by a sampling function. newtype Prob m a = Prob { sample :: Gen (PrimState m) -> m a } -samples :: PrimMonad m => Prob m a -> Int -> Gen (PrimState m) -> m [a] -samples model n gen = replicateM n (sample model gen) +-- | Sample from a model 'n' times. +samples :: PrimMonad m => Int -> Prob m a -> Gen (PrimState m) -> m [a] +samples n model gen = replicateM n (sample model gen) instance Monad m => Functor (Prob m) where fmap h (Prob f) = Prob $ liftM h . f @@ -127,13 +128,13 @@ multinomial n ps = do let Just g = findIndex (> z) cumulative return g -t :: PrimMonad m => Double -> Double -> Double -> Prob m Double -t m s k = do +student :: PrimMonad m => Double -> Double -> Double -> Prob m Double +student m s k = do sd <- sqrt <$> inverseGamma (k / 2) (s * 2 / k) normal m sd isoGauss :: PrimMonad m => [Double] -> Double -> Prob m [Double] -isoGauss ms sd = mapM (\m -> normal m sd) ms +isoGauss ms sd = mapM (`normal` sd) ms poisson :: PrimMonad m => Double -> Prob m Int poisson l = Prob $ genFromTable table where