versatile-mcmc  0.1.7
Public Types | Public Member Functions | Protected Attributes | List of all members
vmcmc::Algorithm Class Referenceabstract

Abstract base class for the core MCMC sampling algorithms. More...

#include <algorithm.hpp>

Inheritance diagram for vmcmc::Algorithm:
Inheritance graph
[legend]
Collaboration diagram for vmcmc::Algorithm:
Collaboration graph
[legend]

Public Types

using DefaultCallable = std::function< double(const std::vector< double > &)>
 

Public Member Functions

void SetParameterConfig (const ParameterConfig &paramConfig)
 Set the parameter configuration. More...
 
const ParameterConfigGetParameterConfig () const
 
void SetPrior (DefaultCallable prior)
 
template<size_t NParams, typename CallableT >
void SetPrior (CallableT prior)
 
void SetLikelihood (DefaultCallable likelihood)
 
template<size_t NParams, typename CallableT >
void SetLikelihood (CallableT likelihood)
 
void SetNegLogLikelihood (DefaultCallable negLoglikelihood)
 
template<size_t NParams, typename CallableT >
void SetNegLogLikelihood (CallableT negLoglikelihood)
 
void SetTotalLength (size_t length)
 
size_t GetTotalLength () const
 
template<typename WriterT , typename... ArgsT>
void AddWriter (ArgsT &&...args)
 Add an output writer by specifying its type and passing constructor arguments. More...
 
void AddWriter (std::shared_ptr< Writer > writer)
 
double EvaluatePrior (const std::vector< double > &paramValues) const
 Evaluate the prior for the given parameter values. More...
 
double EvaluateLikelihood (const std::vector< double > &paramValues) const
 Evaluate the target function likelihood for the given parameter values. More...
 
double EvaluateNegLogLikelihood (const std::vector< double > &paramValues) const
 Evaluate the target function -log(likelihood) for the given parameter values. More...
 
bool Evaluate (Sample &sample) const
 Evalutate the target function prior, likelihood and -log(likelihood) at the position defined by the sample, and update the sample accordingly. More...
 
void Run ()
 Start sampling!
 
virtual void Initialize ()
 
virtual void Advance (size_t nSteps=1)=0
 
virtual void Finalize ()
 
virtual size_t NumberOfChains ()=0
 
virtual const Chain & GetChain (size_t cIndex=0)=0
 
ChainSetStatisticsGetStatistics ()
 
const ChainSetStatisticsGetStatistics () const
 

Protected Attributes

ParameterConfig fParameterConfig
 
DefaultCallable fPrior
 
DefaultCallable fLikelihood
 
DefaultCallable fNegLogLikelihood
 
size_t fTotalLength
 
size_t fCycleLength
 
std::vector< std::shared_ptr< Writer > > fWriters
 
ChainSetStatistics fStatistics
 

Detailed Description

Abstract base class for the core MCMC sampling algorithms.

This base class models the sampling algorithm of an MCMC, advancing to a new state in the parameter space, accepting or rejecting, and saving that state (subsequently sampling the parameter space).

Ideally, this interface should cover single chain algorithms, as well as multi-chain algorithms (like DREAM).

Member Function Documentation

template<typename WriterT , typename... ArgsT>
void vmcmc::Algorithm::AddWriter ( ArgsT &&...  args)
inline

Add an output writer by specifying its type and passing constructor arguments.

Parameters
args
bool vmcmc::Algorithm::Evaluate ( Sample sample) const

Evalutate the target function prior, likelihood and -log(likelihood) at the position defined by the sample, and update the sample accordingly.

Parameters
sample
Returns
False if the likelihood was not evaluated (e.g. due to a zero prior).
double vmcmc::Algorithm::EvaluateLikelihood ( const std::vector< double > &  paramValues) const

Evaluate the target function likelihood for the given parameter values.

Parameters
paramValues
Returns
The likelihood value.
double vmcmc::Algorithm::EvaluateNegLogLikelihood ( const std::vector< double > &  paramValues) const

Evaluate the target function -log(likelihood) for the given parameter values.

Parameters
paramValues
Returns
The negative logarithm (natural base) of the likelihood.
double vmcmc::Algorithm::EvaluatePrior ( const std::vector< double > &  paramValues) const

Evaluate the prior for the given parameter values.

Parameters
paramValues
Returns
The prior value. Returns 1.0 if no priors were defined.
void vmcmc::Algorithm::SetParameterConfig ( const ParameterConfig paramConfig)

Set the parameter configuration.

This is mandatory for every possible implementations of this class. From the configuration, the start points and proposal functions of a sampler a initialized. The number of parameters defines, with how many arguments the target likelihood function is evaluated.

Parameters
paramConfig

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