stochastic-0.1.1.1: Monadic composition of probabilistic functions and sampling.

Data.Stochastic

Description

This module contains convenience functions to construct Samples or StochProcesses corresponding to several probability distributions.

It also contains functions that can be used for running the constructed StochProcesses and generating datapoints, or sampling from a constructed Sample.

Some examples for usage can be found here: http://kevinl.io/posts/2016-08-17-sampling-monad.html

Synopsis

# Constructing a Sample

mkSample :: (RandomGen g, Sampleable d) => d a -> Sample g d a Source #

Function to make a Sample out of a provided Distribution.

certain :: (RandomGen g, Sampleable d) => a -> Sample g d a Source #

Sample for a distribution where we always sample the same value.

discreteUniform :: RandomGen g => [a] -> Sample g Distribution a Source #

Sample for a discrete uniform distribution given a list of provided values.

discrete :: RandomGen g => [(a, Double)] -> Sample g Distribution a Source #

Sample for a discrete distribution with given list of tuples of values of type a and Doubles representing the probability of producing each value when sampling from this distribution.

Sample for a Bernoulli distribution with given probability to produce True.

Sample for a normal distribution with given StdGen, Mean, and StDev.

Sample for a continuous uniform distribution with support [0, 1].

Arguments

 :: RandomGen g => Double The shape parameter. -> Double The scale parameter. -> Sample g Distribution Double

Sample for a gamma distribution given shape parameter and scale parameter.

Sample for a beta distribution.

# Sampling from a Sample

sample :: (RandomGen g, Sampleable d) => Sample g d a -> g -> (a, g) Source #

Get one sample of type a from the Sample along with a new StdGen.

We do an extra next in order to get one more RandomGen because when we sample from normal distributions, we consume one extra RandomGen.

sample_ :: (RandomGen g, Sampleable d) => Sample g d a -> g -> a Source #

Get one sample of type a from the Sample, discarding the RandomGen

sampleN :: (RandomGen g, Sampleable d, Integral i) => i -> Sample g d a -> g -> Seq a Source #

Get a certain number of samples from the Sample

sampleIO :: Sampleable d => Sample StdGen d a -> IO (a, StdGen) Source #

Sample from a Sample of type a using the global random number generator provided by newStdGen, returning a new StdGen with the sampled value.

sampleIO_ :: Sampleable d => Sample StdGen d a -> IO a Source #

Sample from a Sample of type a using the global random number generator provided by newStdGen, discarding the new StdGen.

sampleION :: (Sampleable d, Integral i) => i -> Sample StdGen d a -> IO (Seq a) Source #

Produce several samples from the Sample using the random number generator in the IO monad.

# Constructing a StochProcess

Function to create a StochProcess out of a provided Sample over Doubles.

StochProcess for a distribution over Doubles that always returns the same value when sampled, and records that value.

StochProcess for a discrete uniform distribution over Doubles that records the value sampled from it.

StochProcess for a discrete distribution over Doubles that records the value sampled from the normal distribution.

StochProcess sample for a normal distribution that records the value sampled from the normal distribution.

StochProcess for a discrete uniform distribution over Doubles that records the value sampled from it.

StochProcess for a gamma distribution with provided shape and scale parameters.

StochProcess for a beta distribution.

composeProcess :: Integral i => i -> StochProcess -> (Double -> StochProcess) -> StochProcess Source #

Function to construct a StochProcess computation given an initial computation, a StochProcess function, and number of times to apply the function with bind.

# Running a StochProcess

Run a StochProcess computation and retrieve the recorded results along with a new RandomGen.

Run a StochProcess computation and retrieve the recorded results, discarding the new RandomGen.

runProcessN :: Integral i => i -> StochProcess -> StdGen -> Seq (Seq Double) Source #

Runs a StochProcess computation a given number times and produces a Sequence of Sequences of Doubles.

# Sampling from a StochProcess

Sample from the StochProcess computation, returning the value of type a and a new RandomGen.

Sample from the StochProcess computation, discarding the new RandomGen.

sampleProcessN :: Integral i => i -> StochProcess -> StdGen -> Seq Double Source #

Get a certain number of samples from the StochProcess computation.

Sample from the StochProcess computation in the IO monad, returning a Double and a RandomGen created in the IO monad.

sampleProcessION :: Integral i => i -> StochProcess -> IO (Seq Double) Source #

Get a certain number of samples from the StochProcess computation in the IO monad.