mwc-probability

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

commit 883b1580a49a513eae0e01874313d67d1530d7ac
parent 0f4f58b2aa1d0e9731555645d299f0a5d93d2377
Author: Jared Tobin <jared@jtobin.io>
Date:   Fri, 26 Jan 2018 10:14:19 +1300

Merge pull request #5 from ocramz/master

Add Laplace distribution
Diffstat:
Msrc/System/Random/MWC/Probability.hs | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/System/Random/MWC/Probability.hs b/src/System/Random/MWC/Probability.hs @@ -58,6 +58,7 @@ module System.Random.MWC.Probability ( , normal , logNormal , exponential + , laplace , gamma , inverseGamma , chiSquare @@ -188,6 +189,15 @@ exponential :: PrimMonad m => Double -> Prob m Double exponential r = Prob $ MWC.Dist.exponential r {-# INLINABLE exponential #-} +-- | The Laplace distribution with provided location and scale parameters. +laplace :: (Floating a, Variate a, PrimMonad m) => a -> a -> Prob m a +laplace mu sigma = do + u <- uniformR (-0.5, 0.5) + let b = sigma / sqrt 2 + return $ mu - b * signum u * log (1 - 2 * abs u) +{-# INLINABLE laplace #-} + + -- | The gamma distribution with shape parameter a and scale parameter b. -- -- This is the parameterization used more traditionally in frequentist