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 setParamtersLimits";
182 const char* szName =
"upper limits length";
185 if( lower.
size() != numParameters && lower.
size() != 0 ) {
186 const char* where =
" OptimizerSystem setParamtersLimits";
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;
367 void setConvergenceTolerance(
Real accuracy );
370 void setConstraintTolerance(
Real tolerance);
378 void setMaxIterations(
int iter );
381 void setLimitedMemoryHistory(
int history );
383 void setDiagnosticsLevel(
int level );
389 bool setAdvancedStrOption(
const char *option,
const char *value );
391 bool setAdvancedRealOption(
const char *option,
const Real value );
393 bool setAdvancedIntOption(
const char *option,
const int value );
395 bool setAdvancedBoolOption(
const char *option,
const bool value );
431 void useNumericalGradient(
bool flag,
445 void useNumericalJacobian(
bool flag,
455 bool isUsingNumericalGradient()
const;
457 bool isUsingNumericalJacobian()
const;
459 Real getEstimatedAccuracyOfObjective()
const;
461 Real getEstimatedAccuracyOfConstraints()
const;
470 const OptimizerRep& getRep()
const {assert(rep);
return *rep;}
481 #endif //SimTK_SIMMATH_OPTIMIZER_H_
LBFGS with simple bound constraints; gradient descent.
Definition: Optimizer.h:51
Definition: Exception.h:204
void setNumParameters(const int nParameters)
Sets the number of parameters in the objective function.
Definition: Optimizer.h:129
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
Limited-memory Broyden-Fletcher-Goldfarb-Shanno algorithm; gradient descent.
Definition: Optimizer.h:48
int getNumNonlinearInequalityConstraints() const
Returns the number of linear inequality constraints.
Definition: Optimizer.h:222
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 paramters.
Definition: Optimizer.h:179
void setNumEqualityConstraints(const int n)
Sets the number of equality constraints.
Definition: Optimizer.h:139
API for SimTK Simmath's optimizers.
Definition: Optimizer.h:355
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
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
int size() const
Definition: VectorBase.h:396
OptimizerSystem()
Definition: Optimizer.h:73
int getNumInequalityConstraints() const
Returns the number of inequality constraints.
Definition: Optimizer.h:214
OptimizerSystem(int nParameters)
Definition: Optimizer.h:83
Definition: SimTKmath/include/simmath/internal/common.h:118
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
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
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:577
int getNumLinearInequalityConstraints() const
Returns the number of linear inequality constraints.
Definition: Optimizer.h:220
Definition: Exception.h:174
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
Definition: Exception.h:189
void setNumInequalityConstraints(const int n)
Sets the number of inequality constraints.
Definition: Optimizer.h:149
Includes internal headers providing declarations for the basic SimTK Core classes, including Simmatrix.
int getNumParameters() const
Returns the number of parameters, that is, the number of variables that the Optimizer may adjust whil...
Definition: Optimizer.h:208
#define SimTK_THROW2(exc, a1, a2)
Definition: Exception.h:313
An algorithm that is implemented outside of Simmath.
Definition: Optimizer.h:63
#define SimTK_THROW5(exc, a1, a2, a3, a4, a5)
Definition: Exception.h:319
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
int getNumLinearEqualityConstraints() const
Returns the number of linear equality constraints.
Definition: Optimizer.h:216
#define SimTK_THROW3(exc, a1, a2, a3)
Definition: Exception.h:315
int getNumNonlinearEqualityConstraints() const
Returns the number of nonlinear equality constraints.
Definition: Optimizer.h:218
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
This is the header file that every Simmath compilation unit should include first. ...
int getNumConstraints() const
Returns the total number of constraints.
Definition: Optimizer.h:210
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...
Vector_< Real > Vector
Variable-size column vector of Real elements; abbreviation for Vector_.
Definition: BigMatrix.h:1473
Abstract class which defines an objective/cost function which is optimized by and Optimizer object...
Definition: Optimizer.h:71
IpOpt algorithm (https://projects.coin-or.org/ipopt); gradient descent.
Definition: Optimizer.h:45
Definition: Exception.h:247
void setNumLinearEqualityConstraints(const int n)
Sets the number of lineaer equality constraints.
Definition: Optimizer.h:159
bool getHasLimits() const
Returns true if there are limits on the parameters.
Definition: Optimizer.h:225
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:317
#define SimTK_SIMMATH_EXPORT
Definition: SimTKmath/include/simmath/internal/common.h:64
void setNumLinearInequalityConstraints(const int n)
Sets the number of lineaer inequality constraints.
Definition: Optimizer.h:169
int getNumEqualityConstraints() const
Returns the number of equality constraints.
Definition: Optimizer.h:212