项目作者: ocramz

项目描述 :
Sampling procedures for some common random variables based on splitmix
高级语言: Haskell
项目地址: git://github.com/ocramz/splitmix-distributions.git
创建时间: 2021-05-03T08:21:11Z
项目社区:https://github.com/ocramz/splitmix-distributions

开源协议:

下载


splitmix-distributions

Haskell CI

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:

  1. import Control.Monad (replicateM)
  2. import System.Random.SplitMix.Distributions (Gen, sample, bernoulli, normal)
  3. process :: Gen Double
  4. process = do
  5. coin <- bernoulli 0.7
  6. if coin
  7. then
  8. normal 0 2
  9. else
  10. normal 3 1
  11. dataset :: [Double]
  12. 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.