speedy-slice-0.3.0: Speedy slice sampling.

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

Numeric.MCMC.Slice

Contents

Description

This implementation performs slice sampling by first finding a bracket about a mode (using a simple doubling heuristic), and then doing rejection sampling along it. The result is a reliable and computationally inexpensive sampling routine.

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, 2003 for the definitive reference of the algorithm.

Synopsis

# Documentation

mcmc :: (MonadIO m, PrimMonad m, Show (t a), FoldableWithIndex (Index (t a)) t, Ixed (t a), Num (IxValue (t a)), Variate (IxValue (t a))) => Int -> IxValue (t a) -> t a -> (t a -> Double) -> Gen (PrimState m) -> m () Source #

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

>>> let rosenbrock [x0, x1] = negate (5  *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2)
>>> withSystemRandom . asGenIO $mcmc 3 1 [0, 0] rosenbrock -3.854097694213343e-2,0.16688601288358407 -9.310661272172682e-2,0.2562387977415508 -0.48500122500661846,0.46245400501919076  chain :: (PrimMonad m, FoldableWithIndex (Index (f a)) f, Ixed (f a), Variate (IxValue (f a)), Num (IxValue (f a))) => Int -> IxValue (f a) -> f a -> (f a -> Double) -> Gen (PrimState m) -> m [Chain (f a) b] Source # Trace n iterations of a Markov chain and collect them in a list. >>> results <- withSystemRandom . asGenIO$ mcmc 3 1 [0, 0] rosenbrock


slice :: (PrimMonad m, FoldableWithIndex (Index (t a)) t, Ixed (t a), Num (IxValue (t a)), Variate (IxValue (t a))) => IxValue (t a) -> Transition m (Chain (t a) b) Source #

A slice sampling transition operator.

# Re-exported

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.