Geogram  Version 1.8.9-rc
A programming library of geometric algorithms
GEO::Optimizer Class Referenceabstract

Optimizer minimizes a multivariate function. More...

#include <geogram/numerics/optimizer.h>

Inheritance diagram for GEO::Optimizer:
GEO::Counted

Public Types

typedef void(* funcgrad_callback) (index_t N, double *x, double &f, double *g)
 Optimizer callback that evaluates a function and its gradient. More...
 
typedef void(* newiteration_callback) (index_t N, const double *x, double f, const double *g, double gnorm)
 Optimizer callback that is called at each iteration. More...
 
typedef void(* evalhessian_callback) (index_t N, double *x, double &f, double *g, HESSIAN_MATRIX &hessian)
 Optimizer callback that evaluates a function, its gradient and its Hessian. More...
 

Public Member Functions

virtual void optimize (double *x)=0
 Minimizes a function, starting from initial value x. More...
 
void set_N (index_t N)
 Defines the number of variables.
 
index_t get_N () const
 Returns the number of variables.
 
void set_M (index_t M)
 Defines the inner number of iterations. More...
 
index_t get_M () const
 Returns the inner number of iterations.
 
void set_max_iter (index_t maxiter)
 Defines the maximum number of iterations.
 
index_t get_max_iter () const
 Returns the maximum number of iterations.
 
void set_funcgrad_callback (funcgrad_callback fp)
 Defines the callback that evaluates the function to be minimized and its gradient.
 
void set_newiteration_callback (newiteration_callback fp)
 Defines a callback that will be called at each iteration.
 
void set_evalhessian_callback (evalhessian_callback fp)
 Defines the callback that evaluates the Hessian of function to be minimized (second order derivatives). More...
 
void set_epsg (double eg)
 Defines the stopping criterion in terms of gradient magnitude.
 
void set_epsf (double ef)
 Defines the stopping criterion in terms of function value.
 
void set_epsx (double ex)
 Defines the stopping criterion in terms of variation of x.
 
void set_verbose (bool verb)
 Enables or disables verbose logs.
 
- Public Member Functions inherited from GEO::Counted
void ref () const
 Increments the reference count. More...
 
void unref () const
 Decrements the reference count. More...
 
bool is_shared () const
 Check if the object is shared. More...
 
int nb_refs () const
 Gets the number of references that point to this object. More...
 

Static Public Member Functions

static Optimizercreate (const std::string &name="default")
 Creates an Optimizer. More...
 
- Static Public Member Functions inherited from GEO::Counted
static void ref (const Counted *counted)
 Increments the reference count. More...
 
static void unref (const Counted *counted)
 Decrements the reference count. More...
 

Protected Member Functions

 Optimizer ()
 Optimizer constructor. More...
 
 ~Optimizer () override
 Optimizer destructor.
 
- Protected Member Functions inherited from GEO::Counted
 Counted ()
 Creates a reference counted object. More...
 
virtual ~Counted ()
 Destroys a reference counted object. More...
 

Protected Attributes

index_t n_
 
index_t m_
 
index_t max_iter_
 
funcgrad_callback funcgrad_callback_
 
newiteration_callback newiteration_callback_
 
evalhessian_callback evalhessian_callback_
 
double epsg_
 
double epsf_
 
double epsx_
 
bool verbose_
 

Related Functions

(Note that these are not member functions.)

typedef SmartPointer< OptimizerOptimizer_var
 Smart pointer that contains an Optimizer object.
 
typedef Factory0< OptimizerOptimizerFactory
 Optimizer Factory. More...
 

Detailed Description

Optimizer minimizes a multivariate function.

The dimension of the problem is defined by set_N(). The multivariate function to be minimized is defined by a callback that evaluates the function and its gradient, specified by set_funcgrad_callback(). Optimizer implements the numeric part of CentroidalVoronoiTesselation.

