| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
System.Random.SplitMix.Distributions
Description
Random samplers for few common distributions, with an interface similar to that of mwc-probability.
Usage
Compose your random sampler out of simpler ones thanks to the Applicative and Monad interface, e.g. this is how you would declare and sample a binary mixture of Gaussian random variables:
import Control.Monad (replicateM) import System.Random.SplitMix.Distributions (Gen, sample, bernoulli, normal) process ::GenDouble process = do coin <-bernoulli0.7 if coin thennormal0 2 else normal 3 1 dataset :: [Double] dataset =sample1234 $ replicateM 20 process
and sample your data in a pure (sample) or monadic (sampleT) setting.
Implementation details
The library is built on top of splitmix, so the caveats on safety and performance that apply there are relevant here as well.
Synopsis
- stdUniform :: Gen Double
- uniformR :: Double -> Double -> Gen Double
- exponential :: Double -> Gen Double
- stdNormal :: Gen Double
- normal :: Double -> Double -> Gen Double
- beta :: Double -> Double -> Gen Double
- gamma :: Double -> Double -> Gen Double
- bernoulli :: Double -> Gen Bool
- type Gen = GenT Identity
- sample :: Word64 -> Gen a -> a
- data GenT m a
- sampleT :: Monad m => Word64 -> GenT m a -> m a
- withGen :: Monad m => (SMGen -> (a, SMGen)) -> GenT m a
Distributions
Continuous
stdUniform :: Gen Double Source #
Uniform in [0, 1)
Exponential distribution
Normal distribution
Arguments
| :: Double | shape parameter \( \alpha \gt 0 \) |
| -> Double | shape parameter \( \beta \gt 0 \) |
| -> Gen Double |
Beta distribution, from two standard uniform samples
Arguments
| :: Double | shape parameter \( k \gt 0 \) |
| -> Double | scale parameter \( \theta \gt 0 \) |
| -> Gen Double |
Gamma distribution, using Ahrens-Dieter accept-reject (algorithm GD):
Ahrens, J. H.; Dieter, U (January 1982). "Generating gamma variates by a modified rejection technique". Communications of the ACM. 25 (1): 47–54
Discrete
PRNG
Pure
Monadic
Random generator
wraps splitmix state-passing inside a StateT monad
useful for embedding random generation inside a larger effect stack
Instances
| MonadTrans GenT Source # | |
Defined in System.Random.SplitMix.Distributions | |
| Monad m => MonadState SMGen (GenT m) Source # | |
| Monad m => Monad (GenT m) Source # | |
| Functor m => Functor (GenT m) Source # | |
| Monad m => Applicative (GenT m) Source # | |
| MonadIO m => MonadIO (GenT m) Source # | |
Defined in System.Random.SplitMix.Distributions | |