Simbody  3.5
SimTK::Optimizer Class Reference

API for SimTK Simmath's optimizers. More...

Classes

class  OptimizerRep
 

Public Member Functions

 Optimizer ()
 
 Optimizer (const OptimizerSystem &sys)
 
 Optimizer (const OptimizerSystem &sys, OptimizerAlgorithm algorithm)
 
 ~Optimizer ()
 
void setConvergenceTolerance (Real accuracy)
 Sets the relative accuracy used determine if the problem has converged. More...
 
void setConstraintTolerance (Real tolerance)
 Sets the absolute tolerance used to determine whether constraint violation is acceptable. More...
 
void setMaxIterations (int iter)
 Set the maximum number of iterations allowed of the optimization method's outer stepping loop. More...
 
void setLimitedMemoryHistory (int history)
 Set the maximum number of previous hessians used in a limited memory hessian approximation. More...
 
void setDiagnosticsLevel (int level)
 Set the level of debugging info displayed. More...
 
void setOptimizerSystem (const OptimizerSystem &sys)
 
void setOptimizerSystem (const OptimizerSystem &sys, OptimizerAlgorithm algorithm)
 
bool setAdvancedStrOption (const char *option, const char *value)
 Set the value of an advanced option specified by a string. More...
 
bool setAdvancedRealOption (const char *option, const Real value)
 Set the value of an advanced option specified by a real value. More...
 
bool setAdvancedIntOption (const char *option, const int value)
 Set the value of an advanced option specified by an integer value. More...
 
bool setAdvancedBoolOption (const char *option, const bool value)
 Set the value of an advanced option specified by an boolean value. More...
 
void setDifferentiatorMethod (Differentiator::Method method)
 Set which numerical differentiation algorithm is to be used for the next useNumericalGradient() or useNumericalJacobian() call. More...
 
Differentiator::Method getDifferentiatorMethod () const
 Return the differentiation method last supplied in a call to setDifferentiatorMethod(), not necessarily the method currently in use. More...
 
OptimizerAlgorithm getAlgorithm () const
 Return the algorithm used for the optimization. More...
 
void useNumericalGradient (bool flag, Real estimatedAccuracyOfObjective=SignificantReal)
 Enable numerical calculation of gradient, with optional estimation of the accuracy to which the objective function is calculated. More...
 
void useNumericalJacobian (bool flag, Real estimatedAccuracyOfConstraints=SignificantReal)
 Enable numerical calculation of the constraint Jacobian, with optional estimation of the accuracy to which the constraint functions are calculated. More...
 
Real optimize (Vector &)
 Compute optimization. More...
 
const OptimizerSystemgetOptimizerSystem () const
 Return a reference to the OptimizerSystem currently associated with this Optimizer. More...
 
bool isUsingNumericalGradient () const
 Indicate whether the Optimizer is currently set to use a numerical gradient. More...
 
bool isUsingNumericalJacobian () const
 Indicate whether the Optimizer is currently set to use a numerical Jacobian. More...
 
Real getEstimatedAccuracyOfObjective () const
 Return the estimated accuracy last specified in useNumericalGradient(). More...
 
Real getEstimatedAccuracyOfConstraints () const
 Return the estimated accuracy last specified in useNumericalJacobian(). More...
 

Static Public Member Functions

static bool isAlgorithmAvailable (OptimizerAlgorithm algorithm)
 BestAvailable, UnknownAlgorithm, and UserSuppliedAlgorithm are treated as never available. More...
 

Friends

class OptimizerRep
 

Detailed Description

API for SimTK Simmath's optimizers.

An optimizer finds a minimum to an objective function. Usually, this minimum is a local minimum. Some algorithms, like CMAES, are designed to find the global minumum. The optimizer can be constrained to search for a minimum within a feasible region. The feasible region is defined in two ways: via limits on the parameters of the objective function; and, for algorithms other than CMAES, by supplying constraint functions that must be satisfied. The optimizer starts searching for a minimum beginning at a user supplied initial value for the set of parameters.

