MCMC.cpp File Reference

Definitions of classes for MCMC evaluation of Bayesian models. More...

#include <iostream>
#include "mcmc++/Density.h"
#include "mcmc++/MCMC.h"
#include "mcmc++/intervals.h"

Include dependency graph for MCMC.cpp:

Go to the source code of this file.

Classes

struct  BadValue
struct  BadCT

Defines

#define argCheck_   1
#define checkValue_(x)   ;

Typedefs

typedef ParameterT< double > dPar
typedef ParameterT< int > iPar
typedef ParameterT< std::vector<
double > > 
dVecPar
typedef ParameterT< std::vector<
int > > 
iVecPar
typedef ParameterT< boost::any > aPar
typedef const ParameterT<
double > 
cdPar
typedef const ParameterT<
int > 
ciPar
typedef const ParameterT<
std::vector< double > > 
cdVecPar
typedef const ParameterT<
std::vector< int > > 
ciVecPar
typedef const ParameterT<
boost::any > 
caPar

Functions

lotGetRNG (void)
double safeFreq (const double p, const double zero)
double invSafeFreq (const double x, const double zero)
std::vector< double > safeFreq (const std::vector< double > &p, const double zero)
std::vector< double > invSafeFreq (const std::vector< double > &x, const double zero)
double proposeBeta (const double mean, const double denom, const double tolerance)
double logQBeta (const double newMean, const double oldMean, const double denom, const double tolerance)
std::vector< double > proposeDirch (const std::vector< double > &q, const double denom, const double tolerance)
double logQDirch (const std::vector< double > &newMean, const std::vector< double > &oldMean, const double denom, const double tolerance)
double proposeNorm (const double mean, const double variance)
double logQNorm (const double newMean, const double oldMean, const double variance)
double safeBetaPar (const double x)
void safeDirchPar (std::vector< double > &x)

Variables

const double MCMC_ZERO_FREQ = 1.00e-14


Detailed Description

Definitions of classes for MCMC evaluation of Bayesian models.

The Parameter, Step, and Model classes defined here are the core classes that do all of the work. To implement a Bayesian model using these classes each parameter in the model should be derived from Paramater and should override llike(), at a minimum. lprior() should be overridden for anything other than a flat prior. (Notice that the prior will be improper unless overriden when the parameter has an unbounded domain.) The model is derived from Model, and each parameter is pushed onto a stack (step_), with a specified Step type (MetroStep, SliceStep, or FunctionStep).

Author:
Kent Holsinger
Date:
2005-05-18

Definition in file MCMC.cpp.


Define Documentation

#define argCheck_   1

argCheck_ controls whether arguments are bounds checked before use

Defaults to 1 (true) unles NDEBUG is defined

Definition at line 61 of file MCMC.cpp.

#define checkValue_ (  )     ;

