Model Class Reference

Implements the statistical model. More...

#include <MCMC.h>

Collaboration diagram for Model:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual ~Model (void)
void Simulation (std::ostream &outf, bool interimReport)
virtual void Summarize (int i, std::ostream &outf)
std::string Label (int i) const
void ReportDic (std::ostream &outf)
virtual void Record (const SampleVector &p)
virtual void InterimReport (std::ostream &outf, std::string header, int progress, int goal)
virtual void ReportHead (std::ostream &outf)
virtual void Report (std::ostream &outf, const int lastPar=-1)
virtual double Llike (const SampleVector &par) const
void SetBurnIn (const int nBurnin)
void SetSample (const int nSample)
void SetThin (const int thin)

Protected Member Functions

 Model (int nBurnin, int nSample, int nThin, bool calc=false, bool useMedian=false)
double percent (int k, int n) const
double percent (const std::vector< int > &x, int n) const
double percent (const std::vector< std::vector< int > > &x, int n) const
virtual SampleVector Parameters (void) const

Protected Attributes

int nBurnin_
 number of iterations for burn in
int nSample_
 number of iterations for sample
int nThin_
 number of iterations between saving results
unsigned nElem_
 number of parameters in the model
SimpleStatistic likelihood_
 stores likelihood for DIC calculations
ModelSteps step_
 vector of parameters to sample
Results results_
 vector (boost::any) of stored results
boost::format * summaryFormat_
 boost::format for summary output

Detailed Description

Implements the statistical model.

To build a model, derive a new class from Model. In its constructor, push Steps of the appropriate type onto step_. If you're happy with the default reports, the only other thing you'll need to do is to provide accessor functions to values of the parameters in step_ (or make them public so that Parameters can access them directly).

If you want to calculate DIC for the model, you'll have to provide an appropriate override for Llike(), but everything else will be taken care of automatically.

Definition at line 613 of file MCMC.h.


Constructor & Destructor Documentation

Model::~Model ( void   )  [virtual]

Destructor

Definition at line 737 of file MCMC.cpp.

Model::Model ( int  nBurnin,
int  nSample,
int  nThin,
bool  calc = false,
bool  useMedian = false 
) [protected]

Constructor

Parameters:
nBurnin Number of iterations for "burn in"
nSample Number of iterations for "sample"
nThin Keep every nThin'th sample
calc false == no lLike not overridden, true == lLike overriden (there's probably a way to figure this out, but I haven't worked on it yet). Default is false
useMedian false == use posterior mean in DIC calculation, true == use posterior median in DIC calculation. Default is false.

Definition at line 728 of file MCMC.cpp.


Member Function Documentation

void Model::Simulation ( std::ostream &  outf,
bool  interimReport 
)

Invoke simulation to do the analysis

Parameters:
outf Output stream for progress display
interimReport Produce progress display?

Definition at line 745 of file MCMC.cpp.

References InterimReport(), nBurnin_, nElem_, nSample_, nThin_, Parameters(), Record(), and step_.

void Model::Summarize ( int  i,
std::ostream &  outf 
) [virtual]

Produce the summary statistics for each parameter

Parameters:
i Index of the parameter being reported on
outf The stream on which the report is being written

Definition at line 867 of file MCMC.cpp.

References Label(), SimpleStatistic::Mean(), nSample_, nThin_, quantile(), results_, SimpleStatistic::StdDev(), and summaryFormat_.

Referenced by Report().

std::string Model::Label ( int  i  )  const

Produce the parameter label

Parameters:
i Index of the parameter

Definition at line 884 of file MCMC.cpp.

References step_.

Referenced by Summarize().

void Model::ReportDic ( std::ostream &  outf  ) 

Calculate and report DIC statistics

Definition at line 901 of file MCMC.cpp.

References likelihood_, Llike(), SimpleStatistic::Mean(), nElem_, quantile(), results_, and SimpleStatistic::Variance().

Referenced by Report().

void Model::Record ( const SampleVector p  )  [virtual]

Keep track of current parameter values

Parameters:
p Current parameter values
If you're analysing a big model with lots of parameters, only some of which are of primary interest, you may want to override Record() to either keep track only of the few parameters that are of primary interest, either discarding the others or writing them to disk.

Definition at line 775 of file MCMC.cpp.

References SimpleStatistic::Add(), likelihood_, Llike(), and results_.

Referenced by Simulation().

void Model::InterimReport ( std::ostream &  outf,
std::string  header,
int  progress,
int  goal 
) [virtual]

Produce a progress display

If you're writing a sampler under a GUI and want a progress display, you'll definitely want to override this.

Definition at line 788 of file MCMC.cpp.

Referenced by Simulation().

void Model::ReportHead ( std::ostream &  outf  )  [virtual]

Produce the report header

Parameters:
outf The stream on which the report is being written

Definition at line 852 of file MCMC.cpp.

References summaryFormat_.

Referenced by Report().

void Model::Report ( std::ostream &  outf,
const int  lastPar = -1 
) [virtual]

Produce a final report

Parameters:
outf The stream on which the report is to be written
lastPar -1 = all parameters, k+1 = k parameters
The report includes a header, the label for each parameter, and the posterior mean, standard deviation, 2.5%, 50%, and 97.5tiles.

Definition at line 811 of file MCMC.cpp.

References ReportDic(), ReportHead(), results_, and Summarize().

double Model::Llike ( const SampleVector par  )  const [virtual]

Likelihood

Parameters:
par A vector of parameters from which to calculate the likelihood

Definition at line 894 of file MCMC.cpp.

Referenced by Record(), and ReportDic().

void Model::SetBurnIn ( const int  nBurnin  ) 

Set the number of iterations in the burn-in period

Parameters:
nBurnin the number of burn-in iterations

Definition at line 825 of file MCMC.cpp.

References nBurnin_.

void Model::SetSample ( const int  nSample  ) 

Set the number of iterations in the sample period

Parameters:
nSample the number of sample iterations

Definition at line 834 of file MCMC.cpp.

References nSample_.

void Model::SetThin ( const int  thin  ) 

Set the thinning interval (the interval between saved samples)

thin the thinning interval

Definition at line 843 of file MCMC.cpp.

References nThin_.

double Model::percent ( int  k,
int  n 
) const [protected]

percent -- integer/integer

Parameters:
k Count
n Sample size

Definition at line 959 of file MCMC.cpp.

Referenced by percent().

double Model::percent ( const std::vector< int > &  x,
int  n 
) const [protected]

percent -- average percent across a vector

Parameters:
x Vector of counts
n Sample size

Definition at line 969 of file MCMC.cpp.

References SimpleStatistic::Add(), SimpleStatistic::Mean(), and percent().

double Model::percent ( const std::vector< std::vector< int > > &  x,
int  n 
) const [protected]

percent -- average percent across a vector of vectors

Parameters:
x Vector of vector of counts
n Sample size

Definition at line 984 of file MCMC.cpp.

References SimpleStatistic::Add(), SimpleStatistic::Mean(), and percent().

SampleVector Model::Parameters ( void   )  const [protected, virtual]

Return parameter vector associated with this step

Values in the sample vector are stored as boost::any. Retrieving them will require an appropriate boost::any_cast<>

Definition at line 1020 of file MCMC.cpp.

References step_.

Referenced by Simulation().


The documentation for this class was generated from the following files:
Generated on Tue Mar 27 16:03:50 2007 for mcmc by  doxygen 1.5.1