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 :: (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 ()
- 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 :: (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.
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.