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

Copyright(c) 2015 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@jtobin.ca>
Stabilityunstable
Portabilityghc
Safe HaskellNone
LanguageHaskell2010

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 :: (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 RealWorld -> IO () Source

Trace n iterations of a Markov chain and stream them to stdout.

>>> withSystemRandom . asGenIO $ mcmc 3 1 [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 

Fields

lTarget :: a -> Double
 
glTarget :: Maybe (a -> a)
 

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

Create a generator for variates using a fixed seed.

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), 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.

Note: on Windows, this code does not yet use the native Cryptographic API as a source of random numbers (it uses the system clock instead). As a result, the sequences it generates may not be highly independent.

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

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