|
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 | InputTrait = TypeTrait<Input> |
| using | OutputTrait = TypeTrait<Output> |
| using | Scalar = typename InputTrait::Scalar |
| using | FirstDerivative |
| using | SecondDerivative |
Public Member Functions | |
| SolverBase () | |
| template<typename FunctionLambda> | |
| SolverBase (FunctionLambda &&function, const Input &x_ini, Input &x_sol) | |
| template<typename FunctionLambda, typename FirstDerivativeLambda> | |
| SolverBase (FunctionLambda &&function, FirstDerivativeLambda &&first_derivative, const Input &x_ini, Input &x_sol) | |
| template<typename FunctionLambda, typename FirstDerivativeLambda, typename SecondDerivativeLambda> | |
| SolverBase (FunctionLambda &&function, FirstDerivativeLambda &&first_derivative, SecondDerivativeLambda &&second_derivative, const Input &x_ini, Input &x_sol) | |
| void | reset_bounds (const Integer n=InputTrait::IsDynamic ? 0 :InputTrait::Dimension) |
| const Input & | lower_bound () const |
| void | lower_bound (const Input &t_lower_bound) |
| const Input & | upper_bound () const |
| void | upper_bound (const Input &t_upper_bound) |
| void | bounds (const Input &t_lower_bound, const Input &t_upper_bound) |
| constexpr Integer | input_dimension () const |
| constexpr Integer | output_dimension () const |
| Integer | function_evaluations () const |
| void | max_function_evaluations (const Integer t_max_function_evaluations) |
| Integer | max_function_evaluations () const |
| Integer | iterations () const |
| Integer | max_iterations () const |
| void | max_iterations (const Integer t_max_iterations) |
| Scalar | alpha () const |
| void | alpha (Scalar t_alpha) |
| Integer | relaxations () const |
| Integer | max_relaxations () const |
| void | max_relaxations (const Integer t_max_relaxations) |
| Scalar | tolerance () const |
| void | tolerance (Scalar 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 |
| std::ostream & | ostream () const |
| void | ostream (std::ostream &t_ostream) |
| template<typename FunctionLambda> | |
| bool | solve (FunctionLambda &&function, const Input &x_ini, Input &x_sol) |
| template<typename FunctionLambda, typename FirstDerivativeLambda> | |
| bool | solve (FunctionLambda &&function, FirstDerivativeLambda &&first_derivative, const Input &x_ini, Input &x_sol) |
| template<typename FunctionLambda, typename FirstDerivativeLambda, typename SecondDerivativeLambda> | |
| bool | solve (FunctionLambda &&function, FirstDerivativeLambda &&first_derivative, SecondDerivativeLambda &&second_derivative, const Input &x_ini, Input &x_sol) |
| template<typename FunctionInput, typename FunctionOutput, typename DerivedFunction> | |
| bool | rootfind (const FunctionBase< FunctionInput, FunctionOutput, DerivedFunction > &function, const Input &x_ini, Input &x_sol) |
| template<typename FunctionInput, typename FunctionOutput, typename DerivedFunction> | |
| bool | optimize (const FunctionBase< FunctionInput, FunctionOutput, DerivedFunction > &function, const Input &x_ini, Input &x_sol) |
| constexpr std::string | name () const |
Protected Member Functions | |
| Integer | first_derivative_evaluations () const |
| Integer | max_first_derivative_evaluations () const |
| void | max_first_derivative_evaluations (const Integer t_first_derivative_evaluations) |
| Integer | second_derivative_evaluations () const |
| Integer | max_second_derivative_evaluations () const |
| void | max_second_derivative_evaluations (const Integer t_second_derivative_evaluations) |
| template<typename FunctionInput, typename FunctionOutput, typename DerivedFunction> | |
| bool | solve (const FunctionBase< FunctionInput, FunctionOutput, DerivedFunction > &function, const Input &x_ini, Input &x_sol, bool is_optimization) |
| void | reset_counters () |
| template<typename FunctionLambda> | |
| bool | evaluate_function (FunctionLambda &&function, const Input &x, Output &out) |
| template<typename FirstDerivativeLambda> | |
| bool | evaluate_first_derivative (FirstDerivativeLambda &&function, const Input &x, FirstDerivative &out) |
| template<typename SecondDerivativeLambda> | |
| bool | evaluate_second_derivative (SecondDerivativeLambda &&function, const Input &x, SecondDerivative &out) |
| template<typename FunctionLambda> | |
| bool | damp (FunctionLambda &&function, const Input &x_old, const Input &function_old, const Input &step_old, Input &x_new, Input &function_new, Input &step_new) |
| void | header () |
| void | bottom () |
| void | info (Scalar residuals, const std::string ¬es="-") |
Protected Attributes | |
| Input | m_lower_bound |
| Input | m_upper_bound |
| Integer | m_function_evaluations {0} |
| Integer | m_first_derivative_evaluations |
| Integer | m_second_derivative_evaluations |
| Integer | m_max_function_evaluations |
| Integer | m_max_first_derivative_evaluations |
| Integer | m_max_second_derivative_evaluations |
| Integer | m_iterations {0} |
| Integer | m_max_iterations {100} |
| Scalar | m_alpha {0.8} |
| Integer | m_relaxations {0} |
| Integer | m_max_relaxations |
| Scalar | m_tolerance |
| bool | m_verbose {false} |
| bool | m_damped {true} |
| std::ostream * | m_ostream {&std::cout} |
| std::string | m_task {"Undefined"} |
| bool | m_converged {false} |
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.
| Input | Solver input type. |
| Output | Solver output type. |
| DerivedSolver | Derived solver class. |
| using Optimist::SolverBase< Input, Output, DerivedSolver >::FirstDerivative |
| using Optimist::SolverBase< Input, Output, DerivedSolver >::InputTrait = TypeTrait<Input> |
| using Optimist::SolverBase< Input, Output, DerivedSolver >::OutputTrait = TypeTrait<Output> |
| using Optimist::SolverBase< Input, Output, DerivedSolver >::Scalar = typename InputTrait::Scalar |
| using Optimist::SolverBase< Input, Output, DerivedSolver >::SecondDerivative |
|
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] | t_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] | t_second_derivative_evaluations | The number of maximum allowed second derivative evaluations. |
|
inlineconstexpr |
Get the solver name.
|
inline |
Solve the optimization problem given a function class.
| FunctionInput | The function input dimension. |
| FunctionOutput | The function output dimension. |
| DerivedFunction | Derived function class. |
| [in] | function | Function class. |
| [in] | x_ini | Initialization point. |
| [out] | x_sol | Solution point. |
|
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.
|
inline |
Reset lower and upper bounds to default values.
| [in] | n | Input dimension for dynamic-size types. |
|
inlineprotected |
Reset internal counters and flags.
|
inline |
Solve the root-finding problem given a function class.
| FunctionInput | The function input dimension. |
| FunctionOutput | The function output dimension. |
| DerivedFunction | Derived function class. |
| [in] | function | Function class. |
| [in] | x_ini | Initialization point. |
| [out] | x_sol | Solution point. |
|
inlineprotected |
Get the number of second derivative evaluations.
|
inlineprotected |
Solve the root-finding/optimization problem given a function class.
| Input | Solver input type. |
| Output | Solver output type. |
| DerivedFunction | Derived function class. |
| [in] | function | Function class. |
| [in] | x_ini | Initialization point. |
| [out] | x_sol | Solution point. |
| [in] | is_optimization | Boolean flag for optimization. |
|
inline |
|
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 |
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 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 |
Upper bound.
|
protected |
Verbose mode boolean flag.