UQTk: Uncertainty Quantification Toolkit 3.1.5
MCMC Class Referenceabstract

Markov Chain Monte Carlo base class. Implemented the basic and most general MCMC algorithms. More...

#include <mcmc.h>

Classes

struct  chainstate
 
struct  outputInfo
 

Public Member Functions

 MCMC (double(*logposterior)(Array1D< double > &, void *), void *postinfo)
 Constructor when given a pointer to a logPosterior function and a pointer to additional information (e.g. data)
 
 MCMC (LogPosteriorBase &L)
 Constructor when given a LogPosterior Base class object.
 
 MCMC ()
 Dummy Constructor, used for TMCMC.
 
void setWriteFlag (int I)
 Set the write flag function given an integer.
 
void setFcnAccept (void(*fcnAccept)(void *))
 Set the accept and reject functions.
 
void setFcnReject (void(*fcnReject)(void *))
 
void setChainDim (int chdim)
 Set the dimensions of the chain given an integer.
 
void initChainPropCov (Array2D< double > &propcov)
 Initialize proposal covariance matrix given as a 2d-array For aMCMC, this matrix is used only before adaptivity starts.
 
void initChainPropCovDiag (Array1D< double > &sig)
 Initialize proposal covariance matrix given its 1d-array diagonal For aMCMC, this matrix is used only before adaptivity starts.
 
void setOutputInfo (string outtype, string file, int freq_file, int freq_screen)
 Set output specification struct, type('txt' or 'bin'), filename, frequency of outputs to the file and to screen.
 
void namesPrepended ()
 Set the indicator to confirm that the names of parameters are prepended in the output file.
 
void setSeed (int seed)
 Set random generation seed.
 
void setLower (double lower, int i)
 Set lower bound at the index of i.
 
void setUpper (double upper, int i)
 Set upper bound at the index of i.
 
void setDefaultDomain ()
 Set default unbounded domain.
 
void setPostInfo (void *postinfo)
 Set the Posterior Info pointer.
 
void getChainPropCov (Array2D< double > &propcov)
 Returns proposal covariance matrix.
 
string getFilename ()
 Get the name of the chain file.
 
int getWriteFlag ()
 Get the value of the write flag as an integer.
 
void getSamples (int burnin, int every, Array2D< double > &samples)
 Get samples of the chain with burnin and thining.
 
void getSamples (Array2D< double > &samples)
 Get all samples of the chain.
 
void getFcnAccept (void(*fcnAccept)(void *))
 Get the accept and reject functions given a pointer.
 
void getFcnReject (void(*fcnReject)(void *))
 
string getOutputType ()
 Get the output file type as a string.
 
int getFileFreq ()
 Get the frequency of output to file.
 
int getScreenFreq ()
 Get the frequency of output to the screen.
 
bool getNamesPrepended ()
 Get if the names are prepended.
 
int getSeed ()
 Get the seed used for random generation.
 
double getLower (int i)
 Get the lower bounds based on an index i.
 
double getUpper (int i)
 Get the upper bounds based on an index i.
 
bool getDimInit ()
 Get if the Chain Dimensions are initialized.
 
void getPostInfo (void *post)
 Get post info pointer.
 
bool getPropCovInit ()
 Get if the Prop Cov has been initialized.
 
bool getOutputInit ()
 Get if the output info has been initialized.
 
int getLastWrite ()
 Get last write.
 
bool getFcnAcceptInit ()
 Get if the accept and reject functions are initialized.
 
bool getFcnRejectInit ()
 
virtual int getNSubSteps ()
 Get function for number of sub steps.
 
int getLowerFlag (int i)
 Get function for the lower and upper Flag at index i.
 
int getUpperFlag (int i)
 
void getAcceptRatio (double *accrat)
 Get the chain's acceptance ratio.
 
double getAcceptRatio ()
 Get the chain's acceptance ratio as a double.
 
int GetChainDim () const
 Get the MCMC chain dimensionality.
 
void resetChainState ()
 Reset the chain state.
 
void resetChainFilename (string filename)
 Reset to a new chain file.
 
