Copyright | (c) Adam Scibior 2015-2020 |
---|---|
License | MIT |
Maintainer | leonhard.markert@tweag.io |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
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
- class Monad m => MonadSample m
- random :: MonadSample m => m Double
- uniform :: MonadSample m => Double -> Double -> m Double
- normal :: MonadSample m => Double -> Double -> m Double
- gamma :: MonadSample m => Double -> Double -> m Double
- beta :: MonadSample m => Double -> Double -> m Double
- bernoulli :: MonadSample m => Double -> m Bool
- categorical :: (MonadSample m, Vector v Double) => v Double -> m Int
- logCategorical :: (MonadSample m, Vector v (Log Double), Vector v Double) => v (Log Double) -> m Int
- uniformD :: MonadSample m => [a] -> m a
- geometric :: MonadSample m => Double -> m Int
- poisson :: MonadSample m => Double -> m Int
- dirichlet :: (MonadSample m, Vector v Double) => v Double -> m (v Double)
- class Monad m => MonadCond m
- score :: MonadCond m => Log Double -> m ()
- factor :: MonadCond m => Log Double -> m ()
- condition :: MonadCond m => Bool -> m ()
- class (MonadSample m, MonadCond m) => MonadInfer m
- normalPdf :: Double -> Double -> Double -> Log Double
Documentation
class Monad m => MonadSample m Source #
Monads that can draw random variables.
Instances
:: MonadSample m | |
=> m Double | \(\sim \mathcal{U}(0, 1)\) |
Draw from a uniform distribution.
:: MonadSample m | |
=> Double | lower bound a |
-> Double | upper bound b |
-> m Double | \(\sim \mathcal{U}(a, b)\). |
Draw from a uniform distribution.
:: MonadSample m | |
=> Double | mean μ |
-> Double | standard deviation σ |
-> m Double | \(\sim \mathcal{N}(\mu, \sigma^2)\) |
Draw from a normal distribution.
:: MonadSample m | |
=> Double | shape k |
-> Double | scale θ |
-> m Double | \(\sim \Gamma(k, \theta)\) |
Draw from a gamma distribution.
:: MonadSample m | |
=> Double | shape α |
-> Double | shape β |
-> m Double | \(\sim \mathrm{Beta}(\alpha, \beta)\) |
Draw from a beta distribution.
:: MonadSample m | |
=> Double | probability p |
-> m Bool | \(\sim \mathrm{B}(1, p)\) |
Draw from a Bernoulli distribution.
:: (MonadSample m, Vector v Double) | |
=> v Double | event probabilities |
-> m Int | outcome category |
Draw from a categorical distribution.
:: (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.
:: MonadSample m | |
=> [a] | observable outcomes |
-> m a | \(\sim \mathcal{U}\{\mathrm{xs}\}\) |
Draw from a discrete uniform distribution.
:: 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.
:: MonadSample m | |
=> Double | parameter λ |
-> m Int | \(\sim \mathrm{Pois}(\lambda)\) |
Draw from a Poisson distribution.
:: (MonadSample m, Vector v Double) | |
=> v Double | concentration parameters |
-> 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.
Instances
MonadCond Enumerator Source # | |
Defined in Control.Monad.Bayes.Enumerator | |
MonadCond m => MonadCond (MaybeT m) Source # | |
MonadCond m => MonadCond (ListT m) Source # | |
MonadCond m => MonadCond (Sequential m) Source # | |
Defined in Control.Monad.Bayes.Sequential | |
Monad m => MonadCond (Weighted m) Source # | |
MonadCond m => MonadCond (Traced m) Source # | |
MonadCond m => MonadCond (Traced m) Source # | |
MonadCond m => MonadCond (Traced m) Source # | |
Monad m => MonadCond (Population m) Source # | |
Defined in Control.Monad.Bayes.Population | |
MonadCond m => MonadCond (IdentityT m) Source # | |
MonadCond m => MonadCond (ReaderT r m) Source # | |
MonadCond m => MonadCond (StateT s m) Source # | |
(Monoid w, MonadCond m) => MonadCond (WriterT w m) Source # | |
MonadCond m => MonadCond (ContT r m) Source # | |
(MonadCond m, Monoid w) => MonadCond (RWST r w s m) Source # | |
Record a likelihood.
Synonym for score
.
class (MonadSample m, MonadCond m) => MonadInfer m Source #
Monads that support both sampling and scoring.