lazyppl-1.0: Lazy Probabilistic Programming Library
Safe HaskellSafe-Inferred
LanguageHaskell2010

LazyPPL.Distributions.Memoization

Description

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 monads m that support memoization at certain argument types a.
  • A default trie-based implementation when a is enumerable, and a curry-based implementation when a 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.

Synopsis

Documentation

class Monad m => MonadMemo m a Source #

Type class for memoizable argument types a under a monad m

Instances

Instances details
MonadMemo Prob Table Source # 
Instance details

Defined in LazyPPL.Distributions.DirichletP

Methods

memoize :: (Table -> Prob b) -> Prob (Table -> b) Source #

MonadMemo Prob Dish Source # 
Instance details

Defined in LazyPPL.Distributions.IBP

Methods

memoize :: (Dish -> Prob b) -> Prob (Dish -> b) Source #

Monad m => MonadMemo m Int Source #

Implementation for enumerable types using tries

Instance details

Defined in LazyPPL.Distributions.Memoization

Methods

memoize :: (Int -> m b) -> m (Int -> b) Source #

(Monad m, MonadMemo m a, MonadMemo m b) => MonadMemo m (a, b) Source #

Implementation for pair types using currying

Instance details

Defined in LazyPPL.Distributions.Memoization

Methods

memoize :: ((a, b) -> m b0) -> m ((a, b) -> b0) Source #

memoize :: MonadMemo m a => (a -> m b) -> m (a -> b) Source #

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.

memrec :: Ord a => Show a => ((a -> b) -> a -> Prob b) -> Prob (a -> b) Source #