void parseBinChain (string filename, Array1D< chainstate > &readchain)
 An auxiliary function to parse the binary file and produce an array of chain-states.
 
void writeFullChainTxt (string filename, Array1D< chainstate > fullchain)
 Write an array of chain-states to a file.
 
void getFullChain (Array1D< chainstate > &readchain)
 Get full chain as an array of chain-states.
 
void appendMAP ()
 Append MAP state to the end.
 
double getMode (Array1D< double > &MAPparams)
 Get MAP parameters.
 
int getFullChainSize ()
 Get the full chain size.
 
void setCurrentStateStep (int i)
 Function to set the step of the current state.
 
void getCurrentStateState (Array1D< double > &state)
 Function to get the state of the current state.
 
double getCurrentStatePost ()
 Function to get the post of the current state.
 
void setCurrentStateState (Array1D< double > &newState)
 Function to set the current state's state.
 
void setCurrentStatePost (double newPost)
 Function to set the current state's post.
 
void setCurrentStateAlfa (double newAlfa)
 Function to set the current state's alfa.
 
double getModeStatePost ()
 Function to get the mode state's post.
 
void getModeStateState (Array1D< double > &state)
 Function to get the mode state's state.
 
virtual void runOptim (Array1D< double > &start)
 The optimization routine.
 
virtual void runChain (int ncalls, Array1D< double > &chstart)=0
 The actual function that generates MCMC.
 
virtual void runChain (int ncalls)=0
 Start an MCMC chain with trivial initial condition.
 
void runAcceptFcn ()
 Function to run the accept function.
 
void runRejectFcn ()
 Function to run the reject function.
 
bool newModeFound ()
 Check to see if a new mode was found during last call to runChain.
 
double evalLogPosterior (Array1D< double > &m)
 Function to evaluate the log-posterior.
 
bool inDomain (Array1D< double > &m)
 Check if a point is in the domain.
 
void writeChainTxt (string filename)
 Write the full chain as a text.
 
void writeChainBin (string filename)
 Write the full chain as a binary file.
 
void setNewMode (bool value)
 Function to set a new mode value.
 

Protected Member Functions

void setAcceptRatio (double d)
 Set the acceptance ratio.
 
void addCurrentState ()
 Function to add the current chain state to the full chain.
 
void updateMode ()
 Function to update the Chain mode.
 
void setLastWrite (int i)
 Set last write.
 

Protected Attributes

dsfmt_t RandomState
 

Private Member Functions

virtual double probOldNew (Array1D< double > &a, Array1D< double > &b)
 

Private Attributes

int WRITE_FLAG
 
int FLAG
 
LogPosteriorBaseL_
 
struct MCMC::outputInfo outputinfo_
 
int chainDim_
 
double(* logPosterior_ )(Array1D< double > &, void *) = NULL
 
void(* fcnAccept_ )(void *) = NULL
 
void(* fcnReject_ )(void *) = NULL
 
void * postInfo_ = NULL
 
Array2D< double > chcov
 
int seed_
 
chainstate currState_
 
chainstate modeState_
 
Array1D< chainstatefullChain_
 
int lastwrite_
 
bool namesPrepend = false
 
bool newMode_ = false
 
double accRatio_ = -1.0
 
bool chaindimInit_ = false
 
bool propcovInit_ = false
 
bool methodInit_ = false
 
bool outputInit_ = false
 
bool fcnAcceptFlag_ = false
 
bool fcnRejectFlag_ = false
 
Array1D< double > Lower_
 Lower bounds.
 
Array1D< double > Upper_
 Upper bounds.
 
Array1D< int > lower_flag_
 Lower bound existence flags.
 
Array1D< int > upper_flag_
 Upper bound existence flags.
 

Detailed Description

Markov Chain Monte Carlo base class. Implemented the basic and most general MCMC algorithms.

Constructor & Destructor Documentation

◆ MCMC() [1/3]

MCMC::MCMC ( double(* logposterior )(Array1D< double > &, void *),
void * postinfo )