The objective function and constraints are specified by supplying the Optimizer with a concrete implemenation of an OptimizerSystem class. The OptimizerSystem can be passed to the Optimizer either through the Optimizer constructor or by calling the Optimizer::setOptimizerSystem method. The Optimizer class will select the best optimization algorithm to solve the problem based on the constraints supplied by the OptimizerSystem. A user can also override the optimization algorithm selected by the Optimizer by specifying the optimization algorithm.

Optimization algorithms and advanced options

See OptimizerAlgorithm for a brief description of the available algorithms. Most of these algorithms have options that are specific to the algorithm. These options are set via methods like Optimizer::setAdvancedStrOption. If you want to get going quickly, you can just use the default values of these options and ignore this section. As an example, an int option popsize would be set via:

opt.setAdvancedIntOption("popsize", 5);

For now, we only have detailed documentation for the CMAES algorithm.

CMAES

This is the c-cmaes algorithm written by Niko Hansen (https://github.com/cma-es/c-cmaes).

Some notes:

Advanced options:

The default values for options whose name begins with "stop" are specified at https://github.com/CMA-ES/c-cmaes/blob/master/cmaes_initials.par

  • popsize (int; default: depends on number of parameters) The population size (also known as lambda).
  • init_stepsize (real; default: 0.3) Initial step size; same for all parameters (also known as sigma). A warning is emitted if this is not set.
  • seed (int; default: 0, which uses clock time) Seed for the random number generator that is used to sample the population from a normal distribution. See note below.
  • maxTimeFractionForEigendecomposition (real; default: 0.2) Controls the amount of time spent generating eigensystem decompositions.
  • stopMaxFunEvals (int) Stop optimization after this number of evaluations of the objective function.
  • stopFitness (real) Stop if function value is smaller than stopFitness.
  • stopTolFunHist (real) Stop if function value differences of best values are smaller than stopTolFunHist.
  • stopTolX (real) Stop if step sizes are smaller than stopTolX.
  • stopTolUpXFactor (real) Stop if standard deviation increases by more than stopTolUpXFactor.
  • parallel (str) To run the optimization with multiple threads, set this to "multithreading". Only use this if your OptimizerSystem is threadsafe: you can't reliably modify any mutable variables in your OptimizerSystem::objectiveFun().
  • nthreads (int) If the parallel option is set to "multithreading", this is the number of threads to use (by default, this is the number of processors/threads on the machine).

If you want to generate identical results with repeated optimizations for, you can set the seed option. In addtion, you *must* set the maxTimeFractionForEigendecomposition option to be greater or equal to 1.0.

opt.setAdvancedIntOption("seed", 42);
opt.setAdvancedRealOption("maxTimeFractionForEigendecomposition", 1);

Constructor & Destructor Documentation

SimTK::Optimizer::Optimizer ( )
SimTK::Optimizer::Optimizer ( const OptimizerSystem sys)
SimTK::Optimizer::Optimizer ( const OptimizerSystem sys,
OptimizerAlgorithm  algorithm 
)
SimTK::Optimizer::~Optimizer ( )

Member Function Documentation

static bool SimTK::Optimizer::isAlgorithmAvailable ( OptimizerAlgorithm  algorithm)
static

BestAvailable, UnknownAlgorithm, and UserSuppliedAlgorithm are treated as never available.

void SimTK::Optimizer::setConvergenceTolerance ( Real  accuracy)

Sets the relative accuracy used determine if the problem has converged.

void SimTK::Optimizer::setConstraintTolerance ( Real  tolerance)

Sets the absolute tolerance used to determine whether constraint violation is acceptable.

void SimTK::Optimizer::setMaxIterations ( int  iter)

Set the maximum number of iterations allowed of the optimization method's outer stepping loop.

Most optimizers also have an inner loop ("line search") which is also iterative but is not affected by this setting. Inner loop convergence is typically prescribed by theory, and failure there is often an indication of an ill-formed problem.

void SimTK::Optimizer::setLimitedMemoryHistory ( int  history)

Set the maximum number of previous hessians used in a limited memory hessian approximation.

void SimTK::Optimizer::setDiagnosticsLevel ( int  level)

Set the level of debugging info displayed.

void SimTK::Optimizer::setOptimizerSystem ( const OptimizerSystem sys)
void SimTK::Optimizer::setOptimizerSystem ( const OptimizerSystem sys,
OptimizerAlgorithm  algorithm 
)
bool SimTK::Optimizer::setAdvancedStrOption ( const char *  option,
const char *  value 
)

Set the value of an advanced option specified by a string.

bool SimTK::Optimizer::setAdvancedRealOption ( const char *  option,
const Real  value 
)

Set the value of an advanced option specified by a real value.

bool SimTK::Optimizer::setAdvancedIntOption ( const char *  option,
const int  value 
)

Set the value of an advanced option specified by an integer value.

bool SimTK::Optimizer::setAdvancedBoolOption ( const char *  option,
const bool  value 
)

Set the value of an advanced option specified by an boolean value.

void SimTK::Optimizer::setDifferentiatorMethod ( Differentiator::Method  method)

Set which numerical differentiation algorithm is to be used for the next useNumericalGradient() or useNumericalJacobian() call.

Choices are Differentiator::ForwardDifference (first order) or Differentiator::CentralDifference (second order) with central the default.

Warning
This has no effect if you have already called useNumericalGradient() or useNumericalJacobian(). Those must be called after setDifferentiatorMethod().
See also
SimTK::Differentiator
Differentiator::Method SimTK::Optimizer::getDifferentiatorMethod ( ) const

Return the differentiation method last supplied in a call to setDifferentiatorMethod(), not necessarily the method currently in use.

See setDifferentiatorMethod() for more information.

See also
SimTK::Differentiator
OptimizerAlgorithm SimTK::Optimizer::getAlgorithm ( ) const

Return the algorithm used for the optimization.

You may be interested in this value if you didn't specify an algorithm, or specified for Simbody to choose the BestAvailable algorithm. This method won't return BestAvailable, even if it's the 'algorithm' that you chose.

void SimTK::Optimizer::useNumericalGradient ( bool  flag,
Real  estimatedAccuracyOfObjective = SignificantReal 
)

Enable numerical calculation of gradient, with optional estimation of the accuracy to which the objective function is calculated.

For example, if you are calculate about 6 significant digits, supply the estimated accuracy as 1e-6. Providing the estimated accuracy improves the quality of the calculated derivative. If no accuracy is provided we'll assume the objective is calculated to near machine precision. The method used for calculating the derivative will be whatever was previously supplied in a call to setDifferentiatorMethod(), or the default which is to use central differencing (two function evaluations per gradient entry). See SimTK::Differentiator for more information.

See also
setDifferentiatorMethod(), SimTK::Differentiator
void SimTK::Optimizer::useNumericalJacobian ( bool  flag,
Real  estimatedAccuracyOfConstraints = SignificantReal 
)

Enable numerical calculation of the constraint Jacobian, with optional estimation of the accuracy to which the constraint functions are calculated.

For example, if you are calculating about 6 significant digits, supply the estimated accuracy as 1e-6. Providing the estimated accuracy improves the quality of the calculated derivative. If no accuracy is provided we'll assume the constraints are calculated to near machine precision. The method used for calculating the derivative will be whatever was previously supplied in a call to setDifferentiatorMethod(), or the default which is to use central differencing (two function evaluations per Jacobian column. See SimTK::Differentiator for more information.

See also
setDifferentiatorMethod(), SimTK::Differentiator
Real SimTK::Optimizer::optimize ( Vector )

Compute optimization.

const OptimizerSystem& SimTK::Optimizer::getOptimizerSystem ( ) const

Return a reference to the OptimizerSystem currently associated with this Optimizer.

bool SimTK::Optimizer::isUsingNumericalGradient ( ) const

Indicate whether the Optimizer is currently set to use a numerical gradient.

bool SimTK::Optimizer::isUsingNumericalJacobian ( ) const

Indicate whether the Optimizer is currently set to use a numerical Jacobian.

Real SimTK::Optimizer::getEstimatedAccuracyOfObjective ( ) const

Return the estimated accuracy last specified in useNumericalGradient().

Real SimTK::Optimizer::getEstimatedAccuracyOfConstraints ( ) const

Return the estimated accuracy last specified in useNumericalJacobian().

Friends And Related Function Documentation

friend class OptimizerRep
friend

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