Public Member Functions | Protected Types | Protected Attributes | List of all members
Seldon::NLoptSolver Class Reference

NLopt optimization. More...

#include <NLoptSolver.hxx>

Public Member Functions

 NLoptSolver ()
 Default constructor.
 
 ~NLoptSolver ()
 Destructor.
 
void Initialize (int Nparameter, string algorithm, double parameter_tolerance=1.e-6, double cost_function_tolerance=1.e-6, int Niteration_max=-1)
 Initializations. More...
 
void SetLowerBound (const Vector< double > &)
 Sets lower bounds on the parameters. More...
 
void SetUpperBound (const Vector< double > &)
 Sets upper bounds on the parameters. More...
 
void SetParameterTolerance (double)
 Sets the relative tolerance on the parameters. More...
 
void SetCostFunctionTolerance (double)
 Sets the relative tolerance on the cost function. More...
 
void SetNiterationMax (int)
 Sets the maximum number of cost function evaluations. More...
 
void GetParameterTolerance (double &) const
 Gets the relative tolerance on the parameters. More...
 
void GetCostFunctionTolerance (double &) const
 Gets the relative tolerance on the cost function. More...
 
void GetNiterationMax (int &) const
 Gets the maximum number of cost function evaluations. More...
 
void SetParameter (const Vector< double > &parameter)
 Sets the parameters. More...
 
void GetParameter (Vector< double > &parameter) const
 Gets the parameters. More...
 
void Optimize (cost_ptr cost, void *argument)
 Optimization. More...
 
double GetCost () const
 Returns the value of the cost function. More...
 

Protected Types

typedef double(* cost_ptr) (const Vector< double > &, Vector< double > &, void *)
 

Protected Attributes

nlopt::SeldonOpt opt_
 NLopt optimization solver.
 
nlopt::algorithm algorithm_
 Optimization algorithm.
 
double parameter_tolerance_
 Relative tolerance on the optimization parameters.
 
double cost_function_tolerance_
 Relative tolerance on the cost function.
 
int Niteration_max_
 Maximum number of function evaluations. It is ignored if it is non-positive.
 
Vector< double > parameter_
 The vector that stores parameters values. Before optimization, stores the initial parameter vector; after optimization, it returns the optimized parameters.
 
Vector< double > gradient_
 The vector that stores gradient values. Before optimization, unspecified; after optimization, it returns the gradient vector for optimized parameters.
 
double cost_
 The value of cost function for given parameter values.
 

Detailed Description

NLopt optimization.

Definition at line 38 of file NLoptSolver.hxx.

Member Function Documentation

◆ GetCost()

double Seldon::NLoptSolver::GetCost ( ) const

Returns the value of the cost function.

This method should be called after the optimization, and it returns the value of the cost function associated with the optimized parameters.

Returns
the value of the cost function.

Definition at line 317 of file NLoptSolver.cxx.

◆ GetCostFunctionTolerance()

void Seldon::NLoptSolver::GetCostFunctionTolerance ( double &  tolerance) const

Gets the relative tolerance on the cost function.

Parameters
[out]tolerancerelative tolerance on the cost function . When the variation of the cost function, after one step of the algorithm, has changed by less than tolerance multiplied by the value of the cost function, the optimization is stopped.

Definition at line 241 of file NLoptSolver.cxx.

◆ GetNiterationMax()

void Seldon::NLoptSolver::GetNiterationMax ( int &  Niteration_max) const

Gets the maximum number of cost function evaluations.

Parameters
[out]Niteration_maxmaximum number of cost function evaluations.

Definition at line 251 of file NLoptSolver.cxx.

◆ GetParameter()

void Seldon::NLoptSolver::GetParameter ( Vector< double > &  parameter) const

Gets the parameters.

Parameters
[out]parameterthe parameters vector.

Definition at line 272 of file NLoptSolver.cxx.

◆ GetParameterTolerance()

void Seldon::NLoptSolver::GetParameterTolerance ( double &  tolerance) const

Gets the relative tolerance on the parameters.

Parameters
[out]tolerancerelative tolerance on the parameters . When the variation of every parameter, after one step of the algorithm, has changed by less than tolerance multiplied by the value of the parameter, the optimization is stopped.

Definition at line 228 of file NLoptSolver.cxx.

◆ Initialize()

void Seldon::NLoptSolver::Initialize ( int  Nparameter,
string  algorithm,
double  parameter_tolerance = 1.e-6,
double  cost_function_tolerance = 1.e-6,
int  Niteration_max = -1 
)

Initializations.

