packages feed

splitmix-distributions 0.4.0.0 → 0.5.0.0

raw patch · 3 files changed

+48/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ System.Random.SplitMix.Distributions: laplace :: Monad m => Double -> Double -> GenT m Double
+ System.Random.SplitMix.Distributions: logNormal :: Monad m => Double -> Double -> GenT m Double
+ System.Random.SplitMix.Distributions: weibull :: Monad m => Double -> Double -> GenT m Double

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+0.5 :++- add Log-normal, Laplace, Weibull distributions+ 0.4 :  - add Discrete, Categorical, Zipf-Mandelbrot distributions
splitmix-distributions.cabal view
@@ -1,5 +1,5 @@ name:           splitmix-distributions-version:        0.4.0.0+version:        0.5.0.0 description:    Random samplers for some common distributions, as well as a convenient interface for composing them, based on splitmix. Please see the README on GitHub at <https://github.com/ocramz/splitmix-distributions#readme> homepage:       https://github.com/ocramz/splitmix-distributions#readme bug-reports:    https://github.com/ocramz/splitmix-distributions/issues
src/System/Random/SplitMix/Distributions.hs view
@@ -42,6 +42,9 @@   gamma,   pareto,   dirichlet,+  logNormal,+  laplace,+  weibull,   -- ** Discrete   bernoulli, fairCoin,   multinomial,@@ -293,6 +296,46 @@                Double -- ^ rate parameter \( \lambda > 0 \)             -> GenT m Double exponential l = withGen (exponentialF l)+++++-- | Log-normal distribution with specified mean and standard deviation.+logNormal :: Monad m =>+             Double+          -> Double -- ^ standard deviation \( \sigma \gt 0 \)+          -> GenT m Double+logNormal m sd = exp <$> normal m sd+{-# INLINABLE logNormal #-}+++-- | Laplace or double-exponential distribution with provided location and+--   scale parameters.+laplace :: Monad m =>+           Double -- ^ location parameter+        -> Double  -- ^ scale parameter \( s \gt 0 \)+        -> GenT m Double+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 #-}++-- | Weibull distribution with provided shape and scale parameters.+weibull :: Monad m =>+           Double -- ^ shape \( a \gt 0 \)+        -> Double -- ^ scale \( b \gt 0 \)+        -> GenT m Double+weibull a b = do+  x <- stdUniform+  return $ (- 1/a * log (1 - x)) ** 1/b+{-# INLINABLE weibull #-}++++++  -- | Wrap a 'splitmix' PRNG function withGen :: Monad m =>