MOAB: Mesh Oriented datABase
(version 5.4.1)
|
standard deviation template More...
#include <StdDevTemplate.hpp>
Public Member Functions | |
MESQUITE_EXPORT | StdDevTemplate (QualityMetric *qm=0) |
virtual MESQUITE_EXPORT | ~StdDevTemplate () |
virtual MESQUITE_EXPORT bool | evaluate (EvalType type, PatchData &pd, double &value_out, bool free, MsqError &err) |
Evaluate objective function for specified patch. | |
virtual MESQUITE_EXPORT 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 MESQUITE_EXPORT 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 MESQUITE_EXPORT ObjectiveFunction * | clone () const |
Create copy with same state. |
standard deviation template
This class implements an objective function that is the standard deviation of the quality metric evalutations.
Definition at line 46 of file StdDevTemplate.hpp.
MESQUITE_EXPORT MBMesquite::StdDevTemplate::StdDevTemplate | ( | QualityMetric * | qm = 0 | ) | [inline] |
Definition at line 50 of file StdDevTemplate.hpp.
Referenced by clone().
: VarianceTemplate( qm ) {}
virtual MESQUITE_EXPORT MBMesquite::StdDevTemplate::~StdDevTemplate | ( | ) | [inline, virtual] |
Definition at line 53 of file StdDevTemplate.hpp.
{}
ObjectiveFunction * MBMesquite::StdDevTemplate::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.
Reimplemented from MBMesquite::VarianceTemplate.
Definition at line 42 of file StdDevTemplate.cpp.
References StdDevTemplate().
{ return new StdDevTemplate( *this ); }
bool MBMesquite::StdDevTemplate::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 |
Reimplemented from MBMesquite::VarianceTemplate.
Definition at line 47 of file StdDevTemplate.cpp.
References MBMesquite::QualityMetric::get_negate_flag(), MBMesquite::ObjectiveFunctionTemplate::get_quality_metric(), and MSQ_CHKERR.
{ bool result = VarianceTemplate::evaluate( type, pd, value_out, free, err ); if( MSQ_CHKERR( err ) || !result ) return false; const double neg = get_quality_metric()->get_negate_flag(); value_out = neg * sqrt( neg * value_out ); return true; }
bool MBMesquite::StdDevTemplate::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::VarianceTemplate.
Definition at line 57 of file StdDevTemplate.cpp.
References MBMesquite::QualityMetric::get_negate_flag(), MBMesquite::ObjectiveFunctionTemplate::get_quality_metric(), and MSQ_CHKERR.
{ bool result = VarianceTemplate::evaluate_with_gradient( type, pd, value_out, grad_out, err ); if( MSQ_CHKERR( err ) || !result ) return false; const double neg = get_quality_metric()->get_negate_flag(); value_out *= neg; // undo any negation done by VarianceTemplate value_out = sqrt( value_out ); // standard deviation const double factor = 1.0 / ( 2.0 * value_out ); for( std::vector< Vector3D >::iterator i = grad_out.begin(); i != grad_out.end(); ++i ) *i *= factor; value_out *= neg; // redo any negation done by VariandeTemplate return true; }
bool MBMesquite::StdDevTemplate::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::VarianceTemplate.
Definition at line 77 of file StdDevTemplate.cpp.
References MBMesquite::QualityMetric::get_negate_flag(), MBMesquite::ObjectiveFunctionTemplate::get_quality_metric(), MSQ_CHKERR, and MBMesquite::outer().
{ bool result = VarianceTemplate::evaluate_with_Hessian_diagonal( type, pd, value_out, grad_out, hess_diag_out, err ); if( MSQ_CHKERR( err ) || !result ) return false; const double neg = get_quality_metric()->get_negate_flag(); value_out *= neg; // undo any negation done by VarianceTemplate value_out = sqrt( value_out ); // standard deviation const double f1 = 1.0 / ( 2.0 * value_out ); const double f2 = neg * -0.25 / ( value_out * value_out * value_out ); for( size_t i = 0; i < grad_out.size(); ++i ) { hess_diag_out[i] *= f1; hess_diag_out[i] += f2 * outer( grad_out[i] ); grad_out[i] *= f1; } value_out *= neg; // redo any negation done by VariandeTemplate return true; }