queso-0.51.1
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_env(env),
40  m_optionsDesc(new po::options_description("Infinite Dimensional MCMC Sampler options")),
41  m_option_help(m_prefix + "help"),
42  m_option_dataOutputDirName(m_prefix + "dataOutputDirName"),
43  m_option_dataOutputFileName(m_prefix + "dataOutputFileName"),
44  m_option_num_iters(m_prefix + "num_iters"),
45  m_option_save_freq(m_prefix + "save_freq"),
46  m_option_rwmh_step(m_prefix + "rwmh_step")
47 {
49  m_env.worldRank(),
50  "InfiniteDimensionalMCMCSamplerOptions::constructor(1)",
51  "this constructor is incompatible with the abscense of an options input file");
52 }
53 
55 {
56  if (m_optionsDesc) {
57  delete m_optionsDesc;
58  }
59 }
60 
62 {
64  m_env.worldRank(),
65  "InfiniteDimensionalMCMCSamplerOptions::scanOptionsValues()",
66  "m_optionsDesc variable is NULL");
67 
71 
72  if (m_env.subDisplayFile() != NULL) {
73  *m_env.subDisplayFile() << "In InfiniteDimensionalMCMCSamplerOptions::scanOptionsValues()"
74  << ": after reading values of options with prefix '" << m_prefix
75  << "', state of object is:"
76  << "\n" << *this
77  << std::endl;
78  }
79  return;
80 }
81 
83  po::options_description & optionsDesc) const
84 {
85  optionsDesc.add_options()
86  (m_option_help.c_str(), "produce help message for infinite dimensional sampler")
87  (m_option_dataOutputDirName.c_str(), po::value<std::string>()->default_value(UQ_INF_DATA_OUTPUT_DIR_NAME_ODV), "name of data output dir")
88  (m_option_dataOutputFileName.c_str(), po::value<std::string>()->default_value(UQ_INF_DATA_OUTPUT_FILE_NAME_ODV), "name of data output file (HDF5)")
89  (m_option_num_iters.c_str(), po::value<int>()->default_value(UQ_INF_NUM_ITERS_ODV), "number of mcmc iterations to do")
90  (m_option_save_freq.c_str(), po::value<int>()->default_value(UQ_INF_SAVE_FREQ_ODV), "the frequency at which to save the chain state")
91  (m_option_rwmh_step.c_str(), po::value<double>()->default_value(UQ_INF_RWMH_STEP_ODV), "the step-size in the random-walk Metropolis proposal");
92  return;
93 }
94 
96  po::options_description & optionsDesc)
97 {
98  if (m_env.allOptionsMap().count(m_option_help)) {
99  if (m_env.subDisplayFile()) {
100  *m_env.subDisplayFile() << optionsDesc
101  << std::endl;
102  }
103  }
104 
106  this->m_dataOutputDirName = ((const po::variable_value&) m_env.allOptionsMap()[m_option_dataOutputDirName]).as<std::string>();
107  }
108 
110  this->m_dataOutputFileName = ((const po::variable_value&) m_env.allOptionsMap()[m_option_dataOutputFileName]).as<std::string>();
111  }
112 
113  if (m_env.allOptionsMap().count(m_option_num_iters)) {
114  this->m_num_iters = ((const po::variable_value&) m_env.allOptionsMap()[m_option_num_iters]).as<int>();
115  }
116 
117  if (m_env.allOptionsMap().count(m_option_save_freq)) {
118  this->m_save_freq = ((const po::variable_value&) m_env.allOptionsMap()[m_option_save_freq]).as<int>();
119  }
120 
121  if (m_env.allOptionsMap().count(m_option_rwmh_step)) {
122  this->m_rwmh_step = ((const po::variable_value&) m_env.allOptionsMap()[m_option_rwmh_step]).as<double>();
123  }
124 
125  return;
126 }
127 
128 void InfiniteDimensionalMCMCSamplerOptions::print(std::ostream & os) const
129 {
130  os << "\n" << this->m_option_dataOutputDirName << " = " << this->m_dataOutputDirName;
131  os << "\n" << this->m_option_dataOutputFileName << " = " << this->m_dataOutputFileName;
132  os << "\n" << this->m_option_num_iters << " = " << this->m_num_iters;
133  os << "\n" << this->m_option_save_freq << " = " << this->m_save_freq;
134  os << "\n" << this->m_option_rwmh_step << " = " << this->m_rwmh_step;
135  os << std::endl;
136  return;
137 }
138 
139 std::ostream & operator<<(std::ostream & os,
141 {
142  obj.print(os);
143  return os;
144 }
145 
146 const BaseEnvironment&
148 {
149  return this->m_env;
150 }
151 
152 } // End namespace QUESO
std::string m_dataOutputFileName
Name of the HDF5 output file to store chain statistics.
This class defines the options that specify the behaviour of the MCMC sampler.
void scanOptionsValues()
Scans the input file for options prefixed with prefix.
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
po::variables_map & allOptionsMap() const
Definition: Environment.C:368
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:187
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
void getMyOptionValues(po::options_description &optionsDesc)
void print(std::ostream &os) const
Prints this to os.
unsigned int m_save_freq
The frequency at which to save the state of the chain.
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:341
std::string m_prefix
The prefix to look for in the input file.
#define UQ_INF_DATA_OUTPUT_DIR_NAME_ODV
std::string m_dataOutputDirName
Name of the output dir to save infinite dimensional output files to.
#define UQ_INF_DATA_OUTPUT_FILE_NAME_ODV
void defineMyOptions(po::options_description &optionsDesc) const
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
unsigned int m_num_iters
The total number of iterations to do.
InfiniteDimensionalMCMCSamplerOptions(const BaseEnvironment &env, const char *prefix)
Given prefix, read the input file for parameters named prefix_*.
void scanInputFileForMyOptions(const po::options_description &optionsDesc) const
This method scans the input file provided by the user to QUESO.
Definition: Environment.C:378
const BaseEnvironment & env() const
Returns the QUESO environment.

Generated on Thu Apr 23 2015 19:26:15 for queso-0.51.1 by  doxygen 1.8.5