#include <MCMC.h>
Collaboration diagram for Model:

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 | |
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.
| Model::Model | ( | int | nBurnin, | |
| int | nSample, | |||
| int | nThin, | |||
| bool | calc = false, |
|||
| bool | useMedian = false | |||
| ) | [protected] |
Constructor
| 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. |
| void Model::Simulation | ( | std::ostream & | outf, | |
| bool | interimReport | |||
| ) |
Invoke simulation to do the analysis
| 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
| 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
| 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
| p | Current parameter values |
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
| 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
| outf | The stream on which the report is to be written | |
| lastPar | -1 = all parameters, k+1 = k parameters |
Definition at line 811 of file MCMC.cpp.
References ReportDic(), ReportHead(), results_, and Summarize().
| double Model::Llike | ( | const SampleVector & | par | ) | const [virtual] |
Likelihood
| 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 | ) |
| void Model::SetSample | ( | const int | nSample | ) |
| void Model::SetThin | ( | const int | thin | ) |
| double Model::percent | ( | int | k, | |
| int | n | |||
| ) | const [protected] |
| double Model::percent | ( | const std::vector< int > & | x, | |
| int | n | |||
| ) | const [protected] |
percent -- average percent across a vector
| 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
| 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().
1.5.1