Macro to determine whether a value isnan() and print __FILE__ and __LINE__ if it is (disabled when argCheck == 0 (i.e., when NDEBUG is defined during compilation

Definition at line 79 of file MCMC.cpp.


Typedef Documentation

typedef ParameterT<boost::any> aPar

internal typedef, defined here so that it is invisible and inaccessible to users of the library

Definition at line 344 of file MCMC.cpp.

typedef const ParameterT<boost::any> caPar

internal typedef, defined here so that it is invisible and inaccessible to users of the library

Definition at line 408 of file MCMC.cpp.

typedef const ParameterT<double> cdPar

internal typedef, defined here so that it is invisible and inaccessible to users of the library

Definition at line 392 of file MCMC.cpp.

typedef const ParameterT<std::vector<double> > cdVecPar

internal typedef, defined here so that it is invisible and inaccessible to users of the library

Definition at line 400 of file MCMC.cpp.

typedef const ParameterT<int> ciPar

internal typedef, defined here so that it is invisible and inaccessible to users of the library

Definition at line 396 of file MCMC.cpp.

typedef const ParameterT<std::vector<int> > ciVecPar

internal typedef, defined here so that it is invisible and inaccessible to users of the library

Definition at line 404 of file MCMC.cpp.

typedef ParameterT<double> dPar

internal typedef, defined here so that it is invisible and inaccessible to users of the library

Definition at line 328 of file MCMC.cpp.

typedef ParameterT<std::vector<double> > dVecPar

internal typedef, defined here so that it is invisible and inaccessible to users of the library

Definition at line 336 of file MCMC.cpp.

typedef ParameterT<int> iPar

internal typedef, defined here so that it is invisible and inaccessible to users of the library

Definition at line 332 of file MCMC.cpp.

typedef ParameterT<std::vector<int> > iVecPar

internal typedef, defined here so that it is invisible and inaccessible to users of the library

Definition at line 340 of file MCMC.cpp.


Function Documentation

lot& GetRNG ( void   ) 

Returns a reference to the internal random number generator

Definition at line 104 of file MCMC.cpp.

std::vector<double> invSafeFreq ( const std::vector< double > &  x,
const double  zero 
)

Inverts a safeFreq()ed vector

Parameters:
x The vector to invert
zero The original guard (not checked)

Definition at line 153 of file MCMC.cpp.

double invSafeFreq ( const double  x,
const double  zero 
)

Converts a safeFreq()ed x back

Parameters:
x Frequency to convert back
zero Value used in original guard (not verified)

Definition at line 124 of file MCMC.cpp.

double logQBeta ( const double  newMean,
const double  oldMean,
const double  denom,
const double  tolerance 
)

lQ for a beta proposal

Parameters:
newMean New value proposed
oldMean Old value from which proposed
denom Effective sample size
tolerance Minimum value allowed in original proposal

Definition at line 196 of file MCMC.cpp.

References Density::dbeta(), invSafeFreq(), safeBetaPar(), and Util::safeLog().

double logQDirch ( const std::vector< double > &  newMean,
const std::vector< double > &  oldMean,
const double  denom,
const double  tolerance 
)

lQ for a Dirichlet proposal

Parameters:
newMean New value proposed
oldMean Old value from which proposed
denom Effective sample size
tolerance Minimum value allowed in original proposal

Definition at line 242 of file MCMC.cpp.

References Density::ddirch(), invSafeFreq(), and Util::safeLog().

double logQNorm ( const double  newMean,
const double  oldMean,
const double  variance 
)

lQ for a normal proposal

Parameters:
newMean New value proposed
oldMean Old value from which proposed
variance Variance of the proposal distribution

Definition at line 271 of file MCMC.cpp.

References Density::dnorm(), and Util::safeLog().

double proposeBeta ( const double  mean,
const double  denom,
const double  tolerance 
)

Propose a new beta variate for an M-H step

Parameters:
mean Mean for beta distribution
denom Effective sample size
tolerance Minimum value allowed (to avoid exact 0s and 1s)
The parameters of the beta distribution are given by

\[\alpha = denom \times mean\]

\[\beta = denom \times (1-mean)\]

where alpha and beta are guarded by safeBetaPar()

Definition at line 178 of file MCMC.cpp.

References lot::beta(), safeBetaPar(), and safeFreq().

std::vector<double> proposeDirch ( const std::vector< double > &  q,
const double  denom,
const double  tolerance 
)

Propose a new Dirichlet vector for an M-H step

Parameters:
q Mean of the proposal distribution
denom Effective sample size
tolerance Minimum value allowed (to avoid exact 0s and 1s)
The parameters of the beta distribution are given by

\[\alpha = denom \times mean\]

\[\beta = denom \times (1-mean)\]

where alpha and beta are guarded by safeBetaPar()

Definition at line 220 of file MCMC.cpp.

References lot::dirichlet(), safeDirchPar(), and safeFreq().

double proposeNorm ( const double  mean,
const double  variance 
)

Propose a new normal variate for an M-H step

Parameters:
mean Mean of the proposal distribution
variance Variance of the proposal distribution

Definition at line 261 of file MCMC.cpp.

References lot::norm().

double safeBetaPar ( const double  x  ) 

Ensures MinBetaPar <= x <= MaxBetaPar

Parameters:
x Frequency to guard

Definition at line 282 of file MCMC.cpp.

References MCMC::MaxBetaPar, and MCMC::MinBetaPar.

Referenced by logQBeta(), and proposeBeta().

void safeDirchPar ( std::vector< double > &  x  ) 

Ensures MinBetaPar <= x <= MaxBetaPar for all elements of a Dirichlet parameter vector

Parameters:
x Frequency to guard

Definition at line 293 of file MCMC.cpp.

References MCMC::MaxDirchPar, and MCMC::MinDirchPar.

Referenced by proposeDirch().

std::vector<double> safeFreq ( const std::vector< double > &  p,
const double  zero 
)

Ensures that all values in vector are greater than zero and less than 1.0 - n*zero, where n is p.size()

Parameters:
p Frequency vector to guard
zero Value used for guard (MCMC_ZERO_FREQ default)
Assumes all elements of p are in [0, 1]

Definition at line 138 of file MCMC.cpp.

double safeFreq ( const double  p,
const double  zero 
)

Ensures zero < p < 1-zero

Parameters:
p Frequency to guard
zero Minimum value of p allowed
Assumes all elements of p are in [0, 1]

Definition at line 115 of file MCMC.cpp.


Variable Documentation

const double MCMC_ZERO_FREQ = 1.00e-14

default "zero" value for safeFreq()

Definition at line 100 of file MCMC.cpp.


Generated on Tue Mar 27 16:03:45 2007 for mcmc by  doxygen 1.5.1