Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This is a port of the implementation of LazyPPL: https://lazyppl.bitbucket.io/
Synopsis
- data Tree = Tree {}
- data Trees = Trees {}
- newtype Sampler a = Sampler {
- runSampler :: Tree -> a
- splitTree :: Tree -> (Tree, Tree)
- randomTree :: RandomGen g => g -> Tree
- randomTrees :: RandomGen g => g -> Trees
- sampler :: Sampler a -> IO a
- independent :: Monad m => m a -> m [a]
- weightedsamples :: Weighted Sampler a -> IO [(a, Log Double)]
Documentation
A Tree
is a lazy, infinitely wide and infinitely deep tree, labelled by Doubles
| Our source of randomness will be a Tree, populated by uniform [0,1] choices for each label.
| Often people just use a list or stream instead of a tree.
| But a tree allows us to be lazy about how far we are going all the time.
A probability distribution over a is | a function 'Tree -> a' | The idea is that it uses up bits of the tree as it runs
Sampler | |
|
Instances
Applicative Sampler Source # | |
Functor Sampler Source # | |
Monad Sampler Source # | probabilities for a monad. | Sequencing is done by splitting the tree | and using different bits for different computations. |
MonadDistribution Sampler Source # | |
Defined in Control.Monad.Bayes.Sampler.Lazy random :: Sampler Double Source # uniform :: Double -> Double -> Sampler Double Source # normal :: Double -> Double -> Sampler Double Source # gamma :: Double -> Double -> Sampler Double Source # beta :: Double -> Double -> Sampler Double Source # bernoulli :: Double -> Sampler Bool Source # categorical :: Vector v Double => v Double -> Sampler Int Source # logCategorical :: (Vector v (Log Double), Vector v Double) => v (Log Double) -> Sampler Int Source # uniformD :: [a] -> Sampler a Source # geometric :: Double -> Sampler Int Source # poisson :: Double -> Sampler Int Source # dirichlet :: Vector v Double => v Double -> Sampler (v Double) Source # |
splitTree :: Tree -> (Tree, Tree) Source #
Two key things to do with trees: | Split tree splits a tree in two (bijectively) | Get the label at the head of the tree and discard the rest
randomTree :: RandomGen g => g -> Tree Source #
Preliminaries for the simulation methods. Generate a tree with uniform random labels. This uses split
to split a random seed
randomTrees :: RandomGen g => g -> Trees Source #
independent :: Monad m => m a -> m [a] Source #
weightedsamples :: Weighted Sampler a -> IO [(a, Log Double)] Source #
weightedsamples
runs a probability measure and gets out a stream of (result,weight) pairs