packages feed

mwc-probability 2.0.2 → 2.0.3

raw patch · 4 files changed

+71/−16 lines, 4 files

Files

CHANGELOG view
@@ -1,5 +1,8 @@ 	# Changelog +	- 2.0.3 (2018-05-09)+	* Add inverse Gaussian (Wald) distribution+	 	- 2.0.2 (2018-01-30) 	* Add negative binomial distribution 
README.md view
@@ -13,28 +13,62 @@ state-passing automatically by using a `PrimMonad` like `IO` or `ST s` under the hood. + Examples -------- -Transform a distribution's support while leaving its density structure+* Transform a distribution's support while leaving its density structure invariant: -    -- uniform over [0, 1] to uniform over [1, 2]-    succ <$> uniform+      -- uniform over [0, 1] transformed to uniform over [1, 2]+      succ <$> uniform -Sequence distributions together using bind:+* Sequence distributions together using bind: -    -- a beta-binomial composite distribution-    beta 1 10 >>= binomial 10+      -- a beta-binomial composite distribution+      beta 1 10 >>= binomial 10 -Use do-notation to build complex joint distributions from composable,+* Use do-notation to build complex joint distributions from composable, local conditionals: -    hierarchicalModel = do-      [c, d, e, f] <- replicateM 4 $ uniformR (1, 10)-      a <- gamma c d-      b <- gamma e f-      p <- beta a b-      n <- uniformR (5, 10)-      binomial n p+      hierarchicalModel = do+        [c, d, e, f] <- replicateM 4 $ uniformR (1, 10)+        a <- gamma c d+        b <- gamma e f+        p <- beta a b+        n <- uniformR (5, 10)+        binomial n p +++Included probability distributions+-------------++* Continuous++  * Uniform+  * Normal+  * Log-Normal+  * Exponential+  * Inverse Gaussian+  * Laplace+  * Gamma+  * Inverse Gamma+  * Weibull+  * Chi-squared+  * Beta+  * Student t+  * Pareto+  * Dirichlet process+  * Symmetric Dirichlet process  ++* Discrete++  * Discrete uniform+  * Zipf-Mandelbrot+  * Categorical+  * Bernoulli+  * Binomial+  * Negative Binomial+  * Multinomial+  * Poisson
mwc-probability.cabal view
@@ -1,5 +1,5 @@ name:                mwc-probability-version:             2.0.2+version:             2.0.3 homepage:            http://github.com/jtobin/mwc-probability license:             MIT license-file:        LICENSE@@ -8,7 +8,7 @@ category:            Math build-type:          Simple cabal-version:       >= 1.10-tested-with:         GHC == 8.0.2, GHC == 8.2.2                     +tested-with:         GHC == 8.0.2, GHC == 8.2.2 , GHC == 8.4.2 synopsis:            Sampling function-based probability distributions. description: 
src/System/Random/MWC/Probability.hs view
@@ -73,6 +73,7 @@   , isoNormal       , logNormal   , exponential+  , inverseGaussian   , laplace   , gamma   , inverseGamma@@ -333,6 +334,23 @@   :: (Traversable f, PrimMonad m) => f Double -> Double -> Prob m (f Double) isoNormal ms sd = traverse (`normal` sd) ms {-# INLINABLE isoNormal #-}++-- | The inverse Gaussian (also known as Wald) distribution.+--+-- Both the mean parameter 'mu' and the shape parameter 'lambda' must be positive.+inverseGaussian :: PrimMonad m => Double -> Double -> Prob m Double+inverseGaussian lambda mu = do+  nu <- standardNormal+  let y = nu ** 2+      s =  sqrt (4 * mu * lambda * y + mu ** 2  * y ** 2)+      x = mu * (1 + 1 / (2 * lambda) * (mu * y - s))+      thresh = mu / (mu + x)+  z <- uniform+  if z <= thresh+    then return x+    else return (mu ** 2 / x)+{-# INLINABLE inverseGaussian #-}    +    -- | The Poisson distribution. poisson :: PrimMonad m => Double -> Prob m Int