MOAB: Mesh Oriented datABase
(version 5.4.1)
|
Scales a given an ObjectiveFunction. More...
#include <CompositeOFScalarMultiply.hpp>
Public Member Functions | |
CompositeOFScalarMultiply (double, ObjectiveFunction *, bool delete_OF=false) | |
virtual | ~CompositeOFScalarMultiply () |
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 | |
ObjectiveFunction * | objFunc |
double | mAlpha |
bool | deleteObjFunc |
Scales a given an ObjectiveFunction.
Definition at line 54 of file CompositeOFScalarMultiply.hpp.
MBMesquite::CompositeOFScalarMultiply::CompositeOFScalarMultiply | ( | double | alp, |
ObjectiveFunction * | Obj, | ||
bool | delete_of = false |
||
) |
Sets the QualityMetric pointer to the metric associated with Obj. However, if alp is less than zero, the new ObjectiveFunction's negateFlag is the opposite of Obj's. This objective function defaults to the analytical gradient.
alp | (double) |
Obj | (ObjectiveFunction*) |
Definition at line 53 of file CompositeOFScalarMultiply.cpp.
References mAlpha, and objFunc.
Referenced by clone().
: deleteObjFunc( delete_of ) { objFunc = Obj; mAlpha = alp; }
Definition at line 61 of file CompositeOFScalarMultiply.cpp.
References deleteObjFunc, and objFunc.
{ if( deleteObjFunc ) delete objFunc; }
void MBMesquite::CompositeOFScalarMultiply::clear | ( | ) | [virtual] |
Clear any values accumulated for BCD-related eval calls
Implements MBMesquite::ObjectiveFunction.
Definition at line 71 of file CompositeOFScalarMultiply.cpp.
References MBMesquite::ObjectiveFunction::clear(), and objFunc.
ObjectiveFunction * MBMesquite::CompositeOFScalarMultiply::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 66 of file CompositeOFScalarMultiply.cpp.
References MBMesquite::ObjectiveFunction::clone(), CompositeOFScalarMultiply(), mAlpha, and objFunc.
{ return new CompositeOFScalarMultiply( mAlpha, objFunc->clone(), true ); }
bool MBMesquite::CompositeOFScalarMultiply::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 92 of file CompositeOFScalarMultiply.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 MBMesquite::CompositeOFScalarMultiply::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 99 of file CompositeOFScalarMultiply.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; for( std::vector< Vector3D >::iterator i = grad_out.begin(); i != grad_out.end(); ++i ) *i *= mAlpha; return !MSQ_CHKERR( err ) && ok; }
bool MBMesquite::CompositeOFScalarMultiply::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 129 of file CompositeOFScalarMultiply.cpp.
References MBMesquite::ObjectiveFunction::evaluate_with_Hessian(), mAlpha, MSQ_CHKERR, objFunc, and MBMesquite::MsqHessian::scale().
{ bool ok = objFunc->evaluate_with_Hessian( type, pd, value_out, grad_out, Hessian_out, err ); value_out *= mAlpha; for( std::vector< Vector3D >::iterator i = grad_out.begin(); i != grad_out.end(); ++i ) *i *= mAlpha; Hessian_out.scale( mAlpha ); return !MSQ_CHKERR( err ) && ok; }
bool MBMesquite::CompositeOFScalarMultiply::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 112 of file CompositeOFScalarMultiply.cpp.
References MBMesquite::ObjectiveFunction::evaluate_with_Hessian_diagonal(), mAlpha, MSQ_CHKERR, MBMesquite::PatchData::num_free_vertices(), and objFunc.
{ bool ok = objFunc->evaluate_with_Hessian_diagonal( type, pd, value_out, grad_out, diag_out, err ); value_out *= mAlpha; for( size_t i = 0; i < pd.num_free_vertices(); ++i ) { grad_out[i] *= mAlpha; diag_out[i] *= mAlpha; } return !MSQ_CHKERR( err ) && ok; }
bool MBMesquite::CompositeOFScalarMultiply::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 83 of file CompositeOFScalarMultiply.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 MBMesquite::CompositeOFScalarMultiply::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 76 of file CompositeOFScalarMultiply.cpp.
References MBMesquite::ObjectiveFunction::initialize_queue(), MSQ_ERRRTN, and objFunc.
{ objFunc->initialize_queue( mesh_and_domain, settings, err );MSQ_ERRRTN( err ); }
int MBMesquite::CompositeOFScalarMultiply::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 144 of file CompositeOFScalarMultiply.cpp.
References MBMesquite::ObjectiveFunction::min_patch_layers(), and objFunc.
{ return objFunc->min_patch_layers(); }
bool MBMesquite::CompositeOFScalarMultiply::deleteObjFunc [private] |
Definition at line 102 of file CompositeOFScalarMultiply.hpp.
Referenced by ~CompositeOFScalarMultiply().
double MBMesquite::CompositeOFScalarMultiply::mAlpha [private] |
Definition at line 101 of file CompositeOFScalarMultiply.hpp.
Referenced by clone(), CompositeOFScalarMultiply(), evaluate(), evaluate_with_gradient(), evaluate_with_Hessian(), and evaluate_with_Hessian_diagonal().
Definition at line 100 of file CompositeOFScalarMultiply.hpp.
Referenced by clear(), clone(), CompositeOFScalarMultiply(), evaluate(), evaluate_with_gradient(), evaluate_with_Hessian(), evaluate_with_Hessian_diagonal(), initialize_block_coordinate_descent(), initialize_queue(), min_patch_layers(), and ~CompositeOFScalarMultiply().