MOAB: Mesh Oriented datABase  (version 5.4.1)
PMeanPTemplateTest Class Reference
+ Inheritance diagram for PMeanPTemplateTest:
+ Collaboration diagram for PMeanPTemplateTest:

Public Member Functions

void setUp ()
void test_eval_calc ()
void test_eval_accum ()
void test_eval_save ()
void test_eval_update ()
void test_eval_temp ()
void test_grad_calc ()
void test_grad_save ()
void test_grad_update ()
void test_grad_temp ()
void test_diag_calc ()
void test_diag_save ()
void test_diag_update ()
void test_diag_temp ()
void test_Hess_calc ()
void test_Hess_save ()
void test_Hess_update ()
void test_Hess_temp ()
void test_clone ()
void test_failed_metric_in_eval ()
void test_failed_metric_in_grad ()
void test_failed_metric_in_diag ()
void test_failed_metric_in_Hess ()
void test_false_metric_in_eval ()
void test_false_metric_in_grad ()
void test_false_metric_in_diag ()
void test_false_metric_in_Hess ()
void test_evaluate_arithmatic ()
void test_evaluate_rms ()
void test_gradient_arithmatic ()
void test_gradient_rms ()
void test_diagonal_arithmatic ()
void test_diagonal_rms ()
void test_Hessian_arithmatic ()
void test_Hessian_rms ()
void compare_gradient_arithmatic ()
void compare_gradient_rms ()
void compare_diagonal_gradient_arithmatic ()
void compare_diagonal_gradient_rms ()
void compare_hessian_gradient_arithmatic ()
void compare_hessian_gradient_rms ()
void compare_hessian_diagonal_arithmatic ()
void compare_hessian_diagonal_rms ()
void compare_hessian_arithmatic ()
void compare_hessian_rms ()
void compare_hessian_diag_arithmatic ()
void compare_hessian_diag_rms ()
void test_negate_eval ()
void test_negate_grad ()
void test_negate_diag ()
void test_negate_hess ()

Private Member Functions

void test_eval_type (OFTestMode eval_func, ObjectiveFunction::EvalType type)
void test_evaluate (double power)
void test_gradient (double power)
void test_diagonal (double power)
void test_Hessian (double power)
void check_result (PatchData &pd, double power, double value, Vector3D *gradient=0, Matrix3D *Hessian=0)
 CPPUNIT_TEST_SUITE (PMeanPTemplateTest)
 CPPUNIT_TEST (test_eval_calc)
 CPPUNIT_TEST (test_eval_accum)
 CPPUNIT_TEST (test_eval_save)
 CPPUNIT_TEST (test_eval_update)
 CPPUNIT_TEST (test_eval_temp)
 CPPUNIT_TEST (test_grad_calc)
 CPPUNIT_TEST (test_grad_save)
 CPPUNIT_TEST (test_grad_update)
 CPPUNIT_TEST (test_grad_temp)
 CPPUNIT_TEST (test_diag_calc)
 CPPUNIT_TEST (test_diag_save)
 CPPUNIT_TEST (test_diag_update)
 CPPUNIT_TEST (test_diag_temp)
 CPPUNIT_TEST (test_Hess_calc)
 CPPUNIT_TEST (test_Hess_save)
 CPPUNIT_TEST (test_Hess_update)
 CPPUNIT_TEST (test_Hess_temp)
 CPPUNIT_TEST (test_clone)
 CPPUNIT_TEST (test_failed_metric_in_eval)
 CPPUNIT_TEST (test_failed_metric_in_grad)
 CPPUNIT_TEST (test_failed_metric_in_diag)
 CPPUNIT_TEST (test_failed_metric_in_Hess)
 CPPUNIT_TEST (test_false_metric_in_eval)
 CPPUNIT_TEST (test_false_metric_in_grad)
 CPPUNIT_TEST (test_false_metric_in_diag)
 CPPUNIT_TEST (test_false_metric_in_Hess)
 CPPUNIT_TEST (test_evaluate_arithmatic)
 CPPUNIT_TEST (test_evaluate_rms)
 CPPUNIT_TEST (test_gradient_arithmatic)
 CPPUNIT_TEST (test_gradient_rms)
 CPPUNIT_TEST (test_Hessian_arithmatic)
 CPPUNIT_TEST (test_Hessian_rms)
 CPPUNIT_TEST (compare_gradient_arithmatic)
 CPPUNIT_TEST (compare_gradient_rms)
 CPPUNIT_TEST (compare_diagonal_gradient_arithmatic)
 CPPUNIT_TEST (compare_diagonal_gradient_rms)
 CPPUNIT_TEST (compare_hessian_gradient_arithmatic)
 CPPUNIT_TEST (compare_hessian_gradient_rms)
 CPPUNIT_TEST (compare_hessian_diagonal_arithmatic)
 CPPUNIT_TEST (compare_hessian_diagonal_rms)
 CPPUNIT_TEST (compare_hessian_arithmatic)
 CPPUNIT_TEST (compare_hessian_rms)
 CPPUNIT_TEST (compare_hessian_diag_arithmatic)
 CPPUNIT_TEST (compare_hessian_diag_rms)
 CPPUNIT_TEST (test_negate_eval)
 CPPUNIT_TEST (test_negate_grad)
 CPPUNIT_TEST (test_negate_diag)
 CPPUNIT_TEST (test_negate_hess)
 CPPUNIT_TEST_SUITE_END ()

