Changeset 484

Show
Ignore:
Timestamp:
08/07/09 09:57:52 (15 years ago)
Author:
vbarta
Message:

repeating failing mpdf tests; mpdf_harness configs now have optional cond (0 by default) and mandatory variance

Location:
library/tests
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • library/tests/epdf_harness.cpp

    r482 r484  
    142142 
    143143void epdf_harness::check_sample_mean() { 
    144         // simplify overloading for Visual Studio 
    145         vec delta = 2 * ( sqrt ( variance ) / sqrt ( static_cast<double> ( nsamples ) ) ); 
     144        vec delta = make_close_tolerance ( variance, nsamples ); 
    146145 
    147146        int tc = 0; 
     
    164163       } 
    165164} 
    166  
    167165 
    168166void epdf_harness::check_covariance() { 
     
    189187 
    190188void epdf_harness::check_cond_mean( mprod &mep ) { 
    191         // simplify overloading for Visual Studio 
    192         vec delta = 2 * ( sqrt ( variance ) / sqrt ( static_cast<double> ( nsamples ) ) ); 
     189        vec delta = make_close_tolerance ( variance, nsamples ); 
    193190 
    194191        int tc = 0; 
  • library/tests/mat_checks.h

    r481 r484  
    5151} 
    5252 
     53} 
     54 
     55/*! Constructs the multiple of standard deviation used for sample 
     56  tests (currently 2). */ 
     57inline itpp::vec make_close_tolerance ( const itpp::vec & variance, int nsamples ) { 
     58        // simplify overloading for Visual Studio 
     59        return 2 * ( sqrt ( variance ) / sqrt ( static_cast<double> ( nsamples ) ) ); 
    5360} 
    5461 
  • library/tests/mepdf.cfg

    r456 r484  
    1818  mean = [ 1.1, -1.0 ]; 
    1919  R = ( "matrix", 2, 2, [ 1.0, -0.5, -0.5, 2.0 ] ); 
    20   tolerance = 0.3; 
     20  tolerance = 0.1; 
     21  variance = [ 0.3, 0.3 ]; 
    2122} ); 
    2223 
  • library/tests/mgamma.cfg

    r456 r484  
    2020  mean = [ 1.5, 1.7 ]; 
    2121  R = ( "matrix", 2, 2, [ 2.25, 0.0, 0.0, 2.89 ] ); 
    22   tolerance = 0.5; 
     22  variance = [ 0.4, 0.4 ]; 
     23  tolerance = 0.4; 
    2324} ); 
    2425 
  • library/tests/mlnorm.cfg

    r462 r484  
    1212  R = ( "matrix", 2, 2, [ 1.26402, 0.378231, 0.378231, 5.15925 ] ); 
    1313  tolerance = 0.6; 
     14  variance = [ 0.2, 0.2 ]; 
    1415} ); 
    1516 
  • library/tests/mpdf_harness.cpp

    r480 r484  
    2828void mpdf_harness::from_setting ( const Setting &set ) { 
    2929        hmpdf = UI::build<mpdf> ( set, "mpdf", UI::compulsory ); 
    30         UI::get ( cond, set, "cond", UI::compulsory ); 
    3130        UI::get ( mean, set, "mean", UI::compulsory ); 
     31        UI::get ( variance, set, "variance", UI::compulsory ); 
     32 
     33        if ( !UI::get ( cond, set, "cond", UI::optional ) ) { 
     34                cond = zeros ( hmpdf->dimensionc() ); 
     35        } 
    3236 
    3337        UI::get ( nsamples, set, "nsamples", UI::optional ); 
     
    3842void mpdf_harness::test ( const char *config_name, int idx ) { 
    3943        CurrentContext cc ( config_name, idx ); 
    40  
    41         mat smp = hmpdf->samplecond_m ( cond, nsamples ); 
    42         int n = smp.cols(); 
    43         vec emu = smp * ones ( n ) / n; 
    44         mat er = ( smp * smp.T() ) / n - outer_product ( emu, emu ); 
    45         CHECK_CLOSE_EX ( mean, emu, tolerance ); 
    46  
     44        check_mean(); 
    4745        if ( R.rows() > 0 ) { 
    48                 CHECK_CLOSE_EX ( R, er, tolerance ); 
     46                check_covariance(); 
    4947        } 
    5048} 
    5149 
     50void mpdf_harness::check_mean() { 
     51        vec delta = make_close_tolerance ( variance, nsamples ); 
     52 
     53        int tc = 0; 
     54        Array<vec> actual(CurrentContext::max_trial_count); 
     55        do { 
     56                mat smp = hmpdf->samplecond_m ( cond, nsamples ); 
     57                vec emu = smp * ones ( nsamples ) / nsamples; 
     58                actual( tc ) = emu; 
     59                ++tc; 
     60        } while ( ( tc < CurrentContext::max_trial_count ) && 
     61                  !UnitTest::AreClose ( mean, actual( tc - 1 ), delta ) ); 
     62        if ( ( tc == CurrentContext::max_trial_count ) && 
     63             ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), delta ) ) ) { 
     64                UnitTest::MemoryOutStream stream; 
     65                stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << delta << " but was " << actual; 
     66 
     67                UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); 
     68 
     69                UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
     70       } 
    5271} 
     72 
     73void mpdf_harness::check_covariance() { 
     74        int tc = 0; 
     75        Array<mat> actual(CurrentContext::max_trial_count); 
     76        do { 
     77                mat smp = hmpdf->samplecond_m ( cond, nsamples ); 
     78                vec emu = smp * ones ( nsamples ) / nsamples; 
     79                mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 
     80                actual( tc ) = er; 
     81                ++tc; 
     82        } while ( ( tc < CurrentContext::max_trial_count ) && 
     83                  !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) ); 
     84        if ( ( tc == CurrentContext::max_trial_count ) && 
     85             ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
     86                UnitTest::MemoryOutStream stream; 
     87                stream << CurrentContext::format_context(__LINE__) << "expected " << R << " +/- " << tolerance << " but was " << actual; 
     88 
     89                UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); 
     90 
     91                UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
     92       } 
     93} 
     94 
     95} 
  • library/tests/mpdf_harness.h

    r477 r484  
    2929        vec cond; 
    3030        vec mean; 
     31        vec variance; 
    3132        int nsamples; 
    3233        mat R; 
     
    4647                return hmpdf.get(); 
    4748        } 
     49 
     50private: 
     51        void check_mean(); 
     52 
     53        // assumes R is valid 
     54        void check_covariance(); 
    4855}; 
    4956 
  • library/tests/testsuite.cpp

    r477 r484  
    11#include "UnitTest++.h" 
    22#include "itpp_ext.h" 
     3#include <iostream> 
     4#include <iomanip> 
    35 
    46int main ( int, char const *[] ) { 
    57        itpp::RNG_randomize(); 
    6         return UnitTest::RunAllTests(); 
     8        try { 
     9          return UnitTest::RunAllTests(); 
     10        } catch ( std::exception const& e ) { 
     11          std::cerr << e.what() << std::endl; 
     12          return -1; 
     13        } 
    714}