hasty-hamiltonian-1.3.0: Speedy traversal through parameter space.

Copyright (c) 2015 Jared Tobin MIT Jared Tobin unstable ghc None Haskell2010

Numeric.MCMC.Hamiltonian

Contents

Description

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.

Synopsis

# 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

data Target a :: * -> * #

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.

Constructors

 Target FieldslTarget :: a -> Double glTarget :: Maybe (a -> a)

create :: PrimMonad m => m (Gen (PrimState m)) #

Create a generator for variates using a fixed seed.

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.

asGenIO :: (GenIO -> IO a) -> GenIO -> IO a #

Constrain the type of an action to run in the IO monad.