Private Attributes

PatchData mPatch

Detailed Description

Definition at line 47 of file PMeanPTemplateTest.cpp.


Member Function Documentation

void PMeanPTemplateTest::check_result ( PatchData pd,
double  power,
double  value,
Vector3D gradient = 0,
Matrix3D Hessian = 0 
) [private]

Definition at line 553 of file PMeanPTemplateTest.cpp.

References ASSERT_NO_ERROR, CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, CPPUNIT_ASSERT_MATRICES_EQUAL, CPPUNIT_ASSERT_VECTORS_EQUAL, MBMesquite::EPSILON, MBMesquite::QualityMetric::evaluate_with_Hessian(), MBMesquite::VertexQM::get_evaluations(), MSQ_CHKERR, MBMesquite::OF_FREE_EVALS_ONLY, MBMesquite::Matrix3D::outer_product(), moab::sum(), and value().

{
    MsqPrintError err( cout );
    double mvalue, sum = 0;
    bool rval;
    vector< Vector3D > grads;
    vector< Matrix3D > Hess;
    vector< size_t > indices;

    DistTestMetric metric;
    vector< size_t > handles;
    metric.get_evaluations( pd, handles, OF_FREE_EVALS_ONLY, err );
    ASSERT_NO_ERROR( err );

    for( size_t i = 0; i < handles.size(); ++i )
    {
        rval = metric.evaluate_with_Hessian( pd, handles[i], mvalue, indices, grads, Hess, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) && rval );
        sum += pow( mvalue, power );

        // if (!OF_FREE_EVALS_ONLY && indices.empty())
        //  continue;

        CPPUNIT_ASSERT_EQUAL( (size_t)1, indices.size() );
        CPPUNIT_ASSERT_EQUAL( handles[i], indices[0] );
        CPPUNIT_ASSERT_EQUAL( (size_t)1, grads.size() );
        CPPUNIT_ASSERT_EQUAL( (size_t)1, Hess.size() );

        if( gradient )
        {
            double f = power * pow( mvalue, power - 1 ) / handles.size();
            CPPUNIT_ASSERT_VECTORS_EQUAL( f * grads[0], gradient[i], EPSILON );
        }
        if( Hessian )
        {
            double f  = power / handles.size();
            double p2 = ( power - 1 ) * pow( mvalue, power - 2 );
            double p1 = pow( mvalue, power - 1 );
            Matrix3D m;
            m.outer_product( grads[0], grads[0] );
            m *= p2;
            m += p1 * Hess[0];
            m *= f;
            CPPUNIT_ASSERT_MATRICES_EQUAL( m, Hessian[i], EPSILON );
        }
    }

    CPPUNIT_ASSERT_DOUBLES_EQUAL( sum / handles.size(), value, EPSILON );
}

Definition at line 303 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 2, NULL );
        compare_diagonal_gradient( &of );
    }

Definition at line 287 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        compare_numerical_gradient( &of );
    }

Definition at line 292 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 2, NULL );
        compare_numerical_gradient( &of );
    }

Definition at line 331 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        compare_numerical_hessian( &of );
    }

Definition at line 347 of file PMeanPTemplateTest.cpp.

Definition at line 320 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        compare_hessian_diagonal( &of );
    }

Definition at line 325 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 2, NULL );
        compare_hessian_diagonal( &of );
    }

Definition at line 309 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        compare_hessian_gradient( &of );
    }

Definition at line 314 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 2, NULL );
        compare_hessian_gradient( &of );
    }

Definition at line 336 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 2, NULL );
        compare_numerical_hessian( &of );
    }

Definition at line 378 of file PMeanPTemplateTest.cpp.

References CPPUNIT_ASSERT, MSQ_CHKERR, and MBMesquite::TRIANGLE.