Optimizer objects are created using method create() which uses the Factory service. New Optimizers can be implemented and registered to the factory using geo_register_Optimizer_creator().

See also
OptimizerFactory
geo_register_Optimizer_creator

Definition at line 77 of file optimizer.h.

Member Typedef Documentation

◆ evalhessian_callback

typedef void(* GEO::Optimizer::evalhessian_callback) (index_t N, double *x, double &f, double *g, HESSIAN_MATRIX &hessian)

Optimizer callback that evaluates a function, its gradient and its Hessian.

See also
set_evalhessian_callback()

Definition at line 101 of file optimizer.h.

◆ funcgrad_callback

typedef void(* GEO::Optimizer::funcgrad_callback) (index_t N, double *x, double &f, double *g)

Optimizer callback that evaluates a function and its gradient.

See also
set_funcgrad_callback()

Definition at line 84 of file optimizer.h.

◆ newiteration_callback

typedef void(* GEO::Optimizer::newiteration_callback) (index_t N, const double *x, double f, const double *g, double gnorm)

Optimizer callback that is called at each iteration.

See also
set_newiteration_callback()

Definition at line 92 of file optimizer.h.

Constructor & Destructor Documentation

◆ Optimizer()

GEO::Optimizer::Optimizer ( )
protected

Optimizer constructor.

Should never be called directly, use create() instead.

Member Function Documentation

◆ create()

static Optimizer* GEO::Optimizer::create ( const std::string &  name = "default")
static

Creates an Optimizer.

Parameters
[in]namename of the Optimizer to create:
  • "HLBFG" - BFGS (quasi-Newton)
  • "HM1QN3" - for non-smooth functions
  • "HCG" - non-linear conjugate gradient
  • "HLBFGS_HESS" - BFGS with Hessian (full Newton)
  • "default" - equivalent to "HLBFGS"
Return values
nullptrif name is not a valid Optimizer algorithm name
otherwise,apointer to an Optimizer object. The returned pointer must be stored in a Optimizer_var that does automatic destruction:
Optimizer_var optimizer = Optimizer::create("HLBFGS") ;
static Optimizer * create(const std::string &name="default")
Creates an Optimizer.
SmartPointer< Optimizer > Optimizer_var
Smart pointer that contains an Optimizer object.
Definition: optimizer.h:267

◆ optimize()

virtual void GEO::Optimizer::optimize ( double *  x)
pure virtual

Minimizes a function, starting from initial value x.

Parameters
[in]xis of size n, where n was defined with set_N()

◆ set_evalhessian_callback()

void GEO::Optimizer::set_evalhessian_callback ( evalhessian_callback  fp)
inline

Defines the callback that evaluates the Hessian of function to be minimized (second order derivatives).

Only used in "HLBFGS_HESS" mode.

Definition at line 195 of file optimizer.h.

◆ set_M()

void GEO::Optimizer::set_M ( index_t  M)
inline

Defines the inner number of iterations.

Used by HLBFGSOptimizer.

Definition at line 147 of file optimizer.h.

Friends And Related Function Documentation

◆ OptimizerFactory

Optimizer Factory.

This Factory is used to create Optimizer objects. It can also be used to register new Optimizer implementations.

See also
geo_register_Optimizer_creator
Factory

Definition at line 277 of file optimizer.h.

Member Data Documentation

◆ epsg_

double GEO::Optimizer::epsg_
protected

Error tolerance on x, f and g

Definition at line 258 of file optimizer.h.

◆ m_

index_t GEO::Optimizer::m_
protected

Number of corrections in the BFGS scheme of Hessian approximation update

Definition at line 249 of file optimizer.h.

◆ max_iter_

index_t GEO::Optimizer::max_iter_
protected

Max iterations

Definition at line 251 of file optimizer.h.

◆ n_

index_t GEO::Optimizer::n_
protected

Size of the problem

Definition at line 244 of file optimizer.h.


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