1 #ifndef SimTK_SIMMATH_OPTIMIZER_H_ 2 #define SimTK_SIMMATH_OPTIMIZER_H_ 74 numEqualityConstraints(0),
75 numInequalityConstraints(0),
76 numLinearEqualityConstraints(0),
77 numLinearInequalityConstraints(0),
85 setNumParameters(nParameters);
99 bool new_parameters,
Real& f )
const {
106 bool new_parameters,
Vector &gradient )
const {
112 bool new_parameters,
Vector & constraints )
const {
118 bool new_parameters,
Matrix& jac )
const {
124 bool new_parameters,
Vector &gradient)
const {
130 if( nParameters < 1 ) {
131 const char* where =
" OptimizerSystem Constructor";
132 const char* szName =
"number of parameters";
135 numParameters = nParameters;
141 const char* where =
" OptimizerSystem setNumEqualityConstraints";
142 const char* szName =
"number of equality constraints";
145 numEqualityConstraints = n;
151 const char* where =
" OptimizerSystem setNumInequalityConstraints";
152 const char* szName =
"number of inequality constraints";
155 numInequalityConstraints = n;
160 if( n < 0 || n > numEqualityConstraints ) {
161 const char* where =
" OptimizerSystem setNumLinearEqualityConstraints";
162 const char* szName =
"number of linear equality constraints";
165 numLinearEqualityConstraints = n;
170 if( n < 0 || n > numInequalityConstraints ) {
171 const char* where =
" OptimizerSystem setNumLinearInequalityConstraints";
172 const char* szName =
"number of linear inequality constraints";
175 numLinearInequalityConstraints = n;
180 if( upper.
size() != numParameters && upper.
size() != 0) {
181 const char* where =
" OptimizerSystem setParametersLimits";
182 const char* szName =
"upper limits length";
185 if( lower.
size() != numParameters && lower.
size() != 0 ) {
186 const char* where =
" OptimizerSystem setParametersLimits";
187 const char* szName =
"lower limits length";
197 if( upper.
size() == 0 ) {
200 lowerLimits =
new Vector( lower );
201 upperLimits =
new Vector( upper );
230 *lower = &(*lowerLimits)[0];
231 *upper = &(*upperLimits)[0];
236 int numEqualityConstraints;
237 int numInequalityConstraints;
238 int numLinearEqualityConstraints;
239 int numLinearInequalityConstraints;
433 void setConvergenceTolerance(
Real accuracy );
436 void setConstraintTolerance(
Real tolerance);
444 void setMaxIterations(
int iter );
447 void setLimitedMemoryHistory(
int history );
449 void setDiagnosticsLevel(
int level );
455 bool setAdvancedStrOption(
const char *option,
const char *value );
457 bool setAdvancedRealOption(
const char *option,
const Real value );
459 bool setAdvancedIntOption(
const char *option,
const int value );
461 bool setAdvancedBoolOption(
const char *option,
const bool value );
463 bool setAdvancedVectorOption(
const char *option,
const Vector value );
499 void useNumericalGradient(
bool flag,
513 void useNumericalJacobian(
bool flag,
523 bool isUsingNumericalGradient()
const;
525 bool isUsingNumericalJacobian()
const;
527 Real getEstimatedAccuracyOfObjective()
const;
529 Real getEstimatedAccuracyOfConstraints()
const;
538 const OptimizerRep& getRep()
const {assert(rep);
return *rep;}
549 #endif //SimTK_SIMMATH_OPTIMIZER_H_ LBFGS with simple bound constraints; gradient descent.
Definition: Optimizer.h:51
Definition: Exception.h:205
void setNumParameters(const int nParameters)
Sets the number of parameters in the objective function.
Definition: Optimizer.h:129
Limited-memory Broyden-Fletcher-Goldfarb-Shanno algorithm; gradient descent.
Definition: Optimizer.h:48
Simmath will select best Optimizer based on problem type.
Definition: Optimizer.h:42
void setParameterLimits(const Vector &lower, const Vector &upper)
Set the upper and lower bounds on the parameters.
Definition: Optimizer.h:179
bool getHasLimits() const
Returns true if there are limits on the parameters.
Definition: Optimizer.h:225
void setNumEqualityConstraints(const int n)
Sets the number of equality constraints.
Definition: Optimizer.h:139
API for SimTK Simmath's optimizers.
Definition: Optimizer.h:421
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
int getNumLinearInequalityConstraints() const
Returns the number of linear inequality constraints.
Definition: Optimizer.h:220
OptimizerSystem()
Definition: Optimizer.h:73
int getNumEqualityConstraints() const
Returns the number of equality constraints.
Definition: Optimizer.h:212
OptimizerSystem(int nParameters)
Definition: Optimizer.h:83
Definition: SimTKmath/include/simmath/internal/common.h:122
Definition: OptimizerRep.h:63
SimTK_Real Real
This is the default compiled-in floating point type for SimTK, either float or double.
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:606
Definition: Exception.h:175
Definition: Exception.h:190
int getNumConstraints() const
Returns the total number of constraints.
Definition: Optimizer.h:210
void setNumInequalityConstraints(const int n)
Sets the number of inequality constraints.
Definition: Optimizer.h:149
int getNumNonlinearEqualityConstraints() const
Returns the number of nonlinear equality constraints.
Definition: Optimizer.h:218
Includes internal headers providing declarations for the basic SimTK Core classes, including Simmatrix.
#define SimTK_THROW2(exc, a1, a2)
Definition: Exception.h:318
An algorithm that is implemented outside of Simmath.
Definition: Optimizer.h:63
#define SimTK_THROW5(exc, a1, a2, a3, a4, a5)
Definition: Exception.h:324
virtual int hessian(const Vector ¶meters, bool new_parameters, Vector &gradient) const
Computes Hessian of the objective function; return 0 when successful.
Definition: Optimizer.h:123
C implementation of sequential quadratic programming (requires external library: ftp://frcatel.fri.uniza.sk/pub/soft/math/matprog/doc/fsqp.html); gradient descent.
Definition: Optimizer.h:56
Method
Definition: Differentiator.h:92
#define SimTK_THROW3(exc, a1, a2, a3)
Definition: Exception.h:320
virtual int objectiveFunc(const Vector ¶meters, bool new_parameters, Real &f) const
Objective/cost function which is to be optimized; return 0 when successful.
Definition: Optimizer.h:98
This is the header file that every Simmath compilation unit should include first. ...
void getParameterLimits(Real **lower, Real **upper) const
Returns the limits on the allowed values of each parameter, as an array of lower bounds and an array ...
Definition: Optimizer.h:229
This is the header file that user code should include to pick up the SimTK Simmath numerical differen...
const Real SignificantReal
SignificantReal is the smallest value that we consider to be clearly distinct from roundoff error whe...
virtual int constraintJacobian(const Vector ¶meters, bool new_parameters, Matrix &jac) const
Computes Jacobian of the constraints; return 0 when successful.
Definition: Optimizer.h:117
Vector_< Real > Vector
Variable-size column vector of Real elements; abbreviation for Vector_<Real>.
Definition: BigMatrix.h:1473
Abstract class which defines an objective/cost function which is optimized by and Optimizer object...
Definition: Optimizer.h:71
int size() const
Definition: VectorBase.h:396
int getNumParameters() const
Returns the number of parameters, that is, the number of variables that the Optimizer may adjust whil...
Definition: Optimizer.h:208
IpOpt algorithm (https://projects.coin-or.org/ipopt); gradient descent.
Definition: Optimizer.h:45
int getNumLinearEqualityConstraints() const
Returns the number of linear equality constraints.
Definition: Optimizer.h:216
int getNumNonlinearInequalityConstraints() const
Returns the number of linear inequality constraints.
Definition: Optimizer.h:222
Definition: Exception.h:248
virtual int constraintFunc(const Vector ¶meters, bool new_parameters, Vector &constraints) const
Computes the value of the constraints; return 0 when successful.
Definition: Optimizer.h:111
void setNumLinearEqualityConstraints(const int n)
Sets the number of lineaer equality constraints.
Definition: Optimizer.h:159
virtual ~OptimizerSystem()
Definition: Optimizer.h:88
Definition: Optimizer.h:61
OptimizerAlgorithm
The available Optimizer algorithms.
Definition: Optimizer.h:40
Covariance matrix adaptation, evolution strategy (https://github.com/cma-es/c-cmaes); this is a rando...
Definition: Optimizer.h:60
#define SimTK_THROW4(exc, a1, a2, a3, a4)
Definition: Exception.h:322
#define SimTK_SIMMATH_EXPORT
Definition: SimTKmath/include/simmath/internal/common.h:64
virtual int gradientFunc(const Vector ¶meters, bool new_parameters, Vector &gradient) const
Computes the gradient of the objective function; return 0 when successful.
Definition: Optimizer.h:105
int getNumInequalityConstraints() const
Returns the number of inequality constraints.
Definition: Optimizer.h:214
void setNumLinearInequalityConstraints(const int n)
Sets the number of lineaer inequality constraints.
Definition: Optimizer.h:169