{
    MsqPrintError err( std::cout );

    // Create a triangle mesh with three free vertices
    const double coords[]   = { 1, 1, 0, 2, 1, 0, 3, 1, 0, 2, 2, 0, 1, 3, 0, 1, 2, 0 };
    const bool fixed_vtx[]  = { true, false, true, false, true, false };
    const size_t tri_conn[] = { 0, 1, 5, 1, 2, 3, 3, 4, 5, 1, 3, 5 };
    mPatch.fill( 6, coords, 4, TRIANGLE, tri_conn, fixed_vtx, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
}

Definition at line 169 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::CALCULATE.

    {
        test_eval_type( DIAG, ObjectiveFunction::CALCULATE );
    }

Definition at line 173 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::SAVE.

    {
        test_eval_type( DIAG, ObjectiveFunction::SAVE );
    }

Definition at line 181 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::TEMPORARY.

    {
        test_eval_type( DIAG, ObjectiveFunction::TEMPORARY );
    }

Definition at line 177 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::UPDATE.

    {
        test_eval_type( DIAG, ObjectiveFunction::UPDATE );
    }
void PMeanPTemplateTest::test_diagonal ( double  power) [private]

Definition at line 491 of file PMeanPTemplateTest.cpp.

References MBMesquite::arrptr(), MBMesquite::ObjectiveFunction::CALCULATE, CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::PMeanPTemplate::evaluate_with_Hessian_diagonal(), MBMesquite::grad(), MSQ_CHKERR, n, and value().

{
    MsqPrintError err( cout );
    double value;
    bool rval;
    vector< Vector3D > grad;
    vector< SymMatrix3D > Hess;
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );

    DistTestMetric metric;
    PMeanPTemplate func( power, &metric );
    rval = func.evaluate_with_Hessian_diagonal( ObjectiveFunction::CALCULATE, mPatch, value, grad, Hess, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    size_t n = mPatch.num_free_vertices();
    CPPUNIT_ASSERT_EQUAL( n, grad.size() );
    CPPUNIT_ASSERT_EQUAL( n, Hess.size() );

    vector< Matrix3D > Hessians( n );
    for( size_t r = 0; r < n; ++r )
        Hessians[r] = Hess[r];

    if( !grad.empty() ) check_result( mPatch, power, value, arrptr( grad ), arrptr( Hessians ) );
}

Definition at line 269 of file PMeanPTemplateTest.cpp.

    {
        test_diagonal( 1 );
    }

Definition at line 273 of file PMeanPTemplateTest.cpp.

    {
        test_diagonal( 2 );
    }

Definition at line 135 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::ACCUMULATE.

    {
        test_eval_type( EVAL, ObjectiveFunction::ACCUMULATE );
    }

Definition at line 131 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::CALCULATE.

    {
        test_eval_type( EVAL, ObjectiveFunction::CALCULATE );
    }

Definition at line 139 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::SAVE.

    {
        test_eval_type( EVAL, ObjectiveFunction::SAVE );
    }

Definition at line 147 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::TEMPORARY.

    {
        test_eval_type( EVAL, ObjectiveFunction::TEMPORARY );
    }

Definition at line 453 of file PMeanPTemplateTest.cpp.

References ObjectiveFunctionTests::test_eval_type().

{
    PMeanPTemplate func( 1, NULL );
    ObjectiveFunctionTests::test_eval_type( type, eval_func, &func );
}

Definition at line 143 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::UPDATE.

    {
        test_eval_type( EVAL, ObjectiveFunction::UPDATE );
    }
void PMeanPTemplateTest::test_evaluate ( double  power) [private]

Definition at line 459 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::CALCULATE, CPPUNIT_ASSERT, MBMesquite::PMeanPTemplate::evaluate(), MSQ_CHKERR, MBMesquite::OF_FREE_EVALS_ONLY, and value().

{
    MsqPrintError err( cout );
    double value;
    bool rval;

    DistTestMetric metric;
    PMeanPTemplate func( power, &metric );
    rval = func.evaluate( ObjectiveFunction::CALCULATE, mPatch, value, OF_FREE_EVALS_ONLY, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );

    check_result( mPatch, power, value );
}

Definition at line 251 of file PMeanPTemplateTest.cpp.

References test_evaluate().

    {
        test_evaluate( 1 );
    }

Definition at line 255 of file PMeanPTemplateTest.cpp.

References test_evaluate().

    {
        test_evaluate( 2 );
    }

Definition at line 219 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        test_handles_qm_error( DIAG, &of );
    }

Definition at line 209 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        test_handles_qm_error( EVAL, &of );
    }

Definition at line 214 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        test_handles_qm_error( GRAD, &of );
    }

Definition at line 224 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        test_handles_qm_error( HESS, &of );
    }

Definition at line 240 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        test_handles_invalid_qm( DIAG, &of );
    }

Definition at line 230 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        test_handles_invalid_qm( EVAL, &of );
    }

Definition at line 235 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        test_handles_invalid_qm( GRAD, &of );
    }

Definition at line 245 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 1, NULL );
        test_handles_invalid_qm( HESS, &of );
    }

Definition at line 152 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::CALCULATE.

    {
        test_eval_type( GRAD, ObjectiveFunction::CALCULATE );
    }

