mwc-random-monad 0.7 → 0.7.1.0
raw patch · 3 files changed
+82/−3 lines, 3 filesdep ~mwc-randomPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: mwc-random
API changes (from Hackage documentation)
+ System.Random.MWC.Distributions.Monad: bernoulli :: MonadPrim m => Double -> Rand m Bool
+ System.Random.MWC.Distributions.Monad: beta :: MonadPrim m => Double -> Double -> Rand m Double
+ System.Random.MWC.Distributions.Monad: categorical :: (MonadPrim m, Vector v Double) => v Double -> Rand m Int
+ System.Random.MWC.Distributions.Monad: dirichlet :: (MonadPrim m, Traversable t) => t Double -> Rand m (t Double)
+ System.Random.MWC.Distributions.Monad: uniformPermutation :: (MonadPrim m, Vector v Int) => Int -> Rand m (v Int)
+ System.Random.MWC.Distributions.Monad: uniformShuffle :: (MonadPrim m, Vector v a, Vector v Int) => v a -> Rand m (v a)
Files
- ChangeLog +8/−0
- System/Random/MWC/Distributions/Monad.hs +67/−0
- mwc-random-monad.cabal +7/−3
+ ChangeLog view
@@ -0,0 +1,8 @@+Changes in 0.7.1.0++ * New functions from mwc-random-0.13.2.0++ +Changes in 0.7.0.1++ * Unbreak build for GHC <= 7.2.2
System/Random/MWC/Distributions/Monad.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE FlexibleContexts #-} -- | -- Module : System.Random.MWC.Monad -- Copyright : (c) 2010-2012 Aleksey Khudyakov@@ -9,18 +10,31 @@ -- -- Monadic wrapper for various distributions generators. module System.Random.MWC.Distributions.Monad (+ -- * Variates: non-uniformly distributed values+ -- ** Continuous distributions normal , standard , exponential , truncatedExp , gamma , chiSquare+ , beta+ -- ** Discrete distribution+ , categorical , geometric0 , geometric1+ , bernoulli+ -- ** Multivariate+ , dirichlet+ -- * Permutations+ , uniformPermutation+ , uniformShuffle ) where import Control.Monad.Primitive.Class (MonadPrim(..)) +import Data.Vector.Generic (Vector)+import Data.Traversable (Traversable) import qualified System.Random.MWC.Distributions as MWC import System.Random.MWC.Monad @@ -86,3 +100,56 @@ -> Rand m Int geometric1 p = toRand $ \g -> MWC.geometric1 p g {-# INLINE geometric1 #-}++-- | Random variate generator for Beta distribution+beta :: MonadPrim m+ => Double -- ^ alpha (>0)+ -> Double -- ^ beta (>0)+ -> Rand m Double+{-# INLINE beta #-}+beta a b = toRand $ \g -> MWC.beta a b g++-- | Random variate generator for Dirichlet distribution+dirichlet :: (MonadPrim m, Traversable t)+ => t Double -- ^ container of parameters+ -> Rand m (t Double)+{-# INLINE dirichlet #-}+dirichlet t = toRand $ \g -> MWC.dirichlet t g++-- | Random variate generator for Bernoulli distribution+bernoulli :: (MonadPrim m)+ => Double -- ^ Probability of success (returning True)+ -> Rand m Bool+{-# INLINE bernoulli #-}+bernoulli p = toRand $ \g -> MWC.bernoulli p g++-- | Random variate generator for categorical distribution.+--+-- Note that if you need to generate a lot of variates functions+-- "System.Random.MWC.CondensedTable" will offer better+-- performance. If only few is needed this function will faster+-- since it avoids costs of setting up table.+categorical :: (MonadPrim m, Vector v Double)+ => v Double -- ^ List of weights [>0]+ -> Rand m Int+{-# INLINE categorical #-}+categorical v = toRand $ \g -> MWC.categorical v g+++-- | Random variate generator for uniformly distributed permutations.+-- It returns random permutation of vector /[0 .. n-1]/.+--+-- This is the Fisher-Yates shuffle+uniformPermutation :: (MonadPrim m, Vector v Int)+ => Int+ -> Rand m (v Int)+{-# INLINE uniformPermutation #-}+uniformPermutation n = toRand $ \g -> MWC.uniformPermutation n g++-- | Random variate generator for a uniformly distributed shuffle of a+-- vector.+uniformShuffle :: (MonadPrim m, Vector v a, Vector v Int)+ => v a+ -> Rand m (v a)+{-# INLINE uniformShuffle #-}+uniformShuffle xs = toRand $ \g -> MWC.uniformShuffle xs g
mwc-random-monad.cabal view
@@ -1,5 +1,5 @@ Name: mwc-random-monad-Version: 0.7+Version: 0.7.1.0 License: BSD3 License-file: LICENSE Author: Alexey Khudyakov <alexey.skladnoy@gmail.com>@@ -11,6 +11,8 @@ Synopsis: Monadic interface for mwc-random Description: Simple monadic interface for mwc-random.+extra-source-files:+ ChangeLog Library build-depends:@@ -19,12 +21,14 @@ primitive, monad-primitive, vector >= 0.7,- mwc-random >= 0.13+ mwc-random >= 0.13.2.0 Exposed-modules: System.Random.MWC.Monad System.Random.MWC.Distributions.Monad System.Random.MWC.CondensedTable.Monad- Ghc-options: -O2 -Wall -fsimpl-tick-factor=500+ if impl(GHC > 7.2.2)+ Ghc-options: -fsimpl-tick-factor=500+ Ghc-options: -O2 -Wall Ghc-prof-options: -auto-all source-repository head