Constructor when given a pointer to a logPosterior function and a pointer to additional information (e.g. data)

Note
Constructor using the pointer to the logPosterior and to the posterior information

◆ MCMC() [2/3]

MCMC::MCMC ( LogPosteriorBase & L)

Constructor when given a LogPosterior Base class object.

Note
Constructor using a LogPosteriorBase class object

◆ MCMC() [3/3]

MCMC::MCMC ( )

Dummy Constructor, used for TMCMC.

Note
Dummy Constructor for TMCMC

Member Function Documentation

◆ addCurrentState()

void MCMC::addCurrentState ( )
protected

Function to add the current chain state to the full chain.

◆ appendMAP()

void MCMC::appendMAP ( )

Append MAP state to the end.

◆ evalLogPosterior()

double MCMC::evalLogPosterior ( Array1D< double > & m)

Function to evaluate the log-posterior.

◆ getAcceptRatio() [1/2]

double MCMC::getAcceptRatio ( )

Get the chain's acceptance ratio as a double.

◆ getAcceptRatio() [2/2]

void MCMC::getAcceptRatio ( double * accrat)

Get the chain's acceptance ratio.

◆ GetChainDim()

int MCMC::GetChainDim ( ) const

Get the MCMC chain dimensionality.

◆ getChainPropCov()

void MCMC::getChainPropCov ( Array2D< double > & propcov)

Returns proposal covariance matrix.

Note
Get the proposal covariance matrix given a 2d-array

◆ getCurrentStatePost()

double MCMC::getCurrentStatePost ( )

Function to get the post of the current state.

◆ getCurrentStateState()

void MCMC::getCurrentStateState ( Array1D< double > & state)

Function to get the state of the current state.

◆ getDimInit()

bool MCMC::getDimInit ( )

Get if the Chain Dimensions are initialized.

◆ getFcnAccept()

void MCMC::getFcnAccept ( void(* fcnAccept )(void *))

Get the accept and reject functions given a pointer.

◆ getFcnAcceptInit()

bool MCMC::getFcnAcceptInit ( )

Get if the accept and reject functions are initialized.

◆ getFcnReject()

void MCMC::getFcnReject ( void(* fcnReject )(void *))

◆ getFcnRejectInit()

bool MCMC::getFcnRejectInit ( )

◆ getFileFreq()

int MCMC::getFileFreq ( )

Get the frequency of output to file.

◆ getFilename()

string MCMC::getFilename ( )

Get the name of the chain file.

◆ getFullChain()

void MCMC::getFullChain ( Array1D< chainstate > & readchain)

Get full chain as an array of chain-states.

◆ getFullChainSize()

int MCMC::getFullChainSize ( )

Get the full chain size.

◆ getLastWrite()

int MCMC::getLastWrite ( )

Get last write.

◆ getLower()

double MCMC::getLower ( int i)

Get the lower bounds based on an index i.

◆ getLowerFlag()

int MCMC::getLowerFlag ( int i)

Get function for the lower and upper Flag at index i.

◆ getMode()

double MCMC::getMode ( Array1D< double > & MAPparams)

Get MAP parameters.

◆ getModeStatePost()

double MCMC::getModeStatePost ( )

Function to get the mode state's post.

◆ getModeStateState()

void MCMC::getModeStateState ( Array1D< double > & state)

Function to get the mode state's state.

◆ getNamesPrepended()

bool MCMC::getNamesPrepended ( )

Get if the names are prepended.

◆ getNSubSteps()

virtual int MCMC::getNSubSteps ( )
inlinevirtual

Get function for number of sub steps.

◆ getOutputInit()

bool MCMC::getOutputInit ( )

Get if the output info has been initialized.

◆ getOutputType()

string MCMC::getOutputType ( )

Get the output file type as a string.

◆ getPostInfo()

void MCMC::getPostInfo ( void * post)

Get post info pointer.

◆ getPropCovInit()

bool MCMC::getPropCovInit ( )

Get if the Prop Cov has been initialized.

◆ getSamples() [1/2]