Definition at line 156 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::SAVE.

    {
        test_eval_type( GRAD, ObjectiveFunction::SAVE );
    }

Definition at line 164 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::TEMPORARY.

    {
        test_eval_type( GRAD, ObjectiveFunction::TEMPORARY );
    }

Definition at line 160 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::UPDATE.

    {
        test_eval_type( GRAD, ObjectiveFunction::UPDATE );
    }
void PMeanPTemplateTest::test_gradient ( double  power) [private]

Definition at line 474 of file PMeanPTemplateTest.cpp.

References MBMesquite::arrptr(), MBMesquite::ObjectiveFunction::CALCULATE, CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::PMeanPTemplate::evaluate_with_gradient(), MBMesquite::grad(), MSQ_CHKERR, and value().

{
    MsqPrintError err( cout );
    double value;
    bool rval;
    vector< Vector3D > grad;

    DistTestMetric metric;
    PMeanPTemplate func( power, &metric );
    rval = func.evaluate_with_gradient( ObjectiveFunction::CALCULATE, mPatch, value, grad, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_EQUAL( mPatch.num_free_vertices(), grad.size() );

    if( !grad.empty() ) check_result( mPatch, power, value, arrptr( grad ) );
}

Definition at line 260 of file PMeanPTemplateTest.cpp.

    {
        test_gradient( 1 );
    }

Definition at line 264 of file PMeanPTemplateTest.cpp.

    {
        test_gradient( 2 );
    }

Definition at line 186 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::CALCULATE.

    {
        test_eval_type( HESS, ObjectiveFunction::CALCULATE );
    }

Definition at line 190 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::SAVE.

    {
        test_eval_type( HESS, ObjectiveFunction::SAVE );
    }

Definition at line 198 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::TEMPORARY.

    {
        test_eval_type( HESS, ObjectiveFunction::TEMPORARY );
    }

Definition at line 194 of file PMeanPTemplateTest.cpp.

References MBMesquite::ObjectiveFunction::UPDATE.

    {
        test_eval_type( HESS, ObjectiveFunction::UPDATE );
    }
void PMeanPTemplateTest::test_Hessian ( double  power) [private]

Definition at line 516 of file PMeanPTemplateTest.cpp.

References MBMesquite::arrptr(), MBMesquite::ObjectiveFunction::CALCULATE, CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, CPPUNIT_ASSERT_MATRICES_EQUAL, MBMesquite::EPSILON, MBMesquite::PMeanPTemplate::evaluate_with_Hessian(), MBMesquite::MsqHessian::get_block(), MBMesquite::grad(), MBMesquite::MsqHessian::initialize(), MSQ_CHKERR, n, MBMesquite::MsqHessian::size(), and value().

{
    MsqPrintError err( cout );
    double value;
    bool rval;
    vector< Vector3D > grad;
    MsqHessian Hess;
    Hess.initialize( mPatch, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );

    DistTestMetric metric;
    PMeanPTemplate func( power, &metric );
    rval = func.evaluate_with_Hessian( ObjectiveFunction::CALCULATE, mPatch, value, grad, Hess, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    size_t n = mPatch.num_free_vertices();
    CPPUNIT_ASSERT_EQUAL( n, grad.size() );
    CPPUNIT_ASSERT_EQUAL( n, Hess.size() );

    Matrix3D zero( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
    vector< Matrix3D > Hessians( n );
    for( size_t r = 0; r < n; ++r )
    {
        Matrix3D* mat = Hess.get_block( r, r );
        CPPUNIT_ASSERT( mat != 0 );
        Hessians[r] = *mat;

        for( size_t c = r + 1; c < n; ++c )
        {
            mat = Hess.get_block( r, c );
            if( mat ) CPPUNIT_ASSERT_MATRICES_EQUAL( zero, *mat, EPSILON );
        }
    }

    if( !grad.empty() ) check_result( mPatch, power, value, arrptr( grad ), arrptr( Hessians ) );
}

Definition at line 278 of file PMeanPTemplateTest.cpp.

    {
        test_Hessian( 1 );
    }

Definition at line 282 of file PMeanPTemplateTest.cpp.

    {
        test_Hessian( 2 );
    }

Definition at line 363 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 2, NULL );
        test_negate_flag( DIAG, &of );
    }

Definition at line 353 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 2, NULL );
        test_negate_flag( EVAL, &of );
    }

Definition at line 358 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 2, NULL );
        test_negate_flag( GRAD, &of );
    }

Definition at line 368 of file PMeanPTemplateTest.cpp.

    {
        PMeanPTemplate of( 2, NULL );
        test_negate_flag( HESS, &of );
    }

Member Data Documentation

Definition at line 126 of file PMeanPTemplateTest.cpp.

List of all members.


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