mwc-probability

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

commit 05dea6d89dd0b43f6315e25e966d46aae5d1000d
parent 01e0a01083a3fe4c936401a57b511bb3bf544ffd
Author: Marco Zocca <marco.zocca@recordunion.com>
Date:   Mon, 29 Jan 2018 20:00:37 +0100

fixed typesig of zipf, not sure about correctness

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

diff --git a/src/System/Random/MWC/Probability.hs b/src/System/Random/MWC/Probability.hs @@ -65,7 +65,9 @@ module System.Random.MWC.Probability ( , chiSquare , beta , student - + -- *** Dirichlet process + , dirichlet + , symmetricDirichlet -- ** Discrete-valued , discreteUniform , zipf @@ -74,9 +76,7 @@ module System.Random.MWC.Probability ( , binomial , multinomial , poisson - -- ** Dirichlet process - , dirichlet - , symmetricDirichlet + ) where @@ -296,18 +296,18 @@ categorical ps = do {-# INLINABLE categorical #-} --- | The Zipf distribution, generated with the rejection sampling algorithm X.6.1 shown in L.Devroye, Non-Uniform Random Variate Generation. -zipf :: (Floating b, PrimMonad m, Variate b, Integral a, RealFrac b) => a -> Prob m b -zipf a' = do +-- | The Zipf-Mandelbrot distribution, generated with the rejection sampling algorithm X.6.1 shown in L.Devroye, Non-Uniform Random Variate Generation. +zipf :: (PrimMonad m, Integral b) => Double -> Prob m b +zipf a = do let - a = fromIntegral a' b = 2**(a - 1) go = do u <- uniform v <- uniform - let x = fromIntegral (floor (u**(-1/(a-1))) :: Int) + let xInt = floor (u**(-1/(a-1))) + x = fromIntegral xInt t = (1 + 1/x)**(a-1) if v*x*(t-1)/(b-1) <= t/b - then return x else go + then return xInt else go go {-# INLINABLE zipf #-}