void MCMC::getSamples ( Array2D< double > & samples)

Get all samples of the chain.

◆ getSamples() [2/2]

void MCMC::getSamples ( int burnin,
int every,
Array2D< double > & samples )

Get samples of the chain with burnin and thining.

◆ getScreenFreq()

int MCMC::getScreenFreq ( )

Get the frequency of output to the screen.

◆ getSeed()

int MCMC::getSeed ( )

Get the seed used for random generation.

◆ getUpper()

double MCMC::getUpper ( int i)

Get the upper bounds based on an index i.

◆ getUpperFlag()

int MCMC::getUpperFlag ( int i)

◆ getWriteFlag()

int MCMC::getWriteFlag ( )

Get the value of the write flag as an integer.

◆ inDomain()

bool MCMC::inDomain ( Array1D< double > & m)

Check if a point is in the domain.

◆ initChainPropCov()

void MCMC::initChainPropCov ( Array2D< double > & propcov)

Initialize proposal covariance matrix given as a 2d-array For aMCMC, this matrix is used only before adaptivity starts.

Note
Function that initialize the proposal covariance matrix given as a 2d-array

◆ initChainPropCovDiag()

void MCMC::initChainPropCovDiag ( Array1D< double > & sig)

Initialize proposal covariance matrix given its 1d-array diagonal For aMCMC, this matrix is used only before adaptivity starts.

Note
Function that initialize the proposal covariance matrix given as a 1d-array

◆ namesPrepended()

void MCMC::namesPrepended ( )

Set the indicator to confirm that the names of parameters are prepended in the output file.

Note
Function that sets whether the parameter names will be prepended in the output file

◆ newModeFound()

bool MCMC::newModeFound ( )

Check to see if a new mode was found during last call to runChain.

◆ parseBinChain()

void MCMC::parseBinChain ( string filename,
Array1D< chainstate > & readchain )

An auxiliary function to parse the binary file and produce an array of chain-states.

◆ probOldNew()

virtual double MCMC::probOldNew ( Array1D< double > & a,
Array1D< double > & b )
inlineprivatevirtual

◆ resetChainFilename()

void MCMC::resetChainFilename ( string filename)

Reset to a new chain file.

◆ resetChainState()

void MCMC::resetChainState ( )

Reset the chain state.

◆ runAcceptFcn()

void MCMC::runAcceptFcn ( )

Function to run the accept function.

◆ runChain() [1/2]

virtual void MCMC::runChain ( int ncalls)
pure virtual

Start an MCMC chain with trivial initial condition.

◆ runChain() [2/2]

virtual void MCMC::runChain ( int ncalls,
Array1D< double > & chstart )
pure virtual

The actual function that generates MCMC.

◆ runOptim()

void MCMC::runOptim ( Array1D< double > & start)
virtual

The optimization routine.

◆ runRejectFcn()

void MCMC::runRejectFcn ( )

Function to run the reject function.

◆ setAcceptRatio()

void MCMC::setAcceptRatio ( double d)
protected

Set the acceptance ratio.

◆ setChainDim()

void MCMC::setChainDim ( int chdim)

Set the dimensions of the chain given an integer.

Note
Function that sets the number of dimensions for the MCMC object

◆ setCurrentStateAlfa()

void MCMC::setCurrentStateAlfa ( double newAlfa)

Function to set the current state's alfa.

◆ setCurrentStatePost()

void MCMC::setCurrentStatePost ( double newPost)

Function to set the current state's post.

◆ setCurrentStateState()

void MCMC::setCurrentStateState ( Array1D< double > & newState)

Function to set the current state's state.

◆ setCurrentStateStep()

void MCMC::setCurrentStateStep ( int i)

Function to set the step of the current state.

◆ setDefaultDomain()

void MCMC::setDefaultDomain ( )

Set default unbounded domain.

Note
Sets the default domain for the MCMC object

◆ setFcnAccept()

void MCMC::setFcnAccept ( void(* fcnAccept )(void *))

Set the accept and reject functions.

Note
Function that sets the accept function for the MCMC object

◆ setFcnReject()

