MOAB: Mesh Oriented datABase
(version 5.4.1)
|
Adds a scalar to a given ObjectiveFunction. More...
#include <CompositeOFScalarAdd.hpp>
Public Member Functions | |
CompositeOFScalarAdd (double, ObjectiveFunction *, bool delete_OF=false) | |
virtual | ~CompositeOFScalarAdd () |
virtual void | initialize_queue (MeshDomainAssoc *mesh_and_domain, const Settings *settings, MsqError &err) |
Called at start of instruction queue processing. | |
virtual bool | initialize_block_coordinate_descent (MeshDomainAssoc *mesh_and_domain, const Settings *settings, PatchSet *user_set, MsqError &err) |
Initial accumulated value for block coordinate descent algorithms. | |
virtual bool | evaluate (EvalType type, PatchData &pd, double &value_out, bool free, MsqError &err) |
Evaluate objective function for specified patch. | |
virtual bool | evaluate_with_gradient (EvalType type, PatchData &pd, double &value_out, std::vector< Vector3D > &grad_out, MsqError &err) |
Evaluate objective function and gradient for specified patch. | |
virtual bool | evaluate_with_Hessian_diagonal (EvalType type, PatchData &pd, double &value_out, std::vector< Vector3D > &grad_out, std::vector< SymMatrix3D > &hess_diag_out, MsqError &err) |
Evaluate objective function and diagonal blocks of Hessian for specified patch. | |
virtual bool | evaluate_with_Hessian (EvalType type, PatchData &pd, double &value_out, std::vector< Vector3D > &grad_out, MsqHessian &Hessian_out, MsqError &err) |
Evaluate objective function and Hessian for specified patch. | |
virtual ObjectiveFunction * | clone () const |
Create copy with same state. | |
virtual void | clear () |
virtual int | min_patch_layers () const |
Private Attributes | |
double | mAlpha |
ObjectiveFunction * | objFunc |
bool | deleteObjFunc |
Adds a scalar to a given ObjectiveFunction.
Definition at line 53 of file CompositeOFScalarAdd.hpp.
CompositeOFScalarAdd::CompositeOFScalarAdd | ( | double | alp, |
ObjectiveFunction * | Obj1, | ||
bool | delete_OF = false |
||
) |
Sets the QualityMetric pointer to the metric associated with Obj1. The new ObjectiveFunction's negateFlag is also the same as that of Obj1. This objective function defaults to the analytical gradient which essentially just calls Obj1's gradient function.
alp | (double) |
Obj1 | (ObjectiveFunction*) |
Definition at line 49 of file CompositeOFScalarAdd.cpp.
References mAlpha, and objFunc.
Referenced by clone().
: deleteObjFunc( delete_OF ) { objFunc = Obj1; mAlpha = alp; }
CompositeOFScalarAdd::~CompositeOFScalarAdd | ( | ) | [virtual] |
Definition at line 57 of file CompositeOFScalarAdd.cpp.
References deleteObjFunc, and objFunc.
{ if( deleteObjFunc ) delete objFunc; }
void CompositeOFScalarAdd::clear | ( | ) | [virtual] |
Clear any values accumulated for BCD-related eval calls
Implements MBMesquite::ObjectiveFunction.
Definition at line 67 of file CompositeOFScalarAdd.cpp.
References MBMesquite::ObjectiveFunction::clear(), and objFunc.
ObjectiveFunction * CompositeOFScalarAdd::clone | ( | ) | const [virtual] |
Create copy with same state.
Create a new instance of the objective function that is a copy of the callee with the same accumulated values, parameters, etc.
Implements MBMesquite::ObjectiveFunction.
Definition at line 62 of file CompositeOFScalarAdd.cpp.
References MBMesquite::ObjectiveFunction::clone(), CompositeOFScalarAdd(), mAlpha, and objFunc.
{ return new CompositeOFScalarAdd( mAlpha, objFunc->clone(), true ); }
bool CompositeOFScalarAdd::evaluate | ( | EvalType | type, |
PatchData & | pd, | ||
double & | value_out, | ||
bool | free, | ||
MsqError & | err | ||
) | [virtual] |
Evaluate objective function for specified patch.
Either evaluate the objective function over the passed patch or update the accumulated, global objective function value for changes in the passed patch, depending on the value of the EvalType.
type | Evaluation type. |
pd | The patch. |
value_out | The passed-back value of the objective fuction. |
free | If true, incorporate the quality metric values only for those metric evaluations that depend on at least one free vertex |
Implements MBMesquite::ObjectiveFunction.
Definition at line 86 of file CompositeOFScalarAdd.cpp.
References MBMesquite::ObjectiveFunction::evaluate(), mAlpha, MSQ_CHKERR, and objFunc.
{ bool ok = objFunc->evaluate( type, pd, value_out, free, err ); value_out += mAlpha; return !MSQ_CHKERR( err ) && ok; }
bool CompositeOFScalarAdd::evaluate_with_gradient | ( | EvalType | eval_type, |
PatchData & | pd, | ||
double & | OF_val, | ||
std::vector< Vector3D > & | grad, | ||
MsqError & | err | ||
) | [virtual] |
Evaluate objective function and gradient for specified patch.
Either evaluate the objective function over the passed patch or update the accumulated, global objective function value for changes in the passed patch, depending on the value of the EvalType.
The default implementation of this function will use the value-only variation of the evaluate method and numerical approximation to calculate gradients. Whenever possible, objective function implementations should provide more efficient analyical gradient calculations.
type | Evaluation type. |
pd | The patch. |
value_out | The passed-back value of the objective fuction. |
grad_out | The gradient of the OF wrt the coordinates of each *free* vertex in the patch. |
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. |
Reimplemented from MBMesquite::ObjectiveFunction.
Definition at line 93 of file CompositeOFScalarAdd.cpp.
References MBMesquite::ObjectiveFunction::evaluate_with_gradient(), mAlpha, MSQ_CHKERR, and objFunc.
{ bool ok = objFunc->evaluate_with_gradient( type, pd, value_out, grad_out, err ); value_out += mAlpha; return !MSQ_CHKERR( err ) && ok; }
bool CompositeOFScalarAdd::evaluate_with_Hessian | ( | EvalType | type, |
PatchData & | pd, | ||
double & | value_out, | ||
std::vector< Vector3D > & | grad_out, | ||
MsqHessian & | Hessian_out, | ||
MsqError & | err | ||
) | [virtual] |
Evaluate objective function and Hessian for specified patch.
Either evaluate the objective function over the passed patch or update the accumulated, global objective function value for changes in the passed patch, depending on the value of the EvalType.
The default implementation of this function will fail.
type | Evaluation type. |
pd | The patch. |
value_out | The passed-back value of the objective fuction. |
grad_out | The gradient of the OF wrt the coordinates of each *free* vertex in the patch. |
Hessian_out | The Hessian of the OF wrt the coordinates of each *free* vertex in the patch. |
Reimplemented from MBMesquite::ObjectiveFunction.
Definition at line 116 of file CompositeOFScalarAdd.cpp.
References MBMesquite::ObjectiveFunction::evaluate_with_Hessian(), mAlpha, MSQ_CHKERR, and objFunc.
{ bool ok = objFunc->evaluate_with_Hessian( type, pd, value_out, grad_out, Hessian_out, err ); value_out += mAlpha; return !MSQ_CHKERR( err ) && ok; }
bool CompositeOFScalarAdd::evaluate_with_Hessian_diagonal | ( | EvalType | type, |
PatchData & | pd, | ||
double & | value_out, | ||
std::vector< Vector3D > & | grad_out, | ||
std::vector< SymMatrix3D > & | hess_diag_out, | ||
MsqError & | err | ||
) | [virtual] |
Evaluate objective function and diagonal blocks of Hessian for specified patch.
Either evaluate the objective function over the passed patch or update the accumulated, global objective function value for changes in the passed patch, depending on the value of the EvalType.
The default implementation of this function evaluate the entire Hessian and discard non-diagonal portions. Concrete objective functions should provide a more efficient implementation that evaluates and accumulates only the required terms.
type | Evaluation type. |
pd | The patch. |
value_out | The passed-back value of the objective fuction. |
grad_out | The gradient of the OF wrt the coordinates of each *free* vertex in the patch. |
hess_diag_out | The diagonal blocks of a Hessian. I.e. Decompose the Hessian into 3x3 submatrices and return only the submatrices (blocks) along the diagonal. |
Reimplemented from MBMesquite::ObjectiveFunction.
Definition at line 104 of file CompositeOFScalarAdd.cpp.
References MBMesquite::ObjectiveFunction::evaluate_with_Hessian_diagonal(), mAlpha, MSQ_CHKERR, and objFunc.
{ bool ok = objFunc->evaluate_with_Hessian_diagonal( type, pd, value_out, grad_out, diag_out, err ); value_out += mAlpha; return !MSQ_CHKERR( err ) && ok; }
bool CompositeOFScalarAdd::initialize_block_coordinate_descent | ( | MeshDomainAssoc * | mesh_and_domain, |
const Settings * | settings, | ||
PatchSet * | user_set, | ||
MsqError & | err | ||
) | [virtual] |
Initial accumulated value for block coordinate descent algorithms.
Set accumulated value of objective function to the value for the entire, unmodified mesh. This is the initial state for a block coordinate descent algorithm. The ObjectiveFunction will asked to add or remove values for a specific patch of the mesh during the optimization.
mesh | The Mesh |
domain | The MeshDomain |
user_set | User-defined patch set - not relevant for most OF templates. |
Implements MBMesquite::ObjectiveFunction.
Definition at line 77 of file CompositeOFScalarAdd.cpp.
References MBMesquite::ObjectiveFunction::initialize_block_coordinate_descent(), MSQ_CHKERR, and objFunc.
{ bool rval = objFunc->initialize_block_coordinate_descent( mesh_and_domain, settings, user_set, err ); return !MSQ_CHKERR( err ) && rval; }
void CompositeOFScalarAdd::initialize_queue | ( | MeshDomainAssoc * | mesh_and_domain, |
const Settings * | settings, | ||
MsqError & | err | ||
) | [virtual] |
Called at start of instruction queue processing.
Do any preliminary global initialization, consistency checking, etc.
Implements MBMesquite::ObjectiveFunction.
Definition at line 72 of file CompositeOFScalarAdd.cpp.
References MBMesquite::ObjectiveFunction::initialize_queue(), MSQ_ERRRTN, and objFunc.
{ objFunc->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err ); }
int CompositeOFScalarAdd::min_patch_layers | ( | ) | const [virtual] |
Get the minimum number of layers of adjacent elements required in a patch to evaluate the objective function for a single free vertex.
Implements MBMesquite::ObjectiveFunction.
Definition at line 128 of file CompositeOFScalarAdd.cpp.
References MBMesquite::ObjectiveFunction::min_patch_layers(), and objFunc.
{ return objFunc->min_patch_layers(); }
bool MBMesquite::CompositeOFScalarAdd::deleteObjFunc [private] |
Definition at line 101 of file CompositeOFScalarAdd.hpp.
Referenced by ~CompositeOFScalarAdd().
double MBMesquite::CompositeOFScalarAdd::mAlpha [private] |
Definition at line 99 of file CompositeOFScalarAdd.hpp.
Referenced by clone(), CompositeOFScalarAdd(), evaluate(), evaluate_with_gradient(), evaluate_with_Hessian(), and evaluate_with_Hessian_diagonal().
Definition at line 100 of file CompositeOFScalarAdd.hpp.
Referenced by clear(), clone(), CompositeOFScalarAdd(), evaluate(), evaluate_with_gradient(), evaluate_with_Hessian(), evaluate_with_Hessian_diagonal(), initialize_block_coordinate_descent(), initialize_queue(), min_patch_layers(), and ~CompositeOFScalarAdd().