speedy-slice-0.1.1: Speedy slice sampling.

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

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

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.

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.