mwc-probability

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

commit f3089411a06ee133fa410e820c3856d2715a0adf
parent 016183757f1fa9dba2b2a95047215d36de9cbcea
Author: Marco Zocca <marco.zocca@recordunion.com>
Date:   Tue, 30 Jan 2018 10:04:38 +0100

add normalGamma

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 @@ -72,6 +72,7 @@ module System.Random.MWC.Probability ( , laplace , gamma , inverseGamma + , normalGamma , weibull , chiSquare , beta @@ -221,6 +222,7 @@ weibull :: (Floating a, Variate a, PrimMonad m) => a -> a -> Prob m a weibull a b = do x <- uniform return $ (- 1/a * log (1 - x)) ** 1/b +{-# INLINABLE weibull #-} -- | The gamma distribution with shape parameter a and scale parameter b. @@ -239,6 +241,14 @@ inverseGamma :: PrimMonad m => Double -> Double -> Prob m Double inverseGamma a b = recip <$> gamma a b {-# INLINABLE inverseGamma #-} +-- | The Normal-Gamma distribution of parameters mu, lambda, a, b +normalGamma :: PrimMonad m => Double -> Double -> Double -> Double -> Prob m Double +normalGamma mu lambda a b = do + tau <- gamma a b + let xsd = sqrt $ 1 / (lambda * tau) + normal mu xsd +{-# INLINABLE normalGamma #-} + -- | The chi-square distribution. chiSquare :: PrimMonad m => Int -> Prob m Double chiSquare k = Prob $ MWC.Dist.chiSquare k