monad-bayes-0.1.0.0: A library for probabilistic programming.

Copyright(c) Adam Scibior 2015-2020
LicenseMIT
Maintainerleonhard.markert@tweag.io
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Bayes.Class

Description

This module defines MonadInfer, which can be used to represent a simple model like the following:

import Control.Monad (when)
import Control.Monad.Bayes.Class

model :: MonadInfer m => m Bool
model = do
  rain <- bernoulli 0.3
  sprinkler <-
    bernoulli $
    if rain
      then 0.1
      else 0.4
  let wetProb =
    case (rain, sprinkler) of
      (True,  True)  -> 0.98
      (True,  False) -> 0.80
      (False, True)  -> 0.90
      (False, False) -> 0.00
  score wetProb
  return rain
Synopsis

Documentation

class Monad m => MonadSample m Source #

Monads that can draw random variables.

Minimal complete definition

random

Instances
MonadSample Enumerator Source # 
Instance details

Defined in Control.Monad.Bayes.Enumerator

MonadSample SamplerST Source # 
Instance details

Defined in Control.Monad.Bayes.Sampler

MonadSample SamplerIO Source # 
Instance details

Defined in Control.Monad.Bayes.Sampler

MonadSample m => MonadSample (MaybeT m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

MonadSample m => MonadSample (ListT m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

Monad m => MonadSample (FreeSampler m) Source # 
Instance details

Defined in Control.Monad.Bayes.Free

MonadSample m => MonadSample (Sequential m) Source # 
Instance details

Defined in Control.Monad.Bayes.Sequential

MonadSample m => MonadSample (Weighted m) Source # 
Instance details

Defined in Control.Monad.Bayes.Weighted

MonadSample m => MonadSample (Traced m) Source # 
Instance details

Defined in Control.Monad.Bayes.Traced.Static

MonadSample m => MonadSample (Traced m) Source # 
Instance details

Defined in Control.Monad.Bayes.Traced.Dynamic

MonadSample m => MonadSample (Traced m) Source # 
Instance details

Defined in Control.Monad.Bayes.Traced.Basic

MonadSample m => MonadSample (Population m) Source # 
Instance details

Defined in Control.Monad.Bayes.Population

MonadSample m => MonadSample (IdentityT m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

MonadSample m => MonadSample (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

MonadSample m => MonadSample (StateT s m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

(Monoid w, MonadSample m) => MonadSample (WriterT w m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

MonadSample m => MonadSample (ContT r m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

(MonadSample m, Monoid w) => MonadSample (RWST r w s m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

Methods

random :: RWST r w s m Double Source #

uniform :: Double -> Double -> RWST r w s m Double Source #

normal :: Double -> Double -> RWST r w s m Double Source #

gamma :: Double -> Double -> RWST r w s m Double Source #

beta :: Double -> Double -> RWST r w s m Double Source #

bernoulli :: Double -> RWST r w s m Bool Source #

categorical :: Vector v Double => v Double -> RWST r w s m Int Source #

logCategorical :: (Vector v (Log Double), Vector v Double) => v (Log Double) -> RWST r w s m Int Source #

uniformD :: [a] -> RWST r w s m a Source #

geometric :: Double -> RWST r w s m Int Source #

poisson :: Double -> RWST r w s m Int Source #

dirichlet :: Vector v Double => v Double -> RWST r w s m (v Double) Source #

random Source #

Arguments

:: MonadSample m 
=> m Double

\(\sim \mathcal{U}(0, 1)\)

Draw from a uniform distribution.

uniform Source #

Arguments

:: MonadSample m 
=> Double

lower bound a

-> Double

upper bound b

-> m Double

\(\sim \mathcal{U}(a, b)\).

Draw from a uniform distribution.

normal Source #

Arguments

:: MonadSample m 
=> Double

mean μ

-> Double

standard deviation σ

-> m Double

\(\sim \mathcal{N}(\mu, \sigma^2)\)

Draw from a normal distribution.

gamma Source #

Arguments

:: MonadSample m 
=> Double

shape k

-> Double

scale θ

-> m Double

\(\sim \Gamma(k, \theta)\)

Draw from a gamma distribution.

beta Source #

Arguments

:: MonadSample m 
=> Double

shape α

-> Double

shape β

-> m Double

\(\sim \mathrm{Beta}(\alpha, \beta)\)

Draw from a beta distribution.

bernoulli Source #

Arguments

:: MonadSample m 
=> Double

probability p

-> m Bool

\(\sim \mathrm{B}(1, p)\)

Draw from a Bernoulli distribution.

categorical Source #

Arguments

:: (MonadSample m, Vector v Double) 
=> v Double

event probabilities

-> m Int

outcome category

Draw from a categorical distribution.

logCategorical Source #

Arguments

:: (MonadSample m, Vector v (Log Double), Vector v Double) 
=> v (Log Double)

event probabilities

-> m Int

outcome category

Draw from a categorical distribution in the log domain.

uniformD Source #

Arguments

:: MonadSample m 
=> [a]

observable outcomes xs

-> m a

\(\sim \mathcal{U}\{\mathrm{xs}\}\)

Draw from a discrete uniform distribution.

geometric Source #

Arguments

:: MonadSample m 
=> Double

success rate p

-> m Int

\(\sim\) number of failed Bernoulli trials with success probability p before first success

Draw from a geometric distribution.

poisson Source #

Arguments

:: MonadSample m 
=> Double

parameter λ

-> m Int

\(\sim \mathrm{Pois}(\lambda)\)

Draw from a Poisson distribution.

dirichlet Source #

Arguments

:: (MonadSample m, Vector v Double) 
=> v Double

concentration parameters as

-> m (v Double)

\(\sim \mathrm{Dir}(\mathrm{as})\)

Draw from a Dirichlet distribution.

class Monad m => MonadCond m Source #

Monads that can score different execution paths.

Minimal complete definition

score

Instances
MonadCond Enumerator Source # 
Instance details

Defined in Control.Monad.Bayes.Enumerator

Methods

score :: Log Double -> Enumerator () Source #

MonadCond m => MonadCond (MaybeT m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

Methods

score :: Log Double -> MaybeT m () Source #

MonadCond m => MonadCond (ListT m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

Methods

score :: Log Double -> ListT m () Source #

MonadCond m => MonadCond (Sequential m) Source #

Execution is suspended after each score.

Instance details

Defined in Control.Monad.Bayes.Sequential

Methods

score :: Log Double -> Sequential m () Source #

Monad m => MonadCond (Weighted m) Source # 
Instance details

Defined in Control.Monad.Bayes.Weighted

Methods

score :: Log Double -> Weighted m () Source #

MonadCond m => MonadCond (Traced m) Source # 
Instance details

Defined in Control.Monad.Bayes.Traced.Static

Methods

score :: Log Double -> Traced m () Source #

MonadCond m => MonadCond (Traced m) Source # 
Instance details

Defined in Control.Monad.Bayes.Traced.Dynamic

Methods

score :: Log Double -> Traced m () Source #

MonadCond m => MonadCond (Traced m) Source # 
Instance details

Defined in Control.Monad.Bayes.Traced.Basic

Methods

score :: Log Double -> Traced m () Source #

Monad m => MonadCond (Population m) Source # 
Instance details

Defined in Control.Monad.Bayes.Population

Methods

score :: Log Double -> Population m () Source #

MonadCond m => MonadCond (IdentityT m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

Methods

score :: Log Double -> IdentityT m () Source #

MonadCond m => MonadCond (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

Methods

score :: Log Double -> ReaderT r m () Source #

MonadCond m => MonadCond (StateT s m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

Methods

score :: Log Double -> StateT s m () Source #

(Monoid w, MonadCond m) => MonadCond (WriterT w m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

Methods

score :: Log Double -> WriterT w m () Source #

MonadCond m => MonadCond (ContT r m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

Methods

score :: Log Double -> ContT r m () Source #

(MonadCond m, Monoid w) => MonadCond (RWST r w s m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

Methods

score :: Log Double -> RWST r w s m () Source #

score Source #

Arguments

:: MonadCond m 
=> Log Double

likelihood of the execution path

-> m () 

Record a likelihood.

factor Source #

Arguments

:: MonadCond m 
=> Log Double

likelihood of the execution path

-> m () 

Synonym for score.

condition :: MonadCond m => Bool -> m () Source #

Hard conditioning.

class (MonadSample m, MonadCond m) => MonadInfer m Source #

Monads that support both sampling and scoring.

Instances
MonadInfer Enumerator Source # 
Instance details

Defined in Control.Monad.Bayes.Enumerator

MonadInfer m => MonadInfer (MaybeT m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

MonadInfer m => MonadInfer (ListT m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

MonadInfer m => MonadInfer (Sequential m) Source # 
Instance details

Defined in Control.Monad.Bayes.Sequential

MonadSample m => MonadInfer (Weighted m) Source # 
Instance details

Defined in Control.Monad.Bayes.Weighted

MonadInfer m => MonadInfer (Traced m) Source # 
Instance details

Defined in Control.Monad.Bayes.Traced.Static

MonadInfer m => MonadInfer (Traced m) Source # 
Instance details

Defined in Control.Monad.Bayes.Traced.Dynamic

MonadInfer m => MonadInfer (Traced m) Source # 
Instance details

Defined in Control.Monad.Bayes.Traced.Basic

MonadSample m => MonadInfer (Population m) Source # 
Instance details

Defined in Control.Monad.Bayes.Population

MonadInfer m => MonadInfer (IdentityT m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

MonadInfer m => MonadInfer (ReaderT r m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

MonadInfer m => MonadInfer (StateT s m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

(Monoid w, MonadInfer m) => MonadInfer (WriterT w m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

MonadInfer m => MonadInfer (ContT r m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

(MonadInfer m, Monoid w) => MonadInfer (RWST r w s m) Source # 
Instance details

Defined in Control.Monad.Bayes.Class

normalPdf Source #

Arguments

:: Double

mean μ

-> Double

standard deviation σ

-> Double

sample x

-> Log Double

relative likelihood of observing sample x in \(\mathcal{N}(\mu, \sigma^2)\)

Probability density function of the normal distribution.