Obsidian
Probabilistic Geophysical Joint Inversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
stateline::mcmc::ChainArray Class Reference

Manager for all the states and handle reading / writing from / to databse. More...

#include <chainarray.hpp>

Public Member Functions

 ChainArray (uint nStacks, uint nChains, double tempFactor, double initialSigma, double sigmaFactor, db::Database &db, uint cacheLength, bool recover)
 Create a chain array. More...
 
uint length (uint id)
 Get the length of a chain. More...
 
bool append (uint id, const State &proposedState)
 Append a state to a chain. More...
 
void initialise (uint id, const State &state)
 Initialise a chain (by definitely accepting a new state). More...
 
State lastState (uint id)
 Return the last state from a chain. More...
 
State state (uint id, uint index)
 Return a particular state. More...
 
std::vector< Statestates (uint id)
 Return all states from a chain. More...
 
bool swap (uint id1, uint id2)
 Attempt to swap the states in two different chains. More...
 
double sigma (uint id) const
 Get the proposal width of a specific chain. More...
 
void setSigma (uint id, double sigma)
 Set the proposal width of a specific chain. More...
 
double beta (uint id) const
 Get the inverse temperature of a specific chain. More...
 
void setBeta (uint id, double beta)
 Set the inverse temperature of a specific chain. More...
 
uint numStacks () const
 Get the number of stacks. More...
 
uint numChains () const
 Get the number of chains per stack. More...
 
uint numTotalChains () const
 Get the total number of chains in every stack. More...
 
void flushCache (uint id)
 Forcibly flush the cache for a particular chain. More...
 
void recoverFromCache (uint id)
 Recover a particular chain from cached. More...
 

Detailed Description

Manager for all the states and handle reading / writing from / to databse.

The chain ID used by MCMC sampler.

This class works with Ids:

if nStacks = 2, nChains = 4
id 0 = stack 1 chain 1 // lowest temperature chain of stack 1
id 1 = stack 1 chain 2 // high temperature chain of stack 1
id 2 = stack 1 chain 3 // high temperature chain of stack 1
id 3 = stack 1 chain 4 // highest temperature chain of stack 1
id 4 = stack 2 chain 1 // lowest temperature chain of stack 2
id 5 = stack 2 chain 2 // high temperature chain of stack 2
id 6 = stack 2 chain 3 // high temperature chain of stack 2
id 7 = stack 2 chain 4 // highest temperature chain of stack 2

Constructor & Destructor Documentation

stateline::mcmc::ChainArray::ChainArray ( uint  nStacks,
uint  nChains,
double  tempFactor,
double  initialSigma,
double  sigmaFactor,
db::Database db,
uint  cacheLength,
bool  recover 
)

Create a chain array.

Parameters
nStacksThe number of stacks. Each stack have the same temperature sequence.
nChainsThe number of chains in each stack.
tempFactorThe ratio between the temperatures of consecutive chains in a stack.
initialSigmaThe initial step sizes of the chains.
sigmaFactorThe ratio between the temperatures of consectuive chains in a stack.
dbThe database to store chain data.
cacheLengthThe size of the memory cache used to store the chains.
recoverIf set to true, chain data will be recovered from the database

Member Function Documentation

bool stateline::mcmc::ChainArray::append ( uint  id,
const State proposedState 
)

Append a state to a chain.

Parameters
idThe id of the chain (see The chain ID used by MCMC sampler.).
proposedStateThe new state to append.
Returns
Whether the state accepted or rejected (in which case last state is reappended).
double stateline::mcmc::ChainArray::beta ( uint  id) const

Get the inverse temperature of a specific chain.

Parameters
idThe id of the second chain (see The chain ID used by MCMC sampler.).
Returns
The inverse temperature of the chain.
void stateline::mcmc::ChainArray::flushCache ( uint  id)

Forcibly flush the cache for a particular chain.

Parameters
idThe id of the chain to flush.
void stateline::mcmc::ChainArray::initialise ( uint  id,
const State state 
)

Initialise a chain (by definitely accepting a new state).

Parameters
idThe id of the chain (see The chain ID used by MCMC sampler.).
statethe new state to append
State stateline::mcmc::ChainArray::lastState ( uint  id)

Return the last state from a chain.

Parameters
idThe id of the chain (see The chain ID used by MCMC sampler.).
Returns
The most recent state in the chain.
uint stateline::mcmc::ChainArray::length ( uint  id)

Get the length of a chain.

Parameters
idThe id of the chain (see The chain ID used by MCMC sampler.).
Returns
The number of elements in the chain.
uint stateline::mcmc::ChainArray::numChains ( ) const

Get the number of chains per stack.

Returns
The number of chains in each stack of the chain array.
uint stateline::mcmc::ChainArray::numStacks ( ) const

Get the number of stacks.

Returns
The number of stacks in the chain array.
uint stateline::mcmc::ChainArray::numTotalChains ( ) const

Get the total number of chains in every stack.

Returns
The total number of chains in the chain array.
void stateline::mcmc::ChainArray::recoverFromCache ( uint  id)

Recover a particular chain from cached.

Parameters
idThe id of the chain to recover.
void stateline::mcmc::ChainArray::setBeta ( uint  id,
double  beta 
)

Set the inverse temperature of a specific chain.

Parameters
idThe id of the second chain (see The chain ID used by MCMC sampler.).
betaThe new inverse temperature of the chain.
void stateline::mcmc::ChainArray::setSigma ( uint  id,
double  sigma 
)

Set the proposal width of a specific chain.

Parameters
idThe id of the second chain (see The chain ID used by MCMC sampler.).
sigmaThe new proposal width value.
double stateline::mcmc::ChainArray::sigma ( uint  id) const

Get the proposal width of a specific chain.

Parameters
idThe id of the second chain (see The chain ID used by MCMC sampler.).
Returns
The proposal width of the chain.
State stateline::mcmc::ChainArray::state ( uint  id,
uint  index 
)

Return a particular state.

Parameters
idThe id of the chain (see The chain ID used by MCMC sampler.).
indexThe index of the state (0 for first state).
Returns
The most recent state in the chain.
std::vector< State > stateline::mcmc::ChainArray::states ( uint  id)

Return all states from a chain.

Parameters
idThe id of the chain (see The chain ID used by MCMC sampler.).
Returns
The most recent state in the chain.
bool stateline::mcmc::ChainArray::swap ( uint  id1,
uint  id2 
)

Attempt to swap the states in two different chains.

Parameters
id1The id of the first chain (see The chain ID used by MCMC sampler.).
id2The id of the second chain (see The chain ID used by MCMC sampler.).
Returns
Whether the swap was successful.

The documentation for this class was generated from the following files: