Copyright | (c) 2015 Jared Tobin |
---|---|

License | MIT |

Maintainer | Jared Tobin <jared@jtobin.ca> |

Stability | unstable |

Portability | ghc |

Safe Haskell | None |

Language | Haskell2010 |

This implementation performs Hamiltonian Monte Carlo using an identity mass matrix.

The `mcmc`

function streams a trace to stdout to be processed elsewhere,
while the `slice`

transition can be used for more flexible purposes, such as
working with samples in memory.

See Neal, 2012 for the definitive reference of the algorithm.

- mcmc :: (MonadIO m, PrimMonad m, Num (IxValue (t Double)), Show (t Double), Traversable t, FunctorWithIndex (Index (t Double)) t, Ixed (t Double), IxValue (t Double) ~ Double) => Int -> Double -> Int -> t Double -> Target (t Double) -> Gen (PrimState m) -> m ()
- chain :: (PrimMonad m, Traversable f, FunctorWithIndex (Index (f Double)) f, Ixed (f Double), IxValue (f Double) ~ Double) => Int -> Double -> Int -> f Double -> Target (f Double) -> Gen (PrimState m) -> m [Chain (f Double) b]
- hamiltonian :: (Num (IxValue (t Double)), Traversable t, FunctorWithIndex (Index (t Double)) t, Ixed (t Double), PrimMonad m, IxValue (t Double) ~ Double) => Double -> Int -> Transition m (Chain (t Double) b)
- data Target a :: * -> * = Target {}
- create :: PrimMonad m => m (Gen (PrimState m))
- createSystemRandom :: IO GenIO
- withSystemRandom :: PrimBase m => (Gen (PrimState m) -> m a) -> IO a
- asGenIO :: (GenIO -> IO a) -> GenIO -> IO a

# Documentation

mcmc :: (MonadIO m, PrimMonad m, Num (IxValue (t Double)), Show (t Double), Traversable t, FunctorWithIndex (Index (t Double)) t, Ixed (t Double), IxValue (t Double) ~ Double) => Int -> Double -> Int -> t Double -> Target (t Double) -> Gen (PrimState m) -> m () Source #

Trace `n`

iterations of a Markov chain and stream them to stdout.

`>>>`

`withSystemRandom . asGenIO $ mcmc 10000 0.05 20 [0, 0] target`

chain :: (PrimMonad m, Traversable f, FunctorWithIndex (Index (f Double)) f, Ixed (f Double), IxValue (f Double) ~ Double) => Int -> Double -> Int -> f Double -> Target (f Double) -> Gen (PrimState m) -> m [Chain (f Double) b] Source #

Trace `n`

iterations of a Markov chain and collect the results in a list.

`>>>`

`results <- withSystemRandom . asGenIO $ chain 1000 0.05 20 [0, 0] target`

hamiltonian :: (Num (IxValue (t Double)), Traversable t, FunctorWithIndex (Index (t Double)) t, Ixed (t Double), PrimMonad m, IxValue (t Double) ~ Double) => Double -> Int -> Transition m (Chain (t Double) b) Source #

A Hamiltonian transition operator.

# Re-exported

A `Target`

consists of a function from parameter space to the reals, as
well as possibly a gradient.

Most implementations assume a *log*-target, so records are named
accordingly.

createSystemRandom :: IO GenIO #

Seed a PRNG with data from the system's fast source of pseudo-random
numbers. All the caveats of `withSystemRandom`

apply here as well.

withSystemRandom :: PrimBase m => (Gen (PrimState m) -> m a) -> IO a #

Seed a PRNG with data from the system's fast source of
pseudo-random numbers ("`/dev/urandom`

" on Unix-like systems or
`RtlGenRandom`

on Windows), then run the given action.

This is a somewhat expensive function, and is intended to be called
only occasionally (e.g. once per thread). You should use the `Gen`

it creates to generate many random numbers.