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

LicenseGPL-3
Maintainerhackage@mail.kevinl.io
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Data.Stochastic.Types

Description

This module contains the types used for the stochastic package.

WARNING: In its current state, care should be taken when using discrete distributions as it is never checked that the probabilities sum to 1. As is, execution of sampling may fail at run-time if probabilities aren't normalized.

Synopsis

Documentation

data Distribution a where Source #

Datatype representing parameterized probability distributions over values of type a. GADTs are used to restrict types of certain distributions (e.g. normal distributions can only be defined over floating point numbers)

Constructors

Normal :: Mean -> StDev -> Distribution Double 
Bernoulli :: Double -> Distribution Bool 
Discrete :: [(a, Double)] -> Distribution a 
DiscreteUniform :: [a] -> Distribution a 
Uniform :: Distribution Double 
Certain :: a -> Distribution a 
Gamma :: Double -> Double -> Distribution Double

Gamma distribution, where the first parameter is the shape parameter alpha, and the second parameter is the scale parameter beta.

Beta :: Double -> Double -> Distribution Double 

Instances

Sampleable Distribution Source #

Sampleable instance for Distribution. We ensure that we always pass the *next* RandomGen provided to sampleFrom. This lets us obey the monad laws.

Methods

certainDist :: a -> Distribution a Source #

sampleFrom :: RandomGen g => Distribution a -> g -> (a, g) Source #

Show a => Show (Distribution a) Source #

Show instance for Distributions.

class Sampleable d where Source #

Class of types from which samples can be obtained.

Minimal complete definition

certainDist, sampleFrom

Methods

certainDist :: a -> d a Source #

Constructor for a datatype from which we always sample the same value.

sampleFrom :: RandomGen g => d a -> g -> (a, g) Source #

Sample from the sampleable datatype using a RandomGen returning a new RandomGen.

Instances

Sampleable Distribution Source #

Sampleable instance for Distribution. We ensure that we always pass the *next* RandomGen provided to sampleFrom. This lets us obey the monad laws.

Methods

certainDist :: a -> Distribution a Source #

sampleFrom :: RandomGen g => Distribution a -> g -> (a, g) Source #

newtype Sample g d a Source #

Sample monad containing a random number generator plus a type from which we can sample values of type a

Constructors

Sample 

Fields

Instances

(RandomGen g, Sampleable d) => Monad (Sample g d) Source #

Monad instance for Sample.

Methods

(>>=) :: Sample g d a -> (a -> Sample g d b) -> Sample g d b #

(>>) :: Sample g d a -> Sample g d b -> Sample g d b #

return :: a -> Sample g d a #

fail :: String -> Sample g d a #

(RandomGen g, Sampleable s) => Functor (Sample g s) Source #

Trivial Functor instance for Sample StdGen Distribution.

Methods

fmap :: (a -> b) -> Sample g s a -> Sample g s b #

(<$) :: a -> Sample g s b -> Sample g s a #

(RandomGen g, Sampleable s) => Applicative (Sample g s) Source #

Trivial Applicative instance for Sample StdGen Distribution.

Methods

pure :: a -> Sample g s a #

(<*>) :: Sample g s (a -> b) -> Sample g s a -> Sample g s b #

(*>) :: Sample g s a -> Sample g s b -> Sample g s b #

(<*) :: Sample g s a -> Sample g s b -> Sample g s a #

type StochProcess = WriterT (Seq Double) (Sample StdGen Distribution) Double Source #

Monad that represents a stochastic process. It allows us to record numeric values as we sample.

type Sampler a = Sample StdGen Distribution a Source #

Type synonym for shorter type annotations for Sample.

type Mean = Double Source #

Type synonym for Double so that the type annotation for the Normal constructor is more informative.

type StDev = Double Source #

Type synonyms for Double so that the type annotation for the Normal constructor is more informative.

marsagliaTsang :: RandomGen g => Double -> Double -> g -> (Double, g) Source #

Marsaglia and Tsang's rejection method for generating Gamma variates with parameters alpha and 1, where 1 is the scale parameter, given d and c.