splitmix-distributions

Random samplers for some common distributions, based on splitmix.

https://github.com/ocramz/splitmix-distributions#readme

Version on this page:0.9.0.0
LTS Haskell 19.19:0.9.0.0
Stackage Nightly 2022-08-15:1.0.0
Latest on Hackage:1.0.0

See all snapshots splitmix-distributions appears in

BSD-3-Clause licensed by Marco Zocca
Maintained by ocramz
This version can be pinned in stack with:splitmix-distributions-0.9.0.0@sha256:3e290503505277f37e8981ecd577f56406bef656186700d549c7dfc324e2095c,1574

Module documentation for 0.9.0.0

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

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