queso-0.57.0
OptimizerOptions.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 #include <queso/Environment.h>
27 
28 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
29 #include <queso/BoostInputOptionsParser.h>
30 #else
31 #include <queso/getpot.h>
32 #endif
33 
34 #include <queso/OptimizerOptions.h>
35 
36 namespace QUESO {
37 
39  : m_prefix("ip_"),
40  m_help(UQ_OPT_HELP),
41  m_maxIterations(UQ_OPT_MAX_ITERATIONS),
42  m_tolerance(UQ_OPT_TOLERANCE),
43  m_finiteDifferenceStepSize(UQ_OPT_FINITE_DIFFERENCE_STEP_SIZE),
44  m_solverType(UQ_OPT_SOLVER_TYPE),
45  m_fstepSize(UQ_OPT_FSTEP_SIZE),
46  m_fdfstepSize(UQ_OPT_FDFSTEP_SIZE),
47  m_lineTolerance(UQ_OPT_LINE_TOLERANCE),
48  m_env(NULL),
49 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
50  m_parser(NULL),
51 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
52  m_option_help(m_prefix + "help"),
53  m_option_maxIterations(m_prefix + "maxIterations"),
54  m_option_tolerance(m_prefix + "tolerance"),
55  m_option_finiteDifferenceStepSize(m_prefix + "finiteDifferenceStepSize"),
56  m_option_solverType(m_prefix + "solverType"),
57  m_option_fstepSize(m_prefix + "fstepSize"),
58  m_option_fdfstepSize(m_prefix + "fdfStepSize"),
59  m_option_lineTolerance(m_prefix + "lineTolerance")
60 {
61 }
62 
64  prefix)
65  : m_prefix((std::string)(prefix) + "optimizer_"),
66  m_help(UQ_OPT_HELP),
67  m_maxIterations(UQ_OPT_MAX_ITERATIONS),
68  m_tolerance(UQ_OPT_TOLERANCE),
69  m_finiteDifferenceStepSize(UQ_OPT_FINITE_DIFFERENCE_STEP_SIZE),
70  m_solverType(UQ_OPT_SOLVER_TYPE),
71  m_fstepSize(UQ_OPT_FSTEP_SIZE),
72  m_fdfstepSize(UQ_OPT_FDFSTEP_SIZE),
73  m_lineTolerance(UQ_OPT_LINE_TOLERANCE),
74  m_env(env),
75 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
76  m_parser(new BoostInputOptionsParser(env->optionsInputFileName())),
77 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
78  m_option_help(m_prefix + "help"),
79  m_option_maxIterations(m_prefix + "maxIterations"),
80  m_option_tolerance(m_prefix + "tolerance"),
81  m_option_finiteDifferenceStepSize(m_prefix + "finiteDifferenceStepSize"),
82  m_option_solverType(m_prefix + "solverType"),
83  m_option_fstepSize(m_prefix + "fstepSize"),
84  m_option_fdfstepSize(m_prefix + "fdfStepSize"),
85  m_option_lineTolerance(m_prefix + "lineTolerance")
86 {
87 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
88  m_parser->registerOption<std::string>(m_option_help, UQ_OPT_HELP,
89  "produce help message for statistical inverse problem");
90 
92  UQ_OPT_MAX_ITERATIONS,
93  "max number of optimizer iterations to do");
94  m_parser->registerOption<double>(m_option_tolerance, UQ_OPT_TOLERANCE,
95  "optimize until gradient is less than tolerance");
97  UQ_OPT_FINITE_DIFFERENCE_STEP_SIZE,
98  "if no deriv is given, do finite difference with this step size");
99  m_parser->registerOption<std::string>(m_option_solverType, UQ_OPT_SOLVER_TYPE,
100  "which optimisation algorithm to use");
101  m_parser->registerOption<double>(m_option_fstepSize, UQ_OPT_FSTEP_SIZE,
102  "sets the step size used in gradient-free solvers");
103  m_parser->registerOption<double>(m_option_fdfstepSize, UQ_OPT_FDFSTEP_SIZE,
104  "sets the step size used in gradient-based solvers");
105  m_parser->registerOption<double>(m_option_lineTolerance, UQ_OPT_LINE_TOLERANCE,
106  "sets the line minimisation tolerance");
107 
109 
110  m_parser->getOption<std::string>(m_option_help, m_help);
119 #else
120  m_help = m_env->input()(m_option_help, UQ_OPT_HELP);
121  m_maxIterations = m_env->input()(m_option_maxIterations, UQ_OPT_MAX_ITERATIONS);
122  m_tolerance = m_env->input()(m_option_tolerance, UQ_OPT_TOLERANCE);
123  m_finiteDifferenceStepSize = m_env->input()(m_option_finiteDifferenceStepSize, UQ_OPT_FINITE_DIFFERENCE_STEP_SIZE);
124  m_solverType = m_env->input()(m_option_solverType, UQ_OPT_SOLVER_TYPE);
125  m_fstepSize = m_env->input()(m_option_fstepSize, UQ_OPT_FSTEP_SIZE);
126  m_fdfstepSize = m_env->input()(m_option_fdfstepSize, UQ_OPT_FDFSTEP_SIZE);
127  m_lineTolerance = m_env->input()(m_option_lineTolerance, UQ_OPT_LINE_TOLERANCE);
128 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
129 
130  checkOptions();
131 }
132 
134  :
135  m_prefix(rhs.m_prefix),
136  m_help(rhs.m_help),
137  m_maxIterations(rhs.m_maxIterations),
138  m_tolerance(rhs.m_tolerance),
139  m_finiteDifferenceStepSize(rhs.m_finiteDifferenceStepSize),
140  m_solverType(rhs.m_solverType),
141  m_fstepSize(rhs.m_fstepSize),
142  m_fdfstepSize(rhs.m_fdfstepSize),
143  m_lineTolerance(rhs.m_lineTolerance),
144  m_parser(rhs.m_parser), // We'll never touch the input file in a copied object
145  m_option_help(rhs.m_option_help),
146  m_option_maxIterations(rhs.m_option_maxIterations),
147  m_option_tolerance(rhs.m_option_tolerance),
148  m_option_finiteDifferenceStepSize(rhs.m_option_finiteDifferenceStepSize),
149  m_option_solverType(rhs.m_option_solverType),
150  m_option_fstepSize(rhs.m_option_fstepSize),
151  m_option_fdfstepSize(rhs.m_option_fdfstepSize),
152  m_option_lineTolerance(rhs.m_option_lineTolerance)
153 {
154 }
155 
157 {
158 }
159 
160 void
162 {
163  queso_require_greater_msg(m_tolerance, 0.0, "optimizer tolerance must be > 0");
164  queso_require_greater_msg(m_finiteDifferenceStepSize, 0.0, "finite difference step must be > 0");
165  queso_require_greater_msg(m_maxIterations, 0, "max iterations must be > 0");
166  queso_require_greater_msg(m_fstepSize, 0.0, "fstepSize must be > 0");
167  queso_require_greater_msg(m_fdfstepSize, 0.0, "fdfstepSize must be > 0");
168  queso_require_greater_msg(m_lineTolerance, 0.0, "line tolerance must be > 0");
169 }
170 
171 std::ostream &
172 operator<<(std::ostream& os, const OptimizerOptions & obj)
173 {
174  os << "\n" << obj.m_option_maxIterations << " = " << obj.m_maxIterations
175  << "\n" << obj.m_option_tolerance << " = " << obj.m_tolerance;
176  os << "\n" << obj.m_option_finiteDifferenceStepSize << " = "
178  os << "\n" << obj.m_option_solverType << " = " << obj.m_solverType;
179  os << "\n" << obj.m_option_fstepSize << " = " << obj.m_fstepSize;
180  os << "\n" << obj.m_option_fdfstepSize << " = " << obj.m_fdfstepSize;
181  os << "\n" << obj.m_option_lineTolerance << " = " << obj.m_lineTolerance;
182  os << std::endl;
183  return os;
184 }
185 
186 } // End namespace QUESO
double m_finiteDifferenceStepSize
The step size used to compute gradients from finite differencing. Default is 1e-4.
std::string m_solverType
The optimization algorithm to use. Default is bfgs2.
std::ostream & operator<<(std::ostream &os, const SequenceStatisticalOptions &obj)
std::string m_help
If this string is non-empty, options are print to the output file.
void getOption(const std::string &name, T &value) const
Get option name from the parser and set value to the parsed value.
BoostInputOptionsParser * m_parser
double m_tolerance
The tolerance at which optimization stops. Default is 1e-3.
void registerOption(const std::string &name, const T &defaultValue, const std::string &description)
Call this to register an option with the parser.
std::string m_option_finiteDifferenceStepSize
Option name for OptimizerOptions::m_finiteDifferenceStepSize. Default is m_prefix + &quot;optimizer_finite...
std::string m_option_solverType
Option name for OptimizerOptions::m_solverType. Default is m_prefix + &quot;optimizer_solverType&quot;.
std::string m_option_lineTolerance
Option name for OptimizerOptions::m_lineTolerance. Default is m_prefix + &quot;optimizer_lineTolerance&quot;.
unsigned int m_maxIterations
The maximum number of iterations to do for optimization. Default is 100.
void scanInputFile()
This is the method that parses the input file.
double m_fstepSize
The size of the initial trial steps for optimizing without gradients. Default is 0.1.
const BaseEnvironment * m_env
virtual ~OptimizerOptions()
Destructor.
const GetPot & input() const
The GetPot input file parser.
Definition: Environment.C:1149
OptimizerOptions()
Default constructor. All options have their default values.
std::string m_option_tolerance
Option name for OptimizerOptions::m_tolerance. Default is m_prefix + &quot;optimizer_tolerance&quot;.
std::string m_option_fdfstepSize
Option name for OptimizerOptions::m_fdfstepSize. Default is m_prefix + &quot;optimizer_fdfStepSize&quot;.
std::string m_option_fstepSize
Option name for OptimizerOptions::m_fstepSize. Default is m_prefix + &quot;optimizer_fstepSize&quot;.
double m_lineTolerance
Accuracy to which to solve line minization to. Default is 0.1.
double m_fdfstepSize
The size of the first step when optimizing with gradients. Default is 1.0.
This class provides options for a Optimizer.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:198
std::string m_option_maxIterations
Option name for OptimizerOptions::m_maxIterations. Default is m_prefix + &quot;optimizer_maxIterations&quot;.

Generated on Sat Apr 22 2017 14:04:35 for queso-0.57.0 by  doxygen 1.8.5