queso-0.56.0
InfiniteDimensionalMCMCSamplerOptions.C
Go to the documentation of this file.
1 //--------------------------------------------------------------------------
2 //
3 // QUESO - a library to support the Quantification of Uncertainty
4 // for Estimation, Simulation and Optimization
5 //
6 // Copyright (C) 2008,2009,2010,2011,2012,2013 The PECOS Development Team
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the Version 2.1 GNU Lesser General
10 // Public License as published by the Free Software Foundation.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Lesser General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
20 // Boston, MA 02110-1301 USA
21 //
22 //-----------------------------------------------------------------------el-
23 
24 #include <queso/InfiniteDimensionalMCMCSamplerOptions.h>
25 
26 // ODV = option default value
27 #define UQ_INF_DATA_OUTPUT_DIR_NAME_ODV "chain"
28 #define UQ_INF_DATA_OUTPUT_FILE_NAME_ODV "out.h5"
29 #define UQ_INF_NUM_ITERS_ODV 1000
30 #define UQ_INF_SAVE_FREQ_ODV 1
31 #define UQ_INF_RWMH_STEP_ODV 1e-2
32 
33 namespace QUESO {
34 
36  const BaseEnvironment& env,
37  const char * prefix)
38  : m_prefix((std::string)(prefix) + "infmcmc_"),
39  m_dataOutputDirName(UQ_INF_DATA_OUTPUT_DIR_NAME_ODV),
40  m_dataOutputFileName(UQ_INF_DATA_OUTPUT_FILE_NAME_ODV),
41  m_num_iters(UQ_INF_NUM_ITERS_ODV),
42  m_save_freq(UQ_INF_SAVE_FREQ_ODV),
43  m_rwmh_step(UQ_INF_RWMH_STEP_ODV),
44 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
45  m_parser(new BoostInputOptionsParser(env.optionsInputFileName())),
46 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
47  m_env(env),
48  m_option_help(m_prefix + "help"),
49  m_option_dataOutputDirName(m_prefix + "dataOutputDirName"),
50  m_option_dataOutputFileName(m_prefix + "dataOutputFileName"),
51  m_option_num_iters(m_prefix + "num_iters"),
52  m_option_save_freq(m_prefix + "save_freq"),
53  m_option_rwmh_step(m_prefix + "rwmh_step")
54 {
55  queso_require_not_equal_to_msg(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the abscense of an options input file"));
56 
57 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
58  m_parser->registerOption(m_option_help, "produce help message for infinite dimensional sampler");
59  m_parser->registerOption<std::string>(m_option_dataOutputDirName, UQ_INF_DATA_OUTPUT_DIR_NAME_ODV, "name of data output dir");
60  m_parser->registerOption<std::string>(m_option_dataOutputFileName, UQ_INF_DATA_OUTPUT_FILE_NAME_ODV, "name of data output file (HDF5)");
61  m_parser->registerOption<unsigned int>(m_option_num_iters, UQ_INF_NUM_ITERS_ODV, "number of mcmc iterations to do");
62  m_parser->registerOption<unsigned int>(m_option_save_freq, UQ_INF_SAVE_FREQ_ODV, "the frequency at which to save the chain state");
63  m_parser->registerOption<double >(m_option_rwmh_step, UQ_INF_RWMH_STEP_ODV, "the step-size in the random-walk Metropolis proposal");;
64 
66 
72 #else
75  m_option_num_iters = m_env.input()(m_option_num_iters, UQ_INF_NUM_ITERS_ODV);
76  m_option_save_freq = m_env.input()(m_option_save_freq, UQ_INF_SAVE_FREQ_ODV);
77  m_option_rwmh_step = m_env.input()(m_option_rwmh_step, UQ_INF_RWMH_STEP_ODV);;
78 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
79 
80  checkOptions();
81 }
82 
83 void
85 {
86  queso_require_equal_to_msg(m_num_iters % m_save_freq, 0, "save frequency must divide number of iterations");
87  queso_require_greater_msg(m_rwmh_step, 0, "random-walk Metropolis step size must be positive");
88 }
89 
91 {
92 }
93 
94 void InfiniteDimensionalMCMCSamplerOptions::print(std::ostream & os) const
95 {
96  os << "\n" << this->m_option_dataOutputDirName << " = " << this->m_dataOutputDirName;
97  os << "\n" << this->m_option_dataOutputFileName << " = " << this->m_dataOutputFileName;
98  os << "\n" << this->m_option_num_iters << " = " << this->m_num_iters;
99  os << "\n" << this->m_option_save_freq << " = " << this->m_save_freq;
100  os << "\n" << this->m_option_rwmh_step << " = " << this->m_rwmh_step;
101  os << std::endl;
102  return;
103 }
104 
105 std::ostream & operator<<(std::ostream & os,
107 {
108 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
109  os << (*(obj.m_parser)) << std::endl;
110 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
111  obj.print(os);
112  return os;
113 }
114 
115 const BaseEnvironment&
117 {
118  return this->m_env;
119 }
120 
121 } // End namespace QUESO
unsigned int m_save_freq
The frequency at which to save the state of the chain.
const GetPot & input() const
The GetPot input file parser.
Definition: Environment.C:1148
This class defines the options that specify the behaviour of the MCMC sampler.
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:353
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:197
std::string m_dataOutputDirName
Name of the output dir to save infinite dimensional output files to.
void getOption(std::string &name, T &value)
Get option name from the parser and set value to the parsed value.
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:73
const BaseEnvironment & env() const
Returns the QUESO environment.
#define UQ_INF_DATA_OUTPUT_DIR_NAME_ODV
InfiniteDimensionalMCMCSamplerOptions(const BaseEnvironment &env, const char *prefix)
Given prefix, read the input file for parameters named prefix_*.
#define UQ_INF_DATA_OUTPUT_FILE_NAME_ODV
void scanInputFile()
This is the method that parses the input file.
void print(std::ostream &os) const
Prints this to os.
#define queso_require_greater_msg(expr1, expr2, msg)
Definition: asserts.h:76
#define queso_require_not_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:74
void registerOption(std::string name, T defaultValue, std::string description)
Call this to register an option with the parser.
std::string m_dataOutputFileName
Name of the HDF5 output file to store chain statistics.
unsigned int m_num_iters
The total number of iterations to do.

Generated on Tue Nov 29 2016 10:53:10 for queso-0.56.0 by  doxygen 1.8.5