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

Public Member Functions

 CompositeOFTest ()
void test_add_value ()
void test_multiply_value ()
void test_scalar_add_value ()
void test_scalar_multiply_value ()
void test_add_gradient ()
void test_multiply_gradient ()
void test_scalar_add_gradient ()
void test_scalar_multiply_gradient ()
void test_add_hess_diagonal ()
void test_multiply_hess_diagonal ()
void test_scalar_add_hess_diagonal ()
void test_scalar_multiply_hess_diagonal ()
void test_add_hessian ()
void test_multiply_hessian ()
void test_scalar_add_hessian ()
void test_scalar_multiply_hessian ()
void test_clone_add ()
void test_clone_multiply ()
void test_clone_scalar_add ()
void test_clone_scalar_multiply ()
void test_add_invalid ()
void test_multiply_invalid ()
void test_scalar_add_invalid ()
void test_scalar_multiply_invalid ()
void test_add_error ()
void test_multiply_error ()
void test_scalar_add_error ()
void test_scalar_multiply_error ()
void test_evaluate (double expected_value, ObjectiveFunction &of)
void get_hessians (MsqHessian &LP1_hess, MsqHessian &LP2_hess, ObjectiveFunction &OF, MsqHessian &OF_hess)
void test_composite_clone (ObjectiveFunction &of)
void test_invalid_eval (ObjectiveFunction &of)
void test_eval_fails (ObjectiveFunction &of)

Private Member Functions

 CPPUNIT_TEST_SUITE (CompositeOFTest)
 CPPUNIT_TEST (test_add_value)
 CPPUNIT_TEST (test_multiply_value)
 CPPUNIT_TEST (test_scalar_add_value)
 CPPUNIT_TEST (test_scalar_multiply_value)
 CPPUNIT_TEST (test_add_gradient)
 CPPUNIT_TEST (test_multiply_gradient)
 CPPUNIT_TEST (test_scalar_add_gradient)
 CPPUNIT_TEST (test_scalar_multiply_gradient)
 CPPUNIT_TEST (test_add_hess_diagonal)
 CPPUNIT_TEST (test_multiply_hess_diagonal)
 CPPUNIT_TEST (test_scalar_add_hess_diagonal)
 CPPUNIT_TEST (test_scalar_multiply_hess_diagonal)
 CPPUNIT_TEST (test_add_hessian)
 CPPUNIT_TEST (test_multiply_hessian)
 CPPUNIT_TEST (test_scalar_add_hessian)
 CPPUNIT_TEST (test_scalar_multiply_hessian)
 CPPUNIT_TEST (test_clone_add)
 CPPUNIT_TEST (test_clone_multiply)
 CPPUNIT_TEST (test_clone_scalar_add)
 CPPUNIT_TEST (test_clone_scalar_multiply)
 CPPUNIT_TEST (test_add_invalid)
 CPPUNIT_TEST (test_multiply_invalid)
 CPPUNIT_TEST (test_scalar_add_invalid)
 CPPUNIT_TEST (test_scalar_multiply_invalid)
 CPPUNIT_TEST (test_add_error)
 CPPUNIT_TEST (test_multiply_error)
 CPPUNIT_TEST (test_scalar_add_error)
 CPPUNIT_TEST (test_scalar_multiply_error)
 CPPUNIT_TEST_SUITE_END ()

Private Attributes

FauxObjectiveFunction OF1
FauxObjectiveFunction OF2
FauxObjectiveFunction OF3
FauxObjectiveFunction OF4
FauxObjectiveFunction invalidOF
FauxObjectiveFunction errorOF
IdealWeightInverseMeanRatio metric
LPtoPTemplate LP1
LPtoPTemplate LP2

Detailed Description

Definition at line 106 of file CompositeOFTest.cpp.


Constructor & Destructor Documentation

Definition at line 153 of file CompositeOFTest.cpp.

        : OF1( 1.0 ), OF2( 3.0 ), OF3( -7.0 ), OF4( M_PI ), invalidOF( 1.0, true, false ), errorOF( 1.0, false, true ),
          LP1( 1, &metric ), LP2( 2, &metric )
    {
    }

Member Function Documentation

