queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
StatisticalInverseProblemOptions.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2017 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/Defines.h>
26 
27 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
28 #include <boost/program_options.hpp>
29 #else
30 #include <queso/getpot.h>
31 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
32 
33 #include <queso/StatisticalInverseProblemOptions.h>
34 #include <queso/Miscellaneous.h>
35 
36 // -------------------------------------------------
37 // SipOptionsValues--------------------------
38 // -------------------------------------------------
39 
40 namespace QUESO {
41 
42 // Default constructor -----------------------------
44  :
45  m_prefix("ip_"),
46  m_help(UQ_SIP_HELP),
47  m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ),
48  m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV),
49  m_seedWithMAPEstimator(UQ_SIP_SEEDWITHMAPESTIMATOR),
50  m_useOptimizerMonitor(UQ_SIP_USEOPTIMIZERMONITOR),
51 //m_dataOutputAllowedSet(),
52 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
53  m_parser(),
54 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
55  m_option_help (m_prefix + "help" ),
56  m_option_computeSolution (m_prefix + "computeSolution" ),
57  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
58  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"),
59 #ifdef UQ_SIP_READS_SOLVER_OPTION
60  m_option_solver (m_prefix + "solver" ),
61  m_solverString (UQ_SIP_SOLVER_ODV)
62 #endif
63  m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"),
64  m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor")
65 {
66 }
67 
69  prefix)
70  :
71  m_prefix((std::string)(prefix) + "ip_"),
72  m_help(UQ_SIP_HELP),
73  m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ),
74  m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV),
75  m_seedWithMAPEstimator(UQ_SIP_SEEDWITHMAPESTIMATOR),
76  m_useOptimizerMonitor(UQ_SIP_USEOPTIMIZERMONITOR),
77 //m_dataOutputAllowedSet(),
78 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
79  m_parser(new BoostInputOptionsParser(env->optionsInputFileName())),
80 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
81  m_option_help (m_prefix + "help" ),
82  m_option_computeSolution (m_prefix + "computeSolution" ),
83  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
84  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"),
85 #ifdef UQ_SIP_READS_SOLVER_OPTION
86  m_option_solver (m_prefix + "solver" ),
87  m_solverString (UQ_SIP_SOLVER_ODV)
88 #endif
89  m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"),
90  m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor")
91 {
92 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
93  m_parser->registerOption<std::string>(m_option_help, UQ_SIP_HELP, "produce help message for statistical inverse problem");
94  m_parser->registerOption<bool >(m_option_computeSolution, UQ_SIP_COMPUTE_SOLUTION_ODV , "compute solution process" );
95  m_parser->registerOption<std::string>(m_option_dataOutputFileName, UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV , "name of data output file" );
96  m_parser->registerOption<std::string>(m_option_dataOutputAllowedSet, UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV, "subEnvs that will write to data output file" );
97 #ifdef UQ_SIP_READS_SOLVER_OPTION
98  m_parser->registerOption<std::string>(m_option_solver, UQ_SIP_SOLVER_ODV , "algorithm for calibration" );
99 #endif
100  m_parser->registerOption<bool >(m_option_seedWithMAPEstimator, UQ_SIP_SEEDWITHMAPESTIMATOR , "toggle for seeding chain at MAP" );
101  m_parser->registerOption<bool >(m_option_useOptimizerMonitor, UQ_SIP_USEOPTIMIZERMONITOR , "toggle for using optimizer monitor (prints diagnostics");
102 
103  m_parser->scanInputFile();
104 
105  m_parser->getOption<std::string>(m_option_help, m_help);
108  m_parser->getOption<std::set<unsigned int> >(m_option_dataOutputAllowedSet, m_dataOutputAllowedSet);
109 #ifdef UQ_SIP_READS_SOLVER_OPTION
110  m_parser->getOption<std::string>(m_option_solver, m_solver);
111 #endif
114 #else
115  m_help = env->input()(m_option_help, UQ_SIP_HELP);
116  m_computeSolution = env->input()(m_option_computeSolution, UQ_SIP_COMPUTE_SOLUTION_ODV);
117  m_dataOutputFileName = env->input()(m_option_dataOutputFileName, UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV);
118 
119  // UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV is the empty set (string) by default
120  unsigned int size = env->input().vector_variable_size(m_option_dataOutputAllowedSet);
121  for (unsigned int i = 0; i < size; i++) {
122  // We default to empty set, so the default values are actually never
123  // used here
124  unsigned int allowed = env->input()(m_option_dataOutputAllowedSet, i, i);
125  m_dataOutputAllowedSet.insert(allowed);
126  }
127 
128 #ifdef UQ_SIP_READS_SOLVER_OPTION
129  m_solver = env->input()(m_option_solver, UQ_SIP_SOLVER_ODV);
130 #endif
131  m_seedWithMAPEstimator = env->input()(m_option_seedWithMAPEstimator, UQ_SIP_SEEDWITHMAPESTIMATOR);
132  m_useOptimizerMonitor = env->input()(m_option_useOptimizerMonitor, UQ_SIP_USEOPTIMIZERMONITOR);
133 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
134 
135  checkOptions();
136 }
137 // Copy constructor - -----------------------------
139 {
140  this->copy(src);
141 }
142 // Destructor ---------------------------------------
144 {
145 }
146 
147 // Set methods --------------------------------------
150 {
151  this->copy(rhs);
152  return *this;
153 }
154 // Private methods-----------------------------------
155 void
157 {
158  // Nothing
159 }
160 
161 void
163 {
167 #ifdef UQ_SIP_READS_SOLVER_OPTION
169 #endif
172 }
173 
174 std::ostream &
175 operator<<(std::ostream& os, const SipOptionsValues & obj)
176 {
177  os << "\n" << obj.m_option_computeSolution << " = " << obj.m_computeSolution
178  << "\n" << obj.m_option_dataOutputFileName << " = " << obj.m_dataOutputFileName;
179  os << "\n" << obj.m_option_dataOutputAllowedSet << " = ";
180  for (std::set<unsigned int>::iterator setIt = obj.m_dataOutputAllowedSet.begin(); setIt != obj.m_dataOutputAllowedSet.end(); ++setIt) {
181  os << *setIt << " ";
182  }
183 #ifdef UQ_SIP_READS_SOLVER_OPTION
184  << "\n" << obj.m_option_solver << " = " << obj.m_solverString
185 #endif
186  os << std::endl;
187  return os;
188 }
189 
190 // -------------------------------------------------
191 // StatisticalInverseProblemOptions----------
192 // -------------------------------------------------
193 
194 // Default constructor -----------------------------
196  const BaseEnvironment& env,
197  const char* prefix)
198 :
199  m_ov (),
200  m_prefix ((std::string)(prefix) + "ip_"),
201  m_env (env),
202 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
203  m_optionsDesc (new boost::program_options::options_description("Statistical Inverse Problem options")),
204 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
205  m_option_help (m_prefix + "help" ),
206  m_option_computeSolution (m_prefix + "computeSolution" ),
207  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
208  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"),
209 #ifdef UQ_SIP_READS_SOLVER_OPTION
210  m_option_solver (m_prefix + "solver" )
211 #endif
212  m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"),
213  m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor")
214 {
215  queso_deprecated();
216  queso_require_not_equal_to_msg(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"));
217 }
218 
219 // Constructor 2------------------------------------
221  const BaseEnvironment& env,
222  const char* prefix,
223  const SipOptionsValues& alternativeOptionsValues)
224 :
225  m_ov (alternativeOptionsValues),
226  m_prefix ((std::string)(prefix) + "ip_"),
227  m_env (env),
228 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
229  m_optionsDesc (),
230 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
231  m_option_help (m_prefix + "help" ),
232  m_option_computeSolution (m_prefix + "computeSolution" ),
233  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
234  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"),
235 #ifdef UQ_SIP_READS_SOLVER_OPTION
236  m_option_solver (m_prefix + "solver" )
237 #endif
238  m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"),
239  m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor")
240 {
241  queso_deprecated();
242 
243  queso_require_equal_to_msg(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"));
244 
245  if (m_env.subDisplayFile() != NULL) {
246  *m_env.subDisplayFile() << "In StatisticalInverseProblemOptions::constructor(2)"
247  << ": after setting values of options with prefix '" << m_prefix
248  << "', state of object is:"
249  << "\n" << *this
250  << std::endl;
251  }
252 }
253 // Destructor --------------------------------------
255 {
256  queso_deprecated();
257 }
258 
259 // I/O methods --------------------------------------
260 void
262 {
263 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
264  queso_require_msg(m_optionsDesc, "m_optionsDesc variable is NULL");
265 
269 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
270 
271  if (m_env.subDisplayFile() != NULL) {
272  *m_env.subDisplayFile() << "In StatisticalInverseProblemOptions::scanOptionsValues()"
273  << ": after reading values of options with prefix '" << m_prefix
274  << "', state of object is:"
275  << "\n" << *this
276  << std::endl;
277  }
278 
279  return;
280 }
281 
282 // --------------------------------------------------
283 void
285 {
286  queso_deprecated();
287 
288  os << "\n" << m_option_computeSolution << " = " << m_ov.m_computeSolution
290  os << "\n" << m_option_dataOutputAllowedSet << " = ";
291  for (std::set<unsigned int>::iterator setIt = m_ov.m_dataOutputAllowedSet.begin(); setIt != m_ov.m_dataOutputAllowedSet.end(); ++setIt) {
292  os << *setIt << " ";
293  }
294 #ifdef UQ_SIP_READS_SOLVER_OPTION
295  << "\n" << m_option_solver << " = " << m_ov.m_solverString
296 #endif
299  os << std::endl;
300 
301  return;
302 }
303 
304 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
305 void
306 StatisticalInverseProblemOptions::defineMyOptions(boost::program_options::options_description& optionsDesc) const
307 {
308  queso_deprecated();
309 
310  optionsDesc.add_options()
311  (m_option_help.c_str(), "produce help message for statistical inverse problem")
312  (m_option_computeSolution.c_str(), boost::program_options::value<bool >()->default_value(UQ_SIP_COMPUTE_SOLUTION_ODV ), "compute solution process" )
313  (m_option_dataOutputFileName.c_str(), boost::program_options::value<std::string>()->default_value(UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV ), "name of data output file" )
314  (m_option_dataOutputAllowedSet.c_str(), boost::program_options::value<std::string>()->default_value(UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV), "subEnvs that will write to data output file" )
315 #ifdef UQ_SIP_READS_SOLVER_OPTION
316  (m_option_solver.c_str(), boost::program_options::value<std::string>()->default_value(UQ_SIP_SOLVER_ODV ), "algorithm for calibration" )
317 #endif
318  (m_option_seedWithMAPEstimator.c_str(), boost::program_options::value<bool>()->default_value(UQ_SIP_SEEDWITHMAPESTIMATOR), "toggle optimisation of posterior pdf before sampling")
319  (m_option_useOptimizerMonitor.c_str(), boost::program_options::value<bool>()->default_value(UQ_SIP_USEOPTIMIZERMONITOR), "toggle printing of optimisation progress when seed with MAP estimator")
320  ;
321 }
322 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
323 
324 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
325 //--------------------------------------------------
326 void
327 StatisticalInverseProblemOptions::getMyOptionValues(boost::program_options::options_description& optionsDesc)
328 {
329  queso_deprecated();
330 
331  if (m_env.allOptionsMap().count(m_option_help)) {
332  if (m_env.subDisplayFile()) {
333  *m_env.subDisplayFile() << optionsDesc
334  << std::endl;
335  }
336  }
337 
339  m_ov.m_computeSolution = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_computeSolution]).as<bool>();
340  }
341 
343  m_ov.m_dataOutputFileName = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_dataOutputFileName]).as<std::string>();
344  }
345 
348  std::vector<double> tmpAllow(0,0.);
349  std::string inputString = m_env.allOptionsMap()[m_option_dataOutputAllowedSet].as<std::string>();
350  MiscReadDoublesFromString(inputString,tmpAllow);
351 
352  if (tmpAllow.size() > 0) {
353  for (unsigned int i = 0; i < tmpAllow.size(); ++i) {
354  m_ov.m_dataOutputAllowedSet.insert((unsigned int) tmpAllow[i]);
355  }
356  }
357  }
358 
359 #ifdef UQ_SIP_READS_SOLVER_OPTION
360  if (m_env.allOptionsMap().count(m_option_solver)) {
361  m_ov.m_solverString = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_solver]).as<std::string>();
362  }
363 #endif
364 
366  m_ov.m_seedWithMAPEstimator = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_seedWithMAPEstimator]).as<bool>();
367  }
368 
370  m_ov.m_useOptimizerMonitor = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_useOptimizerMonitor]).as<bool>();
371  }
372 }
373 #endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
374 
375 // --------------------------------------------------
376 // Operator declared outside class definition ------
377 // --------------------------------------------------
378 
379 std::ostream& operator<<(std::ostream& os, const StatisticalInverseProblemOptions& obj)
380 {
381  queso_deprecated();
382  obj.print(os);
383 
384  return os;
385 }
386 
387 } // End namespace QUESO
void print(std::ostream &os) const
It prints the option values.
ScopedPtr< boost::program_options::options_description >::Type m_optionsDesc
ScopedPtr< BoostInputOptionsParser >::Type m_parser
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:198
std::string m_help
If this string is non-empty, options are print to the output file.
void copy(const SipOptionsValues &src)
Copies the option values from src to this.
boost::program_options::variables_map & allOptionsMap() const
Definition: Environment.C:386
std::set< unsigned int > m_dataOutputAllowedSet
std::ostream & operator<<(std::ostream &os, const SequenceStatisticalOptions &obj)
const GetPot & input() const
The GetPot input file parser.
Definition: Environment.C:1149
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix queso_require_not_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"))
StatisticalInverseProblemOptions(const BaseEnvironment &env, const char *prefix)
Constructor: reads options from the input file.
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:354
This class provides options for a Statistical Inverse Problem if no input file is available...
void scanOptionsValues()
It scans the option values from the options input file.
This class reads option values for a Statistical Inverse Problem from an input file.
void getMyOptionValues(boost::program_options::options_description &optionsDesc)
Gets the option values of the SIP.
void MiscReadDoublesFromString(const std::string &inputString, std::vector< double > &outputDoubles)
Definition: Miscellaneous.C:40
void scanInputFileForMyOptions(const boost::program_options::options_description &optionsDesc) const
This method scans the input file provided by the user to QUESO.
Definition: Environment.C:397
SipOptionsValues & operator=(const SipOptionsValues &rhs)
Assignment operator; it copies rhs to this.
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
void defineMyOptions(boost::program_options::options_description &optionsDesc) const
Define my SIP options as the default options.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320

Generated on Tue Jun 5 2018 19:48:56 for queso-0.57.1 by  doxygen 1.8.5