Objective Definition
The objective is the objective function to be minimized. OPTIMake supports the following types of objective definitions:
- general_objective: General type, defined directly through expressions
- least_square_objective: Least square type
- external_general_objective: General type, defined through external C/C++ functions
After defining the objective, use the following interface to minimize it:
prob.objective(obj)
Similarly, use the following interface to add an objective for the last stage:
prob.end_objective(obj)
- prob.objective or prob.end_objective can only be called once to set the objective
general_objective
Below is an example of defining an objective directly through expressions:
# wyref, wphi are previously defined parameters
obj = general_objective(wxref * (x * sin(phi) - xref)**2 + wyref * (y - yref)**2 + wphi * phi**2 + 0.01 * delta**2 + 0.1 * v**2)
prob.objective(obj)
least_square_objective
When the objective has the following form, it can be defined through the least square interface, where is the residual term and is the corresponding weight term.
Below is an example of defining an objective through the least square interface:
r = [x * sin(phi) - xref, y - yref, phi, delta, v]
w = [wxref, wyref, wphi, 0.01, 0.1]
obj = least_square_objective(residuals=r, weights=w)
prob.objective(obj)
The function parameters of the least_square_objective interface are defined as follows:
- residuals: The residual terms, corresponding to , type is list
- weights (optional): The residual weights, corresponding to , can be a list of constants or expressions in terms of parameter , default value is a list of all 1.0
When the objective is defined through the least square interface, its Hessian is approximately computed using the Gauss-Newton method.
external_general_objective
A general_objective defined through external C/C++ functions. During modeling, the sparsity of its Hessian can be specified to accelerate computation.
Below is an example of defining an objective through the external_general_objective interface:
obj_spy_hess = \
[[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]]
obj = external_general_objective(sparsity_hessian=obj_spy_hess)
prob.objective(obj)
The parameters of the external_general_objective interface are as follows:
- sparsity_hessian (optional): The sparsity pattern of the objective's Hessian, a symmetric matrix of dimension , where 0 represents sparse and 1 represents dense; this is an optional parameter with a default value of all 1.0