Base class for concrete Objective Functions ObjectiveFunction contains a pointer to a QualityMetric. If the ObjectiveFunction is associated with more than one QualityMetric (i.e., the Objective is a composite, and the composed ObjectiveFunctions are associated with different QualityMetrics), then the QualityMetric pointer is set to NULL.. More...
#include <ObjectiveFunction.hpp>
Public Types | |
enum | GRADIENT_TYPE { NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT, NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT } |
enum | GRADIENT_TYPE { NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT, NUMERICAL_GRADIENT, ANALYTICAL_GRADIENT } |
Public Member Functions | |
ObjectiveFunction () | |
virtual | ~ObjectiveFunction () |
virtual bool | concrete_evaluate (PatchData &patch, double &fval, MsqError &err)=0 |
bool | evaluate (PatchData &patch, double &fval, MsqError &err) |
void | set_gradient_type (GRADIENT_TYPE grad) |
Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT. More... | |
bool | compute_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size=0) |
Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of gradType. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More... | |
bool | compute_hessian (PatchData &patch, MsqHessian &hessian, Vector3D *const &grad, double &OF_val, MsqError &err) |
Calls compute_analytical_hessian. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More... | |
QualityMetric * | get_quality_metric () |
virtual msq_std::list < QualityMetric * > | get_quality_metric_list () |
void | set_quality_metric (QualityMetric *qm) |
Set the value of qMetric. More... | |
void | set_negate_flag (int neg) |
Set the value of ObjectiveFunction's negateFlag. Unless composite, concrete ObjectiveFunctions should set this flag to to the value of the associated QualityMetric's negateFLag. More... | |
int | get_negate_flag () |
Returns negateFlag. More... | |
ObjectiveFunction () | |
virtual | ~ObjectiveFunction () |
virtual bool | concrete_evaluate (PatchData &patch, double &fval, MsqError &err)=0 |
bool | evaluate (PatchData &patch, double &fval, MsqError &err) |
void | set_gradient_type (GRADIENT_TYPE grad) |
Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT. More... | |
bool | compute_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size=0) |
Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of gradType. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More... | |
bool | compute_hessian (PatchData &patch, MsqHessian &hessian, Vector3D *const &grad, double &OF_val, MsqError &err) |
Calls compute_analytical_hessian. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More... | |
QualityMetric * | get_quality_metric () |
virtual msq_std::list < QualityMetric * > | get_quality_metric_list () |
void | set_quality_metric (QualityMetric *qm) |
Set the value of qMetric. More... | |
void | set_negate_flag (int neg) |
Set the value of ObjectiveFunction's negateFlag. Unless composite, concrete ObjectiveFunctions should set this flag to to the value of the associated QualityMetric's negateFLag. More... | |
int | get_negate_flag () |
Returns negateFlag. More... | |
Protected Member Functions | |
bool | compute_numerical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size) |
Non-virtual function which numerically computes the gradient of the Objective Function. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More... | |
virtual bool | compute_analytical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size) |
virtual bool | compute_analytical_hessian (PatchData &, MsqHessian &, Vector3D *const &, double &, MsqError &) |
double | get_eps (PatchData &pd, double &local_val, int k, MsqVertex *vertex, MsqError &err) |
Returns eps used in the numerical gradient calculation. More... | |
void | set_use_local_gradient (bool new_bool) |
Sets useLocalGradient This variable determines whether compute_numercial_gradient can use the most efficient gradient calculation. More... | |
bool | compute_numerical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size) |
Non-virtual function which numerically computes the gradient of the Objective Function. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'. More... | |
virtual bool | compute_analytical_gradient (PatchData &patch, Vector3D *const &grad, double &OF_val, MsqError &err, size_t array_size) |
virtual bool | compute_analytical_hessian (PatchData &, MsqHessian &, Vector3D *const &, double &, MsqError &) |
double | get_eps (PatchData &pd, double &local_val, int k, MsqVertex *vertex, MsqError &err) |
Returns eps used in the numerical gradient calculation. More... | |
void | set_use_local_gradient (bool new_bool) |
Sets useLocalGradient This variable determines whether compute_numercial_gradient can use the most efficient gradient calculation. More... | |
Private Attributes | |
enum GRADIENT_TYPE | gradType |
QualityMetric * | qMetric |
Flag for numerical or analytical gradient. More... | |
int | negateFlag |
Pointer to associated QualityMetric. More... | |
bool | useLocalGradient |
Base class for concrete Objective Functions ObjectiveFunction contains a pointer to a QualityMetric. If the ObjectiveFunction is associated with more than one QualityMetric (i.e., the Objective is a composite, and the composed ObjectiveFunctions are associated with different QualityMetrics), then the QualityMetric pointer is set to NULL..
Definition at line 67 of file includeLinks/ObjectiveFunction.hpp.
enum GRADIENT_TYPE |
Definition at line 102 of file includeLinks/ObjectiveFunction.hpp.
enum GRADIENT_TYPE |
Definition at line 102 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
|
inline |
Definition at line 70 of file includeLinks/ObjectiveFunction.hpp.
|
inlinevirtual |
Definition at line 76 of file includeLinks/ObjectiveFunction.hpp.
|
inline |
Definition at line 70 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
|
inlinevirtual |
Definition at line 76 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
|
protectedvirtual |
Fills an array of Vector3D, grad, with the gradient of the objective function computed using the gradient of the quality metric. If the function has not been over-riden in the concrete Objective Function, the base class implementation prints a warning and then defaults to numerical gradient. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.
patch | The PatchData object for which the objective function gradient is computed. |
grad | An array of Vector3D, at least the size of the number of vertices in the patch. |
OF_val | is set to the value of the objective function. |
array_size | is the size of the grad Vector3D[] array and must correspond to the number of vertices in the patch. |
Reimplemented in LPtoPTemplate, LPtoPTemplate, MaxTemplate, MaxTemplate, CompositeOFScalarMultiply, LInfTemplate, CompositeOFScalarMultiply, LInfTemplate, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFMultiply, and CompositeOFMultiply.
Definition at line 152 of file ObjectiveFunction/ObjectiveFunction.cpp.
References ObjectiveFunction::compute_numerical_gradient(), MSQ_CHKERR, ObjectiveFunction::NUMERICAL_GRADIENT, and ObjectiveFunction::set_gradient_type().
Referenced by ObjectiveFunction::compute_gradient().
|
protectedvirtual |
Fills an array of Vector3D, grad, with the gradient of the objective function computed using the gradient of the quality metric. If the function has not been over-riden in the concrete Objective Function, the base class implementation prints a warning and then defaults to numerical gradient. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.
patch | The PatchData object for which the objective function gradient is computed. |
grad | An array of Vector3D, at least the size of the number of vertices in the patch. |
OF_val | is set to the value of the objective function. |
array_size | is the size of the grad Vector3D[] array and must correspond to the number of vertices in the patch. |
Reimplemented in LPtoPTemplate, LPtoPTemplate, MaxTemplate, MaxTemplate, CompositeOFScalarMultiply, LInfTemplate, CompositeOFScalarMultiply, LInfTemplate, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFMultiply, and CompositeOFMultiply.
|
protectedvirtual |
Fills a MsqHessian object with the Hessian of the objective function computed using the hessian of the quality metric. If the function has not been over-riden in the concrete Objective Function, the base class implementation prints a warning and returns false. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.
Reimplemented in LPtoPTemplate, and LPtoPTemplate.
Definition at line 161 of file ObjectiveFunction/ObjectiveFunction.cpp.
References MsqError::INVALID_STATE, and MSQ_SETERR.
Referenced by ObjectiveFunction::compute_hessian().
|
protectedvirtual |
Fills a MsqHessian object with the Hessian of the objective function computed using the hessian of the quality metric. If the function has not been over-riden in the concrete Objective Function, the base class implementation prints a warning and returns false. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.
Reimplemented in LPtoPTemplate, and LPtoPTemplate.
bool compute_gradient | ( | PatchData & | patch, |
Vector3D *const & | grad, | ||
double & | OF_val, | ||
MsqError & | err, | ||
size_t | array_size = 0 |
||
) |
Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of gradType. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.
|
inline |
Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of gradType. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.
Calls either compute_numerical_gradient or compute_analytical_gradient depending on the value of gradType.
Definition at line 257 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::ANALYTICAL_GRADIENT, ObjectiveFunction::compute_analytical_gradient(), ObjectiveFunction::compute_numerical_gradient(), ObjectiveFunction::gradType, MSQ_CHKERR, and ObjectiveFunction::NUMERICAL_GRADIENT.
Referenced by TerminationCriterion::accumulate_inner(), CompositeOFMultiply::compute_analytical_gradient(), CompositeOFAdd::compute_analytical_gradient(), CompositeOFScalarAdd::compute_analytical_gradient(), CompositeOFScalarMultiply::compute_analytical_gradient(), ConjugateGradient::optimize_vertex_positions(), SteepestDescent::optimize_vertex_positions(), FeasibleNewton::optimize_vertex_positions(), and TerminationCriterion::reset_inner().
|
inline |
Calls compute_analytical_hessian. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.
Calls compute_analytical_hessian. Numerical objective function hessians are only used for test purposes.
Definition at line 282 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::compute_analytical_hessian(), and MSQ_CHKERR.
Referenced by FeasibleNewton::optimize_vertex_positions().
bool compute_hessian | ( | PatchData & | patch, |
MsqHessian & | hessian, | ||
Vector3D *const & | grad, | ||
double & | OF_val, | ||
MsqError & | err | ||
) |
Calls compute_analytical_hessian. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.
|
protected |
Non-virtual function which numerically computes the gradient of the Objective Function. Function returns 'false' if the patch is not within a required feasible regeion. Otherwise, it returns 'true'.
Numerically Calculates the gradient of the ObjectiveFunction for the free vertices in the patch. Returns 'false' if the patch is outside of a required feasible region, returns 'ture' otherwise. The behavior of the function depends on the value of the boolean useLocalGradient. If useLocalGradient is set to 'true', compute_numerical_gradient creates a sub-patch around a free vertex, and then perturbs that vertex in one of the coordinate directions. Only the ObjectiveFunction value on the local sub-patch is used in the computation of the gradient. Therefore, useLocalGradient should only be set to 'true' for ObjectiveFunctions which can use this method. Unless the concrete ObjectiveFunction sets useLocalGradient to 'true' in its constructor, the value will be 'false'. In this case, the objective function value for the entire patch is used in the calculation of the gradient. This is computationally expensive, but it is numerically correct for all (C_1) functions.
pd | PatchData on which the gradient is taken. |
grad | Array of Vector3D of length the number of vertices used to store gradient. |
OF_val | will be set to the objective function value. |
array_size | Either the length of grad or 0. |
Definition at line 65 of file ObjectiveFunction/ObjectiveFunction.cpp.
References ObjectiveFunction::evaluate(), ObjectiveFunction::get_eps(), PatchData::get_subpatch(), PatchData::get_vertex_array(), MsqError::INVALID_STATE, j, MSQ_CHKERR, MSQ_DBGOUT, MSQ_ERRZERO, MSQ_SETERR, PatchData::num_vertices(), and ObjectiveFunction::useLocalGradient.
Referenced by ObjectiveFunction::compute_analytical_gradient(), and ObjectiveFunction::compute_gradient().
Evaluate the objective function on a given patch.
Implemented in LPtoPTemplate, LPtoPTemplate, MaxTemplate, MaxTemplate, LInfTemplate, LInfTemplate, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFScalarMultiply, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFScalarMultiply, CompositeOFMultiply, and CompositeOFMultiply.
Evaluate the objective function on a given patch.
Implemented in LPtoPTemplate, LPtoPTemplate, MaxTemplate, MaxTemplate, LInfTemplate, LInfTemplate, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFScalarMultiply, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFScalarMultiply, CompositeOFMultiply, and CompositeOFMultiply.
Referenced by ObjectiveFunction::evaluate().
Computes the value of the objective funciton as fval*negateFlag, where fval is computed in concrete_evaluate(patch, fval, err) and negateFlag is either 1 or -1 depending on whether the function needs to be minimized or maximized, respectively. Returns the bool given as a return value from concrete_evaluate. If the bool is 'false', then the patch is not within the feasible region required by the associated QualityMetric(s).
Definition at line 94 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::concrete_evaluate(), and ObjectiveFunction::negateFlag.
Referenced by TerminationCriterion::accumulate_inner(), ObjectiveFunction::compute_numerical_gradient(), CompositeOFMultiply::concrete_evaluate(), CompositeOFAdd::concrete_evaluate(), CompositeOFScalarMultiply::concrete_evaluate(), CompositeOFScalarAdd::concrete_evaluate(), TerminationCriterion::cull_vertices(), ObjectiveFunction::get_eps(), ConjugateGradient::get_step(), SmartLaplacianSmoother::optimize_vertex_positions(), SteepestDescent::optimize_vertex_positions(), FeasibleNewton::optimize_vertex_positions(), and TerminationCriterion::reset_inner().
Computes the value of the objective funciton as fval*negateFlag, where fval is computed in concrete_evaluate(patch, fval, err) and negateFlag is either 1 or -1 depending on whether the function needs to be minimized or maximized, respectively. Returns the bool given as a return value from concrete_evaluate. If the bool is 'false', then the patch is not within the feasible region required by the associated QualityMetric(s).
Definition at line 94 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
References ObjectiveFunction::concrete_evaluate(), and ObjectiveFunction::negateFlag.
|
inlineprotected |
Returns eps used in the numerical gradient calculation.
|
inlineprotected |
Returns eps used in the numerical gradient calculation.
Returns an appropiate value (eps) to use as a delta step for MsqVertex vertex in dimension k (i.e. k=0 -> x, k=1 -> y, k=2 -> z). The objective function value at the perturbed vertex position is given in local_val.
Definition at line 299 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::evaluate(), i, k, and MSQ_ERRZERO.
Referenced by ObjectiveFunction::compute_numerical_gradient().
|
inline |
Returns negateFlag.
Definition at line 170 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::negateFlag.
Referenced by CompositeOFMultiply::CompositeOFMultiply(), CompositeOFScalarMultiply::compute_analytical_gradient(), LPtoPTemplate::compute_analytical_gradient(), and LPtoPTemplate::compute_analytical_hessian().
|
inline |
Returns negateFlag.
Definition at line 170 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
References ObjectiveFunction::negateFlag.
|
inline |
Return the quality metric associated with this objective function. Returns null for composite functions which have multiple associated quality metrics. Use get_quality_metric_list() to retrieve all metrics.
Definition at line 139 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
References ObjectiveFunction::qMetric.
|
inline |
Return the quality metric associated with this objective function. Returns null for composite functions which have multiple associated quality metrics. Use get_quality_metric_list() to retrieve all metrics.
Definition at line 139 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::qMetric.
Referenced by CompositeOFAdd::CompositeOFAdd(), CompositeOFMultiply::CompositeOFMultiply(), CompositeOFScalarAdd::CompositeOFScalarAdd(), CompositeOFScalarMultiply::CompositeOFScalarMultiply(), LPtoPTemplate::compute_analytical_gradient(), LPtoPTemplate::compute_analytical_hessian(), NonSmoothSteepestDescent::compute_function(), NonSmoothSteepestDescent::compute_gradient(), LInfTemplate::concrete_evaluate(), MaxTemplate::concrete_evaluate(), and LPtoPTemplate::concrete_evaluate().
|
inlinevirtual |
returns a list of all associated metrics;
Reimplemented in CompositeOFAdd, CompositeOFScalarAdd, CompositeOFScalarMultiply, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFScalarMultiply, CompositeOFMultiply, and CompositeOFMultiply.
Definition at line 146 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
References ObjectiveFunction::qMetric.
|
inlinevirtual |
returns a list of all associated metrics;
Reimplemented in CompositeOFAdd, CompositeOFScalarAdd, CompositeOFScalarMultiply, CompositeOFAdd, CompositeOFScalarAdd, CompositeOFScalarMultiply, CompositeOFMultiply, and CompositeOFMultiply.
Definition at line 146 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::qMetric.
Referenced by NonSmoothSteepestDescent::compute_function(), NonSmoothSteepestDescent::compute_gradient(), LInfTemplate::concrete_evaluate(), LPtoPTemplate::concrete_evaluate(), CompositeOFMultiply::get_quality_metric_list(), CompositeOFScalarMultiply::get_quality_metric_list(), CompositeOFScalarAdd::get_quality_metric_list(), and CompositeOFAdd::get_quality_metric_list().
|
inline |
Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT.
Definition at line 110 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::gradType.
Referenced by CompositeOFAdd::CompositeOFAdd(), CompositeOFMultiply::CompositeOFMultiply(), CompositeOFScalarAdd::CompositeOFScalarAdd(), CompositeOFScalarMultiply::CompositeOFScalarMultiply(), ObjectiveFunction::compute_analytical_gradient(), LInfTemplate::LInfTemplate(), LPtoPTemplate::LPtoPTemplate(), MaxTemplate::MaxTemplate(), and ShapeImprovementWrapper::ShapeImprovementWrapper().
|
inline |
Set gradType to either NUMERICAL_GRADIENT or ANALYTICAL_GRADIENT.
Definition at line 110 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
References ObjectiveFunction::gradType.
|
inline |
Set the value of ObjectiveFunction's negateFlag. Unless composite, concrete ObjectiveFunctions should set this flag to to the value of the associated QualityMetric's negateFLag.
Definition at line 164 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::negateFlag.
Referenced by CompositeOFAdd::CompositeOFAdd(), CompositeOFMultiply::CompositeOFMultiply(), CompositeOFScalarAdd::CompositeOFScalarAdd(), CompositeOFScalarMultiply::CompositeOFScalarMultiply(), LInfTemplate::LInfTemplate(), LPtoPTemplate::LPtoPTemplate(), and MaxTemplate::MaxTemplate().
|
inline |
Set the value of ObjectiveFunction's negateFlag. Unless composite, concrete ObjectiveFunctions should set this flag to to the value of the associated QualityMetric's negateFLag.
Definition at line 164 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
References ObjectiveFunction::negateFlag.
|
inline |
Set the value of qMetric.
Definition at line 154 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::qMetric.
Referenced by CompositeOFAdd::CompositeOFAdd(), CompositeOFMultiply::CompositeOFMultiply(), CompositeOFScalarAdd::CompositeOFScalarAdd(), CompositeOFScalarMultiply::CompositeOFScalarMultiply(), LInfTemplate::LInfTemplate(), LPtoPTemplate::LPtoPTemplate(), and MaxTemplate::MaxTemplate().
|
inline |
Set the value of qMetric.
Definition at line 154 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
References ObjectiveFunction::qMetric.
|
inlineprotected |
Sets useLocalGradient This variable determines whether compute_numercial_gradient can use the most efficient gradient calculation.
Definition at line 230 of file src/ObjectiveFunction/ObjectiveFunction.hpp.
References ObjectiveFunction::useLocalGradient.
|
inlineprotected |
Sets useLocalGradient This variable determines whether compute_numercial_gradient can use the most efficient gradient calculation.
Definition at line 230 of file includeLinks/ObjectiveFunction.hpp.
References ObjectiveFunction::useLocalGradient.
|
private |
Definition at line 238 of file includeLinks/ObjectiveFunction.hpp.
Referenced by ObjectiveFunction::compute_gradient(), and ObjectiveFunction::set_gradient_type().
|
private |
Pointer to associated QualityMetric.
Definition at line 242 of file includeLinks/ObjectiveFunction.hpp.
Referenced by ObjectiveFunction::evaluate(), ObjectiveFunction::get_negate_flag(), and ObjectiveFunction::set_negate_flag().
|
private |
Flag for numerical or analytical gradient.
Definition at line 240 of file includeLinks/ObjectiveFunction.hpp.
Referenced by ObjectiveFunction::get_quality_metric(), ObjectiveFunction::get_quality_metric_list(), and ObjectiveFunction::set_quality_metric().
|
private |
Equals one if ObjectiveFunction needs to
be minimized; equals negative one if ObjectiveFunction needs to be maximized.
Definition at line 245 of file includeLinks/ObjectiveFunction.hpp.
Referenced by ObjectiveFunction::compute_numerical_gradient(), and ObjectiveFunction::set_use_local_gradient().