void MCMC::setFcnReject ( void(* fcnReject )(void *))
Note
Function that sets the reject function for the MCMC object

◆ setLastWrite()

void MCMC::setLastWrite ( int i)
protected

Set last write.

◆ setLower()

void MCMC::setLower ( double lower,
int i )

Set lower bound at the index of i.

Note
Sets the lower limit at index i

◆ setNewMode()

void MCMC::setNewMode ( bool value)

Function to set a new mode value.

◆ setOutputInfo()

void MCMC::setOutputInfo ( string outtype,
string file,
int freq_file,
int freq_screen )

Set output specification struct, type('txt' or 'bin'), filename, frequency of outputs to the file and to screen.

Note
Function that sets the output information for the MCMC object

◆ setPostInfo()

void MCMC::setPostInfo ( void * postinfo)

Set the Posterior Info pointer.

◆ setSeed()

void MCMC::setSeed ( int seed)

Set random generation seed.

Note
Function that sets the seed for random generation

◆ setUpper()

void MCMC::setUpper ( double upper,
int i )

Set upper bound at the index of i.

Note
Sets the upper limit at index i

◆ setWriteFlag()

void MCMC::setWriteFlag ( int I)

Set the write flag function given an integer.

Note
Function that sets the Write Flag of the MCMC object

◆ updateMode()

void MCMC::updateMode ( )
protected

Function to update the Chain mode.

◆ writeChainBin()

void MCMC::writeChainBin ( string filename)

Write the full chain as a binary file.

◆ writeChainTxt()

void MCMC::writeChainTxt ( string filename)

Write the full chain as a text.

◆ writeFullChainTxt()

void MCMC::writeFullChainTxt ( string filename,
Array1D< chainstate > fullchain )

Write an array of chain-states to a file.

Member Data Documentation

◆ accRatio_

double MCMC::accRatio_ = -1.0
private

◆ chainDim_

int MCMC::chainDim_
private

◆ chaindimInit_

bool MCMC::chaindimInit_ = false
private

◆ chcov

Array2D<double> MCMC::chcov
private

◆ currState_

chainstate MCMC::currState_
private

◆ fcnAccept_

void(* MCMC::fcnAccept_) (void *) = NULL
private

◆ fcnAcceptFlag_

bool MCMC::fcnAcceptFlag_ = false
private

◆ fcnReject_

void(* MCMC::fcnReject_) (void *) = NULL
private

◆ fcnRejectFlag_

bool MCMC::fcnRejectFlag_ = false
private

◆ FLAG

int MCMC::FLAG
private

◆ fullChain_

Array1D<chainstate> MCMC::fullChain_
private

◆ L_

LogPosteriorBase* MCMC::L_
private

◆ lastwrite_

int MCMC::lastwrite_
private

◆ logPosterior_

double(* MCMC::logPosterior_) (Array1D< double > &, void *) = NULL
private

◆ Lower_

Array1D<double> MCMC::Lower_
private

Lower bounds.

◆ lower_flag_

Array1D<int> MCMC::lower_flag_
private

Lower bound existence flags.

◆ methodInit_

bool MCMC::methodInit_ = false
private

◆ modeState_

chainstate MCMC::modeState_
private

◆ namesPrepend

bool MCMC::namesPrepend = false
private

◆ newMode_

bool MCMC::newMode_ = false
private

◆ outputinfo_

struct MCMC::outputInfo MCMC::outputinfo_
private

◆ outputInit_

bool MCMC::outputInit_ = false
private

◆ postInfo_

void* MCMC::postInfo_ = NULL
private

◆ propcovInit_

bool MCMC::propcovInit_ = false
private

◆ RandomState

dsfmt_t MCMC::RandomState
protected

◆ seed_

int MCMC::seed_
private

◆ Upper_

Array1D<double> MCMC::Upper_
private

Upper bounds.

◆ upper_flag_

Array1D<int> MCMC::upper_flag_
private

Upper bound existence flags.

◆ WRITE_FLAG

int MCMC::WRITE_FLAG
private

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