Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Stochastic memoization for the LazyPPL
library.
Stochastic memoization is a useful primitive for programming non-parametric models.
It has type (a -> Prob b) -> Prob (a -> b)
, and can be thought of as simultaneously sampling results for all possible arguments, in a lazy way.
When a
is enumerable, this amounts to converting a stream of probabilities to a random stream, which we can do by sampling each probability once.
This module provides:
- A general type-class
MonadMemo
for monadsm
that support memoization at certain argument typesa
. - A default trie-based implementation when
a
is enumerable, and a curry-based implementation whena
is a pair type. - A general implementation
generalmemoize
for probability, using memo-tables. - A memoized recursion combinator,
memrec
.
For illustrations, see the graph example, clustering, additive clustering, or the infinite relational model.
Documentation
class Monad m => MonadMemo m a Source #
Type class for memoizable argument types a
under a monad m
Instances
MonadMemo Prob Table Source # | |
MonadMemo Prob Dish Source # | |
Monad m => MonadMemo m Int Source # | Implementation for enumerable types using tries |
(Monad m, MonadMemo m a, MonadMemo m b) => MonadMemo m (a, b) Source # | Implementation for pair types using currying |
Defined in LazyPPL.Distributions.Memoization |
generalmemoize :: Ord a => (a -> Prob b) -> Prob (a -> b) Source #
A general memoization method when m
is a probability monad.
We use unsafePerformIO to maintain
a table of calls that have already been made.
If a
is finite, we could just sample all values of a
in advance
and avoid unsafePerformIO. If a
is enumerable, we can use the trie method.