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

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