BSD-3-Clause licensed by Marco Zocca
Maintained by ocramz
This version can be pinned in stack with:splitmix-distributions-1.0.0@sha256:5d7a585aff4bdad60c0d6354c9ab0c7cb6e0ef6b60c1fc596c4b26cb6300f3ec,1572

Module documentation for 1.0.0

Used by 1 package in lts-20.12(full list with versions):

splitmix-distributions

Random samplers for some common distributions, as well as a convenient interface for composing them, based on splitmix.

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 :: Gen Double
process = do
    coin <- bernoulli 0.7
    if coin
    then
        normal 0 2
    else
        normal 3 1

dataset :: [Double]
dataset = sample 1234 $ 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.

Changes

1.0

  • add MonadReader r (GenT m) instance
  • fixed MonadState (GenT m) instance via MonadTrans (i.e. as done in ‘mtl’)

0.9 :

  • ensure it builds with ghc 8.6.5 (== stackage lts 14.27) as well
  • relax lower bound

0.8 :

  • add exceptions dependency
  • add MonadThrow (GenT m) instance

0.7 :

  • add sampleIO, samplesIO
  • clarify pure vs IO-based sampling in the docs

0.6 :

  • add Chinese Restaurant Process

0.5 :

  • add Log-normal, Laplace, Weibull distributions

0.4 :

  • add Discrete, Categorical, Zipf-Mandelbrot distributions

0.3 :

  • type signatures of all generators are now parametrized over some Monad m rather than Identity. This allows for more flexibility on the use site.

0.2 :

  • add Pareto, Dirichlet, multinomial distributions