Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
drwnOptimizer Class Referenceabstract

Interface for solving large-scale unconstrained optimization problems using L-BFGS. More...

Inheritance diagram for drwnOptimizer:
drwnLinearRegressorBase drwnMultiClassLogisticBase drwnTLinearRegressor< FeatureMap > drwnTMultiClassLogistic< FeatureMap > drwnTMultiClassLogistic< drwnBiasJointFeatureMap >

Public Member Functions

 drwnOptimizer ()
 default constructor
 drwnOptimizer (unsigned n)
 construct a problem with dimension n
 drwnOptimizer (const drwnOptimizer &o)
 copy constructor
void initialize (unsigned n, const double *x=NULL)
 initialize an optimization problem of size n possibly with feasible starting point x $\mathbb{R}^n$ (or zero)
void initialize (const double *x=NULL)
 initialize an optimization problem at feasible starting point x in $\mathbb{R}^n$ (or zero)
double solve (unsigned maxiter, bool bMonitor=false)
 Solve the optimization problem for up to maxiter iterations to precision set by EPSF, EPSG, and EPSX static variables. Calls monitor function after each iteration if bMonitor is true.
virtual double objective (const double *x) const =0
 returns value of objective function at point x
virtual void gradient (const double *x, double *df) const =0
 populates gradient of objective function at point x
virtual double objectiveAndGradient (const double *x, double *df) const
 returns value of objective function and populates gradient df at point x
unsigned size () const
 dimension of optimization problem
double operator[] (unsigned i) const
 returns the i-th component of the current solution
double & operator[] (unsigned i)
 returns a reference to the i-th component of the current solution
virtual void monitor (unsigned iter, double objValue)
 callback for each iteration during optimization (if bMonitor is true)

Public Attributes

unsigned _n
 dimension of optimization problem (i.e., $\mathbb{R}^n$)
double * _x
 current feasible solution in $\mathbb{R}^n$
double * _df
 gradient at _x in $\mathbb{R}^n$

Static Public Attributes

static double EPSF = 1.0e-6
 default tolerance on function convergence
static double EPSG = 1.0e-3
 deafult tolerance on gradient convergence
static double EPSX = 1.0e-6
 default tolerance on solution convergence

Detailed Description

Interface for solving large-scale unconstrained optimization problems using L-BFGS.

Implements optimization using L-BFGS code is based on an implementation by Jorge Nocedal:

The derived class must override functions objective and gradient. It should also implement the objectiveAndGradient function for efficiency, and may override the monitor function. The monitor function can assume that _x contains the current estimate for the solution. Other functions should use the input argument.

This class tries to minimize the objective function define by objective.

The following simple example optimizes the one-dimensional function $f(x) = (x - 2)(x - 4)$.

class MyObjective : public drwnOptimizer
MyObjective() : drwnOptimizer(1) { }
~MyObjective() { }
double objective(const double *x) const {
return (x[0] - 2.0) * (x[0] - 4.0);
void gradient(const double *x, double *df) const {
df[0] = 2.0 * (x[0] - 3.0);
int main()
MyObjective objFunction;
double f_star = objFunction.solve(1000);
double x_star = objFunction[0];
cout << "f(" << x_star << ") = " << f_star << endl;
return 0;

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