MOAB: Mesh Oriented datABase  (version 5.2.1)
MBMesquite::StdDevTemplate Class Reference

standard deviation template More...

#include <StdDevTemplate.hpp>

+ Inheritance diagram for MBMesquite::StdDevTemplate:
+ Collaboration diagram for MBMesquite::StdDevTemplate:

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.

Detailed Description

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.


Constructor & Destructor Documentation

Definition at line 50 of file StdDevTemplate.hpp.

Referenced by clone().

: VarianceTemplate( qm ) {}

Definition at line 53 of file StdDevTemplate.hpp.

{}

Member Function Documentation

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.

Parameters:
typeEvaluation type.
pdThe patch.
value_outThe passed-back value of the objective fuction.
freeIf true, incorporate the quality metric values only for those metric evaluations that depend on at least one free vertex
Returns:
false if any QualityMetric evaluation returned false, true otherwise.

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.

Parameters:
typeEvaluation type.
pdThe patch.
value_outThe passed-back value of the objective fuction.
grad_outThe gradient of the OF wrt the coordinates of each *free* vertex in the patch.
Returns:
false if any QualityMetric evaluation returned false, true otherwise.

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.

Parameters:
pdPatchData on which the gradient is taken.
gradArray of Vector3D of length the number of vertices used to store gradient.
OF_valwill 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.

Parameters:
typeEvaluation type.
pdThe patch.
value_outThe passed-back value of the objective fuction.
grad_outThe gradient of the OF wrt the coordinates of each *free* vertex in the patch.
hess_diag_outThe diagonal blocks of a Hessian. I.e. Decompose the Hessian into 3x3 submatrices and return only the submatrices (blocks) along the diagonal.
Returns:
false if any QualityMetric evaluation returned false, true otherwise.

Reimplemented from MBMesquite::VarianceTemplate.

Definition at line 74 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;
}

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines