![]() |
UtilsLite
Utilities for C++ programming
|
Implements the Nelder-Mead optimization algorithm for nonlinear optimization problems. More...
#include <Utils_NelderMead.hh>
Public Types | |
using | Vec_t = Eigen::Matrix<Real,Eigen::Dynamic,1> |
using | Mat_t = Eigen::Matrix<Real,Eigen::Dynamic,Eigen::Dynamic> |
using | MapVec = Eigen::Map<Vec_t> |
using | MapMat = Eigen::Map<Mat_t> |
using | integer = int |
using | NMFunc = std::function<Real(Real const[])> |
using | NM_move |
Public Member Functions | |
NelderMead (string_view name) | |
Constructor that initializes the NelderMead instance with a specific name. | |
string_view | name (void) const |
Get the name of the class. | |
void | setup (integer dim, NMFunc &fun, Console const *console) |
Setup the optimizer with the function and console interface. | |
void | change_console (Console const *console) |
Change the console output interface. | |
void | set_verbose (integer level) |
Set the verbosity level for logging during the optimization process. | |
void | set_tolerance (Real tol) |
Set the tolerance for stopping criteria in the optimization process. | |
void | set_max_iterations (integer mit) |
Set the maximum number of iterations allowed in the optimization process. | |
void | set_max_fun_evaluation (integer mfev) |
Set the maximum number of function evaluations allowed in the optimization process. | |
void | message (Real tol) const |
Display a message with information about the current tolerance level. | |
string | info () const |
Provide information about the current state of the Nelder-Mead optimization. | |
void | print_info (ostream_type &stream) const |
Print detailed information about the current state of the Nelder-Mead optimizer. | |
bool | search () |
Perform the search step of the optimization process. | |
bool | run (Real const x_sol[], Real h) |
Run the optimization process starting from an initial guess and step size. | |
Real | get_last_solution (Real x[]) const |
Get the solution found by the Nelder-Mead algorithm after the last run. | |
Real | get_better_value () const |
Get the best function value found during the optimization process. | |
Real | get_worst_value () const |
Get the worst function value encountered during the optimization process. | |
Static Public Member Functions | |
static string | to_string (NM_move n) |
Implements the Nelder-Mead optimization algorithm for nonlinear optimization problems.
The Nelder-Mead algorithm is a widely used simplex-based method for minimizing an objective function in multiple dimensions. It is especially useful for problems where derivative information is not readily available or when the objective function is noisy.
Real | The numeric type used for calculations, typically float or double . |
This implementation of the Nelder-Mead algorithm is based on several foundational works:
using Utils::NelderMead< Real >::integer = int |
using Utils::NelderMead< Real >::MapMat = Eigen::Map<Mat_t> |
using Utils::NelderMead< Real >::MapVec = Eigen::Map<Vec_t> |
using Utils::NelderMead< Real >::Mat_t = Eigen::Matrix<Real,Eigen::Dynamic,Eigen::Dynamic> |
using Utils::NelderMead< Real >::NM_move |
using Utils::NelderMead< Real >::NMFunc = std::function<Real(Real const[])> |
using Utils::NelderMead< Real >::Vec_t = Eigen::Matrix<Real,Eigen::Dynamic,1> |
|
inlineexplicit |
Constructor that initializes the NelderMead instance with a specific name.
name | The name to be assigned to this instance of the Nelder-Mead optimizer. |
|
inline |
Change the console output interface.
console | A pointer to the new console object for logging. |
|
inline |
Get the best function value found during the optimization process.
|
inline |
Get the solution found by the Nelder-Mead algorithm after the last run.
x | An array to store the solution values (the optimizer writes the solution here). |
|
inline |
Get the worst function value encountered during the optimization process.
string Utils::NelderMead< Real >::info | ( | ) | const |
Provide information about the current state of the Nelder-Mead optimization.
void Utils::NelderMead< Real >::message | ( | Real | tol | ) | const |
Display a message with information about the current tolerance level.
tol | The tolerance level for which a message should be displayed. |
|
inline |
Get the name of the class.
|
inline |
Print detailed information about the current state of the Nelder-Mead optimizer.
stream | The output stream where the information will be printed. |
bool Utils::NelderMead< Real >::run | ( | Real const | x_sol[], |
Real | h ) |
Run the optimization process starting from an initial guess and step size.
x_sol | An array containing the initial guess for the solution. |
h | The initial step size for the simplex search. |
bool Utils::NelderMead< Real >::search | ( | ) |
Perform the search step of the optimization process.
void Utils::NelderMead< Real >::set_max_fun_evaluation | ( | integer | mfev | ) |
Set the maximum number of function evaluations allowed in the optimization process.
mfev | The maximum number of function evaluations. |
void Utils::NelderMead< Real >::set_max_iterations | ( | integer | mit | ) |
Set the maximum number of iterations allowed in the optimization process.
mit | The maximum number of iterations to be performed. |
void Utils::NelderMead< Real >::set_tolerance | ( | Real | tol | ) |
Set the tolerance for stopping criteria in the optimization process.
tol | The tolerance value, typically a small positive number (e.g., 1e-6). |
|
inline |
Set the verbosity level for logging during the optimization process.
level | The verbosity level (higher values produce more detailed output). |
void Utils::NelderMead< Real >::setup | ( | integer | dim, |
NMFunc & | fun, | ||
Console const * | console ) |
Setup the optimizer with the function and console interface.
dim | The dimensionality of the optimization problem. |
fun | A reference to the function to be minimized. |
console | A pointer to the console for output logging during optimization. |
|
inlinestatic |