|
Optimist
0.0.0
A C++ library for optimization
|
Class container for the generic root-finding/optimization problem solver. More...
#include <SolverBase.hh>
Public Types | |
| using | InputType |
| using | OutputType |
| using | TraceType = typename std::vector<InputType> |
| using | FirstDerivativeType |
| using | SecondDerivativeType |
Public Member Functions | |
| SolverBase () | |
| template<typename FunctionLambda> | |
| SolverBase (FunctionLambda &&function, InputType const &x_ini, InputType &x_sol) | |
| template<typename FunctionLambda, typename FirstDerivativeLambda> | |
| SolverBase (FunctionLambda &&function, FirstDerivativeLambda &&first_derivative, InputType const &x_ini, InputType &x_sol) | |
| template<typename FunctionLambda, typename FirstDerivativeLambda, typename SecondDerivativeLambda> | |
| SolverBase (FunctionLambda &&function, FirstDerivativeLambda &&first_derivative, SecondDerivativeLambda &&second_derivative, InputType const &x_ini, InputType &x_sol) | |
| InputType const & | lower_bound () const |
| void | lower_bound (InputType const &t_lower_bound) |
| InputType const & | upper_bound () const |
| void | upper_bound (InputType const &t_upper_bound) |
| void | bounds (InputType const &t_lower_bound, InputType const &t_upper_bound) |
| constexpr Integer | input_dimension () const |
| constexpr Integer | output_dimension () const |
| Integer | function_evaluations () const |
| void | max_function_evaluations (Integer t_max_function_evaluations) |
| Integer | max_function_evaluations () const |
| Integer | iterations () const |
| Integer | max_iterations () const |
| void | max_iterations (Integer t_max_iterations) |
| Real | alpha () const |
| void | alpha (Real t_alpha) |
| Integer | relaxations () const |
| Integer | max_relaxations () const |
| void | max_relaxations (Integer t_max_relaxations) |
| Real | tolerance () const |
| void | tolerance (Real t_tolerance) |
| void | verbose_mode (bool t_verbose) |
| bool | verbose_mode () const |
| void | enable_verbose_mode () |
| void | disable_verbose_mode () |
| void | damped_mode (bool t_damped) |
| bool | damped_mode () const |
| void | enable_damped_mode () |
| void | disable_damped_mode () |
| std::string | task () const |
| void | task (std::string t_task) |
| bool | converged () const |
| const TraceType & | trace () const |
| std::ostream & | ostream () const |
| void | ostream (std::ostream &t_ostream) |
| template<typename FunctionLambda> | |
| bool | solve (FunctionLambda &&function, InputType const &x_ini, InputType &x_sol) |
| template<typename FunctionLambda, typename FirstDerivativeLambda> | |
| bool | solve (FunctionLambda &&function, FirstDerivativeLambda &&first_derivative, InputType const &x_ini, InputType &x_sol) |
| template<typename FunctionLambda, typename FirstDerivativeLambda, typename SecondDerivativeLambda> | |
| bool | solve (FunctionLambda &&function, FirstDerivativeLambda &&first_derivative, SecondDerivativeLambda &&second_derivative, InputType const &x_ini, InputType &x_sol) |
| template<Integer FunInDim, Integer FunOutDim, typename DerivedFunction> | |
| bool | rootfind (FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen &&FunOutDim==1 > const &function, InputType const &x_ini, InputType &x_sol) |
| template<Integer FunInDim, Integer FunOutDim, typename DerivedFunction> | |
| bool | optimize (FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen &&FunOutDim==1 > const &function, InputType const &x_ini, InputType &x_sol) |
| std::string | name () const |
Protected Member Functions | |
| Integer | first_derivative_evaluations () const |
| Integer | max_first_derivative_evaluations () const |
| void | max_first_derivative_evaluations (Integer first_derivative_evaluations) |
| Integer | second_derivative_evaluations () const |
| Integer | max_second_derivative_evaluations () const |
| void | max_second_derivative_evaluations (Integer second_derivative_evaluations) |
| template<Integer FunInDim, Integer FunOutDim, typename DerivedFunction> | |
| bool | solve (FunctionBase< Real, FunInDim, FunOutDim, DerivedFunction, ForceEigen &&FunOutDim==1 > const &function, InputType const &x_ini, InputType &x_sol, bool is_optimization) |
| void | reset () |
| template<typename FunctionLambda> | |
| bool | evaluate_function (FunctionLambda &&function, InputType const &x, OutputType &out) |
| template<typename FirstDerivativeLambda> | |
| bool | evaluate_first_derivative (FirstDerivativeLambda &&function, InputType const &x, FirstDerivativeType &out) |
| template<typename SecondDerivativeLambda> | |
| bool | evaluate_second_derivative (SecondDerivativeLambda &&function, InputType const &x, SecondDerivativeType &out) |
| void | store_trace (InputType const &x) |
| template<typename FunctionLambda> | |
| bool | damp (FunctionLambda &&function, InputType const &x_old, InputType const &function_old, InputType const &step_old, InputType &x_new, InputType &function_new, InputType &step_new) |
| void | header () |
| void | bottom () |
| void | info (Real residuals, std::string const ¬es="-") |
Protected Attributes | |
| InputType | m_lower_bound |
| InputType | m_upper_bound |
| Integer | m_function_evaluations {0} |
| Integer | m_first_derivative_evaluations {0} |
| Integer | m_second_derivative_evaluations {0} |
| Integer | m_max_function_evaluations {1000} |
| Integer | m_max_first_derivative_evaluations {1000} |
| Integer | m_max_second_derivative_evaluations {1000} |
| Integer | m_iterations {0} |
| Integer | m_max_iterations {100} |
| Real | m_alpha {0.8} |
| Integer | m_relaxations {0} |
| Integer | m_max_relaxations {10} |
| Real | m_tolerance {EPSILON_LOW} |
| bool | m_verbose {false} |
| bool | m_damped {true} |
| std::ostream * | m_ostream {&std::cout} |
| std::string | m_task {"Undefined"} |
| bool | m_converged {false} |
| TraceType | m_trace |
The solvers implemented in Optimist are derived from the Solver class, which provides a common interface for solving nonlinear systems of equations. The Solver class is an abstract base class that defines the methods and attributes required by the derived classes. The derived classes implement the specific algorithms for solving the nonlinear systems of equations.
This class provides a base class for developing solvers that handle a generic function \(\mathbf{f}(\mathbf{x}): \mathbb{R}^{n} \rightarrow \mathbb{R}^{m}\). In general, the derived classes are designed to solve root-finding problems of the form
\[ \mathbf{f}(\mathbf{x}) = \mathbf{0} \text{,} \quad \text{with} \quad \mathbf{f}: \mathbb{R}^{n} \rightarrow \mathbb{R}^{n} \text{,} \]
as well as optimization problems of the form
\[ \min_{\mathbf{x}} f(\mathbf{x}) \text{,} \quad f: \mathbb{R}^{n} \rightarrow \mathbb{R} \text{.} \]
If \(n > 1\) the solver is a multi-dimensional solver, otherwise, it is a scalar solver. The linear algebra operations are performed using the Eigen library, which provides a high-level interface for matrix operations. Otherwise, for \(n = 1\), the base type changes to Real, a scalar type defined in the Optimist library.
| Real | Scalar number type. |
| SolInDim | The root-finding/optimization problem input dimension. |
| SolOutDim | The root-finding/optimization problem output dimension. |
| DerivedSolver | Derived solver class. |
| ForceEigen | Force the use of Eigen types for input and output. |
| using Optimist::SolverBase< Real, SolInDim, SolOutDim, DerivedSolver, ForceEigen >::FirstDerivativeType |
| using Optimist::SolverBase< Real, SolInDim, SolOutDim, DerivedSolver, ForceEigen >::InputType |
| using Optimist::SolverBase< Real, SolInDim, SolOutDim, DerivedSolver, ForceEigen >::OutputType |
| using Optimist::SolverBase< Real, SolInDim, SolOutDim, DerivedSolver, ForceEigen >::SecondDerivativeType |
| using Optimist::SolverBase< Real, SolInDim, SolOutDim, DerivedSolver, ForceEigen >::TraceType = typename std::vector<InputType> |
|
inline |
Class constructor for the nonlinear solver.
|
inline |
|
inline |
|
inline |
Class constructor for the nonlinear solver.
| FunctionLambda | Function lambda type. |
| FirstDerivativeLambda | First derivative lambda type. |
| SecondDerivativeLambda | Second derivative lambda type. |
| [in] | function | Function lambda. |
| [in] | first_derivative | First derivative lambda. |
| [in] | second_derivative | The second derivative lambda. |
| [in] | x_ini | Initialization point. |
| [out] | x_sol | Solution point. |
|
inline |
Get relaxation factor \( \alpha \).
|
inline |
Set relaxation factor \( \alpha \).
| [in] | t_alpha | The relaxation factor \( \alpha \). |
|
inlineprotected |
Print the table bottom solver information.
|
inline |
Set the bounds.
| [in] | t_lower_bound | The lower bound. |
| [in] | t_upper_bound | The upper bound. |
|
inline |
Get the convergence boolean flag.
|
inlineprotected |
Damp the step using the affine invariant criterion.
| FunctionLambda | Function lambda type. |
| [in] | function | Function lambda. |
| [in] | x_old | Old point. |
| [in] | function_old | Old function value. |
| [in] | step_old | Old step. |
| [in] | x_new | New point. |
| [in] | function_new | New function value. |
| [out] | step_new | New step. |
|
inline |
Get the damped mode boolean flag.
|
inline |
Set the damped mode boolean flag.
| [in] | t_damped | The damped mode boolean flag. |
|
inline |
Disable solver's damped mode.
|
inline |
Disable solver's verbose mode.
|
inline |
Enable solver's damped mode.
|
inline |
Enable solver's verbose mode.
|
inlineprotected |
Evaluate the first derivative.
| FirstDerivativeLambda | First derivative lambda type. |
| [in] | function | First derivative lambda. |
| [in] | x | Input point. |
| [out] | out | First derivative value. |
|
inlineprotected |
|
inlineprotected |
Evaluate the second derivative.
| [in] | function | Second derivative lambda. |
| [in] | x | Input point. |
| [out] | out | Second derivative value. |
|
inlineprotected |
Get the number of function derivative evaluations.
|
inline |
Get the number of function evaluations.
|
inlineprotected |
Print the table header solver information.
|
inlineprotected |
Print the solver information during the algorithm iterations.
|
inlineconstexpr |
Get the input dimension of the function.
|
inline |
Get the number of algorithm iterations.
|
inline |
Get the lower bound.
|
inline |
Set the lower bound.
| [in] | t_lower_bound | The lower bound. |
|
inlineprotected |
Get the number of maximum allowed first derivative evaluations.
|
inlineprotected |
Set the number of maximum allowed first derivative evaluations.
| [in] | first_derivative_evaluations | The number of maximum allowed first derivative evaluations. |
|
inline |
Get the number of maximum allowed function evaluations.
|
inline |
Set the number of maximum allowed function evaluations.
| [in] | t_max_function_evaluations | The number of maximum allowed function evaluations. |
|
inline |
Get the number of maximum allowed iterations.
|
inline |
Set the number of maximum allowed iterations.
| [in] | t_max_iterations | The number of maximum allowed iterations. |
|
inline |
Get the number of maximum allowed relaxations.
|
inline |
Set the number of maximum allowed relaxations.
| [in] | t_max_relaxations | The number of maximum allowed relaxations. |
|
inlineprotected |
Get the number of maximum allowed second derivative evaluations.
|
inlineprotected |
Set the number of maximum allowed second derivative evaluations.
| [in] | second_derivative_evaluations | The number of maximum allowed second derivative evaluations. |
|
inline |
Get the solver name.
|
inline |
Solve the optimization problem given a function class.
| [in] | function | Function class. |
| [in] | x_ini | Initialization point. |
| [out] | x_sol | Solution point. |
| FunInDim | The function output dimension. |
| FunOutDim | The function output dimension. |
| DerivedFunction | Derived function class. |
|
inline |
Get the output stream for verbose mode.
|
inline |
Set the output stream for verbose mode.
| [in] | t_ostream | The output stream for verbose mode. |
|
inlineconstexpr |
Get the output dimension of the function.
|
inline |
Get the number of algorithm relaxations.
|
inlineprotected |
Reset solver internal counters and variables.
|
inline |
Solve the root-finding problem given a function class.
| [in] | function | Function class. |
| [in] | x_ini | Initialization point. |
| [out] | x_sol | Solution point. |
| FunInDim | The function output dimension. |
| FunOutDim | The function output dimension. |
| DerivedFunction | Derived function class. |
|
inlineprotected |
Get the number of second derivative evaluations.
|
inlineprotected |
Solve the root-finding/optimization problem given a function class.
| [in] | function | Function class. |
| [in] | x_ini | Initialization point. |
| [out] | x_sol | Solution point. |
| [in] | is_optimization | Boolean flag for optimization. |
| FunInDim | The function output dimension. |
| FunOutDim | The function output dimension. |
| DerivedFunction | Derived function class. |
|
inline |
Solve the root-finding/optimization problem given the function, and its first derivative.
| FunctionLambda | First derivative lambda type. |
| FirstDerivativeLambda | Function lambda type. |
| [in] | function | Function lambda. |
| [in] | first_derivative | First derivative lambda |
| [in] | x_ini | Initialization point. |
| [out] | x_sol | Solution point. |
|
inline |
Solve the root-finding/optimization problem given the function, and its first and second derivatives.
| FunctionLambda | Function lambda type. |
| FirstDerivativeLambda | First derivative lambda type. |
| SecondDerivativeLambda | Second derivative lambda type. |
| [in] | function | Function lambda. |
| [in] | first_derivative | First derivative lambda. |
| [in] | second_derivative | The second derivative lambda. |
| [in] | x_ini | Initialization point. |
| [out] | x_sol | Solution point. |
|
inline |
|
inlineprotected |
Update the history of the solver with the current point and function value.
| [in] | x | The point \( \mathbf{x} \). |
|
inline |
Get the task name.
|
inline |
Set the task name.
| [in] | t_task | The task name. |
|
inline |
Get the tolerance \( \epsilon \).
|
inline |
Set the tolerance \( \epsilon \) for which the nonlinear solver stops, i.e., \( \left\| \mathbf{F}(\mathbf{x}) \right\|_{2} < \epsilon \).
| [in] | t_tolerance | The tolerance \( \epsilon \). |
|
inline |
Get the trace of input values during the algorithm iterations.
|
inline |
Get the upper bound.
|
inline |
Set the upper bound.
| [in] | t_upper_bound | The upper bound. |
|
inline |
Get the verbose mode boolean flag.
|
inline |
Set the verbose mode boolean flag.
| [in] | t_verbose | The verbose mode boolean flag. |
|
protected |
Relaxation factor \( \alpha \).
|
protected |
Convergence boolean flag.
|
protected |
Damped mode boolean flag.
|
protected |
First derivative evaluations.
|
protected |
Function evaluations.
|
protected |
Algorithm iterations.
|
protected |
Lower bound.
|
protected |
Maximum allowed first derivative evaluations.
|
protected |
Maximum allowed function evaluations.
|
protected |
Maximum allowed algorithm iterations.
|
protected |
Maximum allowed algorithm relaxations.
|
protected |
Maximum allowed second derivative evaluations.
|
protected |
Output stream for verbose mode.
|
protected |
Algorithm relaxations.
|
protected |
Second derivative evaluations.
|
protected |
Task name.
|
protected |
Solver tolerance \( \epsilon \) for convergence.
|
protected |
Trace for points \( \mathbf{x} \) values.
|
protected |
Upper bound.
|
protected |
Verbose mode boolean flag.