void CompositeOFTest::get_hessians ( MsqHessian LP1_hess,
MsqHessian LP2_hess,
ObjectiveFunction OF,
MsqHessian OF_hess 
)

Definition at line 271 of file CompositeOFTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::ObjectiveFunction::CALCULATE, CPPUNIT_ASSERT, MBMesquite::create_twelve_hex_patch(), MBMesquite::ObjectiveFunction::evaluate_with_Hessian(), MBMesquite::grad(), MBMesquite::MsqHessian::initialize(), and value().

{
    MsqPrintError err( cout );
    PatchData pd;
    create_twelve_hex_patch( pd, err );
    ASSERT_NO_ERROR( err );

    LP1_hess.initialize( pd, err );
    ASSERT_NO_ERROR( err );
    LP2_hess.initialize( pd, err );
    ASSERT_NO_ERROR( err );
    OF_hess.initialize( pd, err );
    ASSERT_NO_ERROR( err );

    std::vector< Vector3D > grad;
    bool rval;
    double value;
    rval = LP1.evaluate_with_Hessian( ObjectiveFunction::CALCULATE, pd, value, grad, LP1_hess, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( rval );
    rval = LP2.evaluate_with_Hessian( ObjectiveFunction::CALCULATE, pd, value, grad, LP2_hess, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( rval );
    rval = OF.evaluate_with_Hessian( ObjectiveFunction::CALCULATE, pd, value, grad, OF_hess, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( rval );
}

Definition at line 557 of file CompositeOFTest.cpp.

{
    CompositeOFAdd add1( &OF1, &errorOF );
    test_eval_fails( add1 );

    CompositeOFAdd add2( &errorOF, &OF3 );
    test_eval_fails( add2 );
}

Definition at line 368 of file CompositeOFTest.cpp.

References b, b1, b2, CPPUNIT_ASSERT_MATRICES_EQUAL, MBMesquite::MsqHessian::get_block(), MBMesquite::hess(), and MBMesquite::MsqHessian::size().

{
    // test value and gradient
    CompositeOFAdd OF( &LP1, &LP2 );
    compare_hessian_gradient( &OF );

    // test actual hessian values
    MsqHessian hess1, hess2, hess;
    get_hessians( hess1, hess2, OF, hess );
    Matrix3D *b1, *b2, *b;
    for( unsigned r = 0; r < hess.size(); ++r )
    {
        for( unsigned c = r; c < hess.size(); ++c )
        {
            b1 = hess1.get_block( r, c );
            b2 = hess2.get_block( r, c );
            b  = hess.get_block( r, c );
            if( b )
            {
                CPPUNIT_ASSERT_MATRICES_EQUAL( *b1 + *b2, *b, 1e-6 );
            }
        }
    }
}

Definition at line 527 of file CompositeOFTest.cpp.

Definition at line 214 of file CompositeOFTest.cpp.

References test_evaluate().

{
    CompositeOFAdd add1( &OF1, &OF2 );
    test_evaluate( OF1.get_value() + OF2.get_value(), add1 );

    CompositeOFAdd add2( &OF3, &OF4 );
    test_evaluate( OF3.get_value() + OF4.get_value(), add2 );
}

Definition at line 488 of file CompositeOFTest.cpp.

Definition at line 460 of file CompositeOFTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::ObjectiveFunction::CALCULATE, MBMesquite::ObjectiveFunction::clone(), CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, MBMesquite::ObjectiveFunction::evaluate(), and FauxObjectiveFunction::get_instance_count().

{
    // save current count of instances of underlying OFs for later
    const int init_count = FauxObjectiveFunction::get_instance_count();

    // clone the objective function
    ObjectiveFunction* clone = OF.clone();

    // check that the underlying OFs were also cloned
    CPPUNIT_ASSERT( init_count < FauxObjectiveFunction::get_instance_count() );

    // check that the value is the same
    MsqPrintError err( cout );
    double orig_val, clone_val;
    bool rval;
    rval = OF.evaluate( ObjectiveFunction::CALCULATE, patch(), orig_val, false, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( rval );
    rval = clone->evaluate( ObjectiveFunction::CALCULATE, patch(), clone_val, false, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( orig_val, clone_val, 1e-6 );

    // check that cloned instances of underlying OFs are deleted
    delete clone;
    CPPUNIT_ASSERT_EQUAL( init_count, FauxObjectiveFunction::get_instance_count() );
}
void CompositeOFTest::test_evaluate ( double  expected_value,
ObjectiveFunction of 
)

Definition at line 204 of file CompositeOFTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::ObjectiveFunction::CALCULATE, CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, MBMesquite::ObjectiveFunction::evaluate(), and value().

{
    MsqPrintError err( cout );
    double value;
    bool rval = OF.evaluate( ObjectiveFunction::CALCULATE, patch(), value, false, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( expected, value, 1e-6 );
}

Definition at line 509 of file CompositeOFTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::ObjectiveFunction::CALCULATE, CPPUNIT_ASSERT, MBMesquite::ObjectiveFunction::evaluate(), and value().

{
    MsqPrintError err( cout );
    bool rval;
    double value;
    rval = OF.evaluate( ObjectiveFunction::CALCULATE, patch(), value, false, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( rval == false );
}

Definition at line 566 of file CompositeOFTest.cpp.

Definition at line 308 of file CompositeOFTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::ObjectiveFunction::CALCULATE, CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, CPPUNIT_ASSERT_MATRICES_EQUAL, CPPUNIT_ASSERT_VECTORS_EQUAL, MBMesquite::create_twelve_hex_patch(), MBMesquite::CompositeOFMultiply::evaluate_with_Hessian_diagonal(), MBMesquite::grad(), MBMesquite::hess(), MBMesquite::PatchData::num_free_vertices(), MBMesquite::Matrix3D::outer_product(), MBMesquite::transpose(), and value().

{
    CompositeOFMultiply OF( &LP1, &LP2 );
    std::vector< SymMatrix3D > hess1, hess2, hess;

    MsqPrintError err( cout );
    PatchData pd;
    create_twelve_hex_patch( pd, err );
    ASSERT_NO_ERROR( err );

    std::vector< Vector3D > grad1, grad2, grad;
    bool rval;
    double value1, value2, value;
    rval = LP1.evaluate_with_Hessian_diagonal( ObjectiveFunction::CALCULATE, pd, value1, grad1, hess1, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( rval );
    rval = LP2.evaluate_with_Hessian_diagonal( ObjectiveFunction::CALCULATE, pd, value2, grad2, hess2, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( rval );
    rval = OF.evaluate_with_Hessian_diagonal( ObjectiveFunction::CALCULATE, pd, value, grad, hess, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( rval );

    CPPUNIT_ASSERT_EQUAL( pd.num_free_vertices(), grad1.size() );
    CPPUNIT_ASSERT_EQUAL( pd.num_free_vertices(), grad2.size() );
    CPPUNIT_ASSERT_EQUAL( pd.num_free_vertices(), grad.size() );

    CPPUNIT_ASSERT_EQUAL( pd.num_free_vertices(), hess1.size() );
    CPPUNIT_ASSERT_EQUAL( pd.num_free_vertices(), hess2.size() );
    CPPUNIT_ASSERT_EQUAL( pd.num_free_vertices(), hess.size() );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( value1 * value2, value, 1e-6 );

    for( size_t i = 0; i < pd.num_free_vertices(); ++i )
    {
        const Vector3D expected_grad = value2 * grad1[i] + value1 * grad2[i];
        CPPUNIT_ASSERT_VECTORS_EQUAL( expected_grad, grad[i], 1e-6 );

        Matrix3D o;
        o.outer_product( grad1[i], grad2[i] );
        Matrix3D expect = o + transpose( o );
        expect += value2 * hess1[i];
        expect += value1 * hess2[i];
        CPPUNIT_ASSERT_MATRICES_EQUAL( expect, Matrix3D( hess[i] ), 1e-6 );
    }
}

Definition at line 393 of file CompositeOFTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::ObjectiveFunction::CALCULATE, CPPUNIT_ASSERT, MBMesquite::create_twelve_hex_patch(), MBMesquite::CompositeOFMultiply::evaluate_with_Hessian(), MBMesquite::grad(), MBMesquite::hess(), MBMesquite::MsqHessian::initialize(), and value().

{
    MsqError err;
    PatchData pd;
    create_twelve_hex_patch( pd, err );
    ASSERT_NO_ERROR( err );

    // this should always fail because the Hessian is not sparse
    CompositeOFMultiply OF( &LP1, &LP2 );
    double value;
    MsqHessian hess;
    hess.initialize( pd, err );
    ASSERT_NO_ERROR( err );
    std::vector< Vector3D > grad;
    OF.evaluate_with_Hessian( ObjectiveFunction::CALCULATE, pd, value, grad, hess, err );
    CPPUNIT_ASSERT( err );
}

Definition at line 223 of file CompositeOFTest.cpp.

References test_evaluate().

Definition at line 575 of file CompositeOFTest.cpp.

Definition at line 411 of file CompositeOFTest.cpp.

References b, b1, CPPUNIT_ASSERT_MATRICES_EQUAL, MBMesquite::MsqHessian::get_block(), MBMesquite::hess(), and MBMesquite::MsqHessian::size().

{
    // test value and gradient
    CompositeOFScalarAdd OF( 1111.1, &LP1 );
    compare_hessian_gradient( &OF );

    // test actual hessian values
    MsqHessian hess1, hess2, hess;
    get_hessians( hess1, hess2, OF, hess );
    Matrix3D *b1, *b;
    for( unsigned r = 0; r < hess.size(); ++r )
    {
        for( unsigned c = r; c < hess.size(); ++c )
        {
            b1 = hess1.get_block( r, c );
            b  = hess.get_block( r, c );
            if( b )
            {
                CPPUNIT_ASSERT_MATRICES_EQUAL( *b1, *b, 1e-6 );
            }
        }
    }
}

Definition at line 232 of file CompositeOFTest.cpp.

References test_evaluate().

{
    CompositeOFScalarAdd add1( sqrt( 2.0 ), &OF1 );
    test_evaluate( OF1.get_value() + sqrt( 2.0 ), add1 );

    CompositeOFScalarAdd add2( -1.0, &OF4 );
    test_evaluate( OF4.get_value() - 1, add2 );
}

Definition at line 361 of file CompositeOFTest.cpp.

References scale().

{
    const double scale = 2.5;
    CompositeOFScalarMultiply OF( scale, &LP1 );
    compare_hessian_diagonal( &OF );
}

Definition at line 435 of file CompositeOFTest.cpp.

References b, b1, CPPUNIT_ASSERT_MATRICES_EQUAL, MBMesquite::MsqHessian::get_block(), MBMesquite::hess(), scale(), and MBMesquite::MsqHessian::size().

{
    // test value and gradient
    const double scale = 2.5;
    CompositeOFScalarMultiply OF( scale, &LP1 );
    compare_hessian_gradient( &OF );

    // test actual hessian values
    MsqHessian hess1, hess2, hess;
    get_hessians( hess1, hess2, OF, hess );
    Matrix3D *b1, *b;
    for( unsigned r = 0; r < hess.size(); ++r )
    {
        for( unsigned c = r; c < hess.size(); ++c )
        {
            b1 = hess1.get_block( r, c );
            b  = hess.get_block( r, c );
            if( b )
            {
                CPPUNIT_ASSERT_MATRICES_EQUAL( scale * *b1, *b, 1e-6 );
            }
        }
    }
}

Definition at line 241 of file CompositeOFTest.cpp.

References test_evaluate().

{
    CompositeOFScalarMultiply mult1( sqrt( 2.0 ), &OF1 );
    test_evaluate( OF1.get_value() * sqrt( 2.0 ), mult1 );

    CompositeOFScalarMultiply mult2( -1.0, &OF4 );
    test_evaluate( -OF4.get_value(), mult2 );
}

Member Data Documentation

Definition at line 150 of file CompositeOFTest.cpp.

Definition at line 150 of file CompositeOFTest.cpp.

Definition at line 148 of file CompositeOFTest.cpp.

Definition at line 148 of file CompositeOFTest.cpp.

Definition at line 148 of file CompositeOFTest.cpp.

Definition at line 148 of file CompositeOFTest.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