Parameters
[in]Nparametertotal number of parameters to be optimized.
[in]algorithmname of the optimization algorithm, one of: GN_DIRECT, GN_DIRECT_L, GN_DIRECT_L_RAND, GN_DIRECT_NOSCAL, GN_DIRECT_L_NOSCAL, GN_DIRECT_L_RAND_NOSCAL, GN_ORIG_DIRECT, GN_ORIG_DIRECT_L, GD_STOGO, GD_STOGO_RAND, LD_LBFGS_NOCEDAL, LD_LBFGS, LN_PRAXIS, LD_VAR1, LD_VAR2, LD_TNEWTON, LD_TNEWTON_RESTART, LD_TNEWTON_PRECOND, LD_TNEWTON_PRECOND_RESTART, GN_CRS2_LM, GN_MLSL, GD_MLSL, GN_MLSL_LDS, GD_MLSL_LDS, LD_MMA, LN_COBYLA, LN_NEWUOA, LN_NEWUOA_BOUND, LN_NELDERMEAD, LN_SBPLX, LN_AUGLAG, LD_AUGLAG, LN_AUGLAG_EQ, LD_AUGLAG_EQ, LN_BOBYQA, GN_ISRES, AUGLAG, AUGLAG_EQ, G_MLSL, G_MLSL_LDS, LD_SLSQP, NUM_ALGORITHMS.
[in]parameter_tolerancerelative tolerance on the parameters. When the variation of the parameters, after one step of the algorithm, has changed by less than parameter_tolerance multiplied by the value of the parameters, the optimization is stopped. If you do not want to use a particular tolerance termination, you can just set that tolerance to zero and it will be ignored.
[in]cost_function_tolerancerelative tolerance on the cost function. When the variation of the cost function, after one step of the algorithm, has changed by less than cost_function_tolerance multiplied by the value of the cost function, the optimization is stopped. If you do not want to use a particular tolerance termination, you can just set that tolerance to zero and it will be ignored.
[in]Niteration_maxmaximum number of cost function evaluations. It is ignored if it is non-positive.

Definition at line 72 of file NLoptSolver.cxx.

◆ Optimize()

void Seldon::NLoptSolver::Optimize ( cost_ptr  cost,
void *  argument 
)

Optimization.

Parameters
[in]costpointer to the cost function. This function takes as first argument a 'const Vector<double>&' of parameters. The second argument of the function is a 'Vector<double>&' which must be, on exit, the gradient of the cost function. NLopt will allocate it before the call. Note that, in case a derivative-free algorithm is used, this gradient vector is empty, and the cost function is not supposed to compute it (it is thus recommended to test the length of the vector in the cost function). The third argument of the function is argument, provided as 'void *'. The cost function returns the cost value in 'double'.
[in]argumentthird argument of the cost function. This argument is passed to the cost function after the parameters vector and the gradient.

Definition at line 293 of file NLoptSolver.cxx.

◆ SetCostFunctionTolerance()

void Seldon::NLoptSolver::SetCostFunctionTolerance ( double  tolerance)

Sets the relative tolerance on the cost function.

Parameters
[in]tolerancerelative tolerance on the cost function. When the variation of the cost function, after one step of the algorithm, has changed by less than tolerance multiplied by the value of the cost function, the optimization is stopped. If you do not want to use a particular tolerance termination, you can just set that tolerance to zero and it will be ignored.

Definition at line 204 of file NLoptSolver.cxx.

◆ SetLowerBound()

void Seldon::NLoptSolver::SetLowerBound ( const Vector< double > &  lower_bound)

Sets lower bounds on the parameters.

Parameters
[in]lower_boundthe lower bound vector.

Definition at line 162 of file NLoptSolver.cxx.

◆ SetNiterationMax()

void Seldon::NLoptSolver::SetNiterationMax ( int  Niteration_max)

Sets the maximum number of cost function evaluations.

Parameters
[in]Niteration_maxmaximum number of cost function evaluations. It is ignored if it is non-positive.

Definition at line 215 of file NLoptSolver.cxx.

◆ SetParameter()

void Seldon::NLoptSolver::SetParameter ( const Vector< double > &  parameter)

Sets the parameters.

Parameters
[in]parameterthe parameters vector.

Definition at line 261 of file NLoptSolver.cxx.

◆ SetParameterTolerance()

void Seldon::NLoptSolver::SetParameterTolerance ( double  tolerance)

Sets the relative tolerance on the parameters.

Parameters
[in]tolerancerelative tolerance on the parameters. When the variation of every parameter, after one step of the algorithm, has changed by less than tolerance multiplied by the value of the parameter, the optimization is stopped. If you do not want to use a particular tolerance termination, you can just set that tolerance to zero and it will be ignored.

Definition at line 189 of file NLoptSolver.cxx.

◆ SetUpperBound()

void Seldon::NLoptSolver::SetUpperBound ( const Vector< double > &  upper_bound)

Sets upper bounds on the parameters.

Parameters
[in]upper_boundthe lower bound vector.

Definition at line 173 of file NLoptSolver.cxx.


The documentation for this class was generated from the following files: