mcmc-0.1.3: Sample from a posterior using Markov chain Monte Carlo

Copyright(c) Dominik Schrempf 2020
LicenseGPL-3.0-or-later
Maintainerdominik.schrempf@gmail.com
Stabilityunstable
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Mcmc.Move

Contents

Description

Creation date: Wed May 20 13:42:53 2020.

Synopsis

Move

data Move a Source #

A Move is an instruction about how the Markov chain will traverse the state space a. Essentially, it is a probability density conditioned on the current state.

A Move may be tuneable in that it contains information about how to enlarge or shrink the step size to tune the acceptance ratio.

Constructors

Move 

Fields

Instances
Eq (Move a) Source # 
Instance details

Defined in Mcmc.Move

Methods

(==) :: Move a -> Move a -> Bool #

(/=) :: Move a -> Move a -> Bool #

Ord (Move a) Source # 
Instance details

Defined in Mcmc.Move

Methods

compare :: Move a -> Move a -> Ordering #

(<) :: Move a -> Move a -> Bool #

(<=) :: Move a -> Move a -> Bool #

(>) :: Move a -> Move a -> Bool #

(>=) :: Move a -> Move a -> Bool #

max :: Move a -> Move a -> Move a #

min :: Move a -> Move a -> Move a #

Show (Move a) Source # 
Instance details

Defined in Mcmc.Move

Methods

showsPrec :: Int -> Move a -> ShowS #

show :: Move a -> String #

showList :: [Move a] -> ShowS #

data MoveSimple a Source #

Simple move without tuning information.

In order to calculate the Metropolis-Hastings ratio, we need to know the probability (density) of jumping forth, and the probability (density) of jumping back.

Constructors

MoveSimple 

Fields

  • mvSample :: a -> GenIO -> IO a

    Instruction about randomly moving from the current state to a new state, given some source of randomness.

  • mvDensity :: Maybe (a -> a -> Log Double)

    The density of going from one state to another. Set to Nothing for symmetric moves.

data Tuner a Source #

Tune the acceptance ratio of a Move; see tune, or autotune.

tuner :: (Double -> MoveSimple a) -> Tuner a Source #

Create a Tuner. The tuning function accepts a tuning parameter, and returns a corresponding MoveSimple. The larger the tuning parameter, the larger the Move, and vice versa.

tune :: Double -> Move a -> Maybe (Move a) Source #

Tune a Move. Return Nothing if Move is not tuneable. If the parameter dt is larger than 1.0, the Move is enlarged, if 0<dt<1.0, it is shrunk. Negative tuning parameters are not allowed.

autotune :: Double -> Move a -> Maybe (Move a) Source #

For a given acceptance ratio, auto tune the Move. For now, a Move is enlarged when the acceptance ratio is above 0.44, and shrunk otherwise. Return Nothing if Move is not tuneable.

XXX: The desired acceptance ratio 0.44 is optimal for one-dimensional Moves; one could also store the affected number of dimensions with the Move and tune towards an acceptance ratio accounting for the number of dimensions.

Cycle

data Cycle a Source #

In brief, a Cycle is a list of moves. The state of the Markov chain will be logged only after each Cycle, and the iteration counter will be increased by one. Moves must have unique names, so that they can be identified.

Moves are replicated according to their weights and executed in random order. That is, they are not executed in the order they appear in the Cycle. However, if a Move has weight w, it is executed exactly w times per iteration.

fromList :: [Move a] -> Cycle a Source #

Create a Cycle from a list of Moves.

autotuneC :: Int -> Acceptance (Move a) -> Cycle a -> Cycle a Source #

Tune the Moves in the Cycle. Tuning has no effect on Moves that cannot be tuned. See autotune.

summarizeCycle :: Maybe (Int, Acceptance (Move a)) -> Cycle a -> Text Source #

Summarize the Moves in the Cycle. Also report acceptance ratios for the given number of last iterations.

Acceptance

newtype Acceptance k Source #

For each key k, store the list of accepted (True) and rejected (False) proposals. For reasons of efficiency, the lists are stored in reverse order; latest first.

Constructors

Acceptance 

Fields

Instances
ToJSONKey k => ToJSON (Acceptance k) Source # 
Instance details

Defined in Mcmc.Move

(Ord k, FromJSONKey k) => FromJSON (Acceptance k) Source # 
Instance details

Defined in Mcmc.Move

emptyA :: Ord k => [k] -> Acceptance k Source #

In the beginning there was the Word.

Initialize an empty storage of accepted/rejected values.

pushA :: (Ord k, Show k) => k -> Bool -> Acceptance k -> Acceptance k Source #

For key k, prepend an accepted (True) or rejected (False) proposal.

resetA :: Acceptance k -> Acceptance k Source #

Reset acceptance storage.

acceptanceRatios :: Int -> Acceptance k -> Map k Double Source #

Acceptance ratios averaged over the given number of last iterations. If less than n iterations are available, only those are used.