packages feed

mwc-probability 2.0.1 → 2.0.2

raw patch · 3 files changed

+20/−3 lines, 3 files

Files

CHANGELOG view
@@ -1,5 +1,8 @@ 	# Changelog +	- 2.0.2 (2018-01-30)+	* Add negative binomial distribution+ 	- 2.0.1 (2018-01-30) 	* Add Normal-Gamma and Pareto distributions 
mwc-probability.cabal view
@@ -1,5 +1,5 @@ name:                mwc-probability-version:             2.0.1+version:             2.0.2 homepage:            http://github.com/jtobin/mwc-probability license:             MIT license-file:        LICENSE
src/System/Random/MWC/Probability.hs view
@@ -53,6 +53,10 @@ -- -- which will be reused throughout all examples. -- Note: creating a random generator is an expensive operation, so it should be only performed once in the code (usually in the top-level IO action, e.g `main`).+--+-- == References+--+-- 1) L.Devroye, Non-Uniform Random Variate Generation, Springer-Verlag, New York, 1986. (Made freely available by the author: http://www.nrbook.com/devroye )   module System.Random.MWC.Probability (@@ -87,6 +91,7 @@   , categorical   , bernoulli   , binomial+  , negativeBinomial   , multinomial   , poisson   @@ -295,6 +300,16 @@ binomial n p = fmap (length . filter id) $ replicateM n (bernoulli p) {-# INLINABLE binomial #-} +-- | The negative binomial distribution with `n` trials each with "success" probability `p`.+-- Example X.1.5 in [1].+--+-- Note: `n` must be larger than 1 and `p` included between 0 and 1.+negativeBinomial :: (PrimMonad m, Integral a) => a -> Double -> Prob m Int+negativeBinomial n p = do+  y <- gamma (fromIntegral n) ((1-p) / p)+  poisson y+{-# INLINABLE negativeBinomial #-}+ -- | The multinomial distribution. multinomial :: (Foldable f, PrimMonad m) => Int -> f Double -> Prob m [Int] multinomial n ps = do@@ -336,8 +351,7 @@   -- | The Zipf-Mandelbrot distribution, generated with the rejection--- sampling algorithm X.6.1 shown in--- L.Devroye, Non-Uniform Random Variate Generation.+-- sampling algorithm X.6.1 shown in [1]. -- -- The parameter should be positive, but values close to 1 should be -- avoided as they are very computationally intensive. The following