atomicrex  0.1
An advanced atomistic model building tool
Public Member Functions | List of all members
atomicrex::NloptMinimizer Class Reference
Inheritance diagram for atomicrex::NloptMinimizer:
atomicrex::Minimizer

Public Member Functions

 NloptMinimizer (FitJob *job)
 Constructor.
 
virtual void prepare (std::vector< double > &&x0, const std::function< double(const std::vector< double > &)> &func, const std::function< double(const std::vector< double > &, std::vector< double > &)> &gradient=std::function< double(const std::vector< double > &, std::vector< double > &)>()) override
 
virtual void setConstraints (std::vector< BoundConstraints > &&constraintTypes, std::vector< double > &&lowerBounds, std::vector< double > &&upperBounds) override
 
virtual MinimizerResult iterate () override
 Performs one minimization iteration.
 
virtual void parse (XML::Element minimizerElement) override
 Parses the minimizer's parameters from the XML file.
 
double objective_function (const std::vector< double > &, std::vector< double > &)
 The Objective function that gets passed to Nlopt.
 
nlopt::algorithm get_algorithm (FPString)
 Get the Nlopt algorithm from a string.
 
const nlopt::opt * get_optimizer ()
 Returns the optimizer object.
 
- Public Member Functions inherited from atomicrex::Minimizer
 Minimizer (FitJob *job)
 Constructor.
 
FitJobjob () const
 Returns the job to which this object belongs.
 
virtual void setConstraints (std::vector< BoundConstraints > &&constraintTypes, std::vector< double > &&lowerBounds, std::vector< double > &&upperBounds)
 Sets constraints for variations of the parameters. More...
 
int itercount () const
 Returns the number of iterations performed so far.
 
double value () const
 Returns the value of the objective function at the current x.
 
double gradientNorm2 () const
 Returns the 2-norm of the gradient of the objective function at the current x.
 
double convergenceThreshold () const
 Returns the limit for which the minimizer converges.
 
int maximumNumberOfIterations () const
 Returns the maximum number of iterations for the minimizer.
 
void setMaximumNumberOfIterations (int num)
 Set the maximum number of iterations for the minimizer.
 

Additional Inherited Members

- Public Types inherited from atomicrex::Minimizer
enum  MinimizerResult { MINIMIZATION_CONTINUE, MINIMIZATION_CONVERGED, MINIMIZATION_ABNORMAL, MINIMIZATION_ERROR }
 
enum  BoundConstraints { NO_BOUNDS = 0, LOWER_BOUNDS = 1, BOTH_BOUNDS = 2, UPPER_BOUNDS = 3 }
 
- Static Public Member Functions inherited from atomicrex::Minimizer
static std::shared_ptr< MinimizercreateAndParse (XML::Element minimizerElement, FitJob *job)
 Factory function that creates an instance of the minimizer type that is defined in the XML file.
 
- Protected Member Functions inherited from atomicrex::Minimizer
double numericGradient (const std::vector< double > &x, std::vector< double > &g)
 Computes the gradient of the objective function using finite differences.
 
- Protected Attributes inherited from atomicrex::Minimizer
FitJob_job
 Pointer to the job this object belongs to.
 
std::function< double(const std::vector< double > &)> _func
 Calculates the value of the objective function to be minimized.
 
std::function< double(const std::vector< double > &, std::vector< double > &)> _gradientFunc
 Calculates the gradient of the objective function.
 
double f = 0.0
 The value of the objective function;.
 
double _gradNorm2 = 0.0
 The 2-norm of the gradient.
 
int _itercount = 0
 Number of iterations performed so far.
 
double _convergenceThreshold = 1e-5
 The limit for which the minimizer converges.
 
int _maximumNumberOfIterations = 100
 Maximum number of iterations for the minimizer.
 
double _gradientEpsilon = 1e-6
 

Member Function Documentation

◆ prepare()

void atomicrex::NloptMinimizer::prepare ( std::vector< double > &&  x0,
const std::function< double(const std::vector< double > &)> &  func,
const std::function< double(const std::vector< double > &, std::vector< double > &)> &  gradient = std::function<double(const std::vector<double>&, std::vector<double>&)>() 
)
overridevirtual

Initializes the minimizer by setting the objective function and the starting vector. Must be called once before entering the minimization loop.

Parameters
x0An R-value reference to the starting vector. The length of this vector determines the number of dimensions. The function transfers the vector to internal storage. That means the passed-in vector will no longer be valid after the function returns.
funcThe object that computes the value of the objective function at a given point x.
gradientAn optional function object that computes the (analytic) gradient of the objective function at a given point x (and also the value of the objective function). If no gradient function is provided, and the minimization algorithm requires the gradient, the minimizer will compute it using finite differences by evaluating func several times.

Reimplemented from atomicrex::Minimizer.

◆ setConstraints()

void atomicrex::NloptMinimizer::setConstraints ( std::vector< BoundConstraints > &&  constraintTypes,
std::vector< double > &&  lowerBounds,
std::vector< double > &&  upperBounds 
)
overridevirtual

Sets the constraints for variations of the parameters. Must be called after prepare() and before the minimization loop is entered.


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