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

Scales a given an ObjectiveFunction. More...

#include <CompositeOFScalarMultiply.hpp>

+ Inheritance diagram for MBMesquite::CompositeOFScalarMultiply:
+ Collaboration diagram for MBMesquite::CompositeOFScalarMultiply:

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 ObjectiveFunctionclone () const
 Create copy with same state.
virtual void clear ()
virtual int min_patch_layers () const

Private Attributes

ObjectiveFunctionobjFunc
double mAlpha
bool deleteObjFunc

Detailed Description

Scales a given an ObjectiveFunction.

Definition at line 54 of file CompositeOFScalarMultiply.hpp.


Constructor & Destructor Documentation

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.

Parameters:
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;
}

Member Function Documentation

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.

{
    objFunc->clear();
}

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.

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.

Implements MBMesquite::ObjectiveFunction.

Definition at line 90 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.

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::ObjectiveFunction.

Definition at line 97 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.

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.
Hessian_outThe Hessian of the OF wrt the coordinates of each *free* vertex in the patch.
Returns:
false if any QualityMetric evaluation returned false, true otherwise.

Reimplemented from MBMesquite::ObjectiveFunction.

Definition at line 121 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.

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::ObjectiveFunction.

Definition at line 107 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.

Parameters:
meshThe Mesh
domainThe MeshDomain
user_setUser-defined patch set - not relevant for most OF templates.

Implements MBMesquite::ObjectiveFunction.

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

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 133 of file CompositeOFScalarMultiply.cpp.

References MBMesquite::ObjectiveFunction::min_patch_layers(), and objFunc.

{
    return objFunc->min_patch_layers();
}

Member Data Documentation

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