Changeset 716

Show
Ignore:
Timestamp:
11/11/09 22:58:25 (14 years ago)
Author:
mido
Message:

clean up within testsuite - pdf_harness is used even in the case of emix and mmix test

Location:
library
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/stat/emix.h

    r715 r716  
    209209        //!@} 
    210210        void from_setting ( const Setting &set ) { 
    211                 UI::get ( Coms, set, "pdfs", UI::compulsory ); 
    212  
    213                 if( !UI::get( w, set, "weights", UI::optional ) ) 
     211         
     212                vec w0;                  
     213                Array<shared_ptr<epdf> > Coms0; 
     214         
     215                UI::get ( Coms0, set, "pdfs", UI::compulsory ); 
     216 
     217                if( !UI::get( w0, set, "weights", UI::optional ) ) 
    214218                { 
    215219                        int len = Coms.length(); 
    216                         w.set_length( len ); 
    217                         w = 1.0 / len; 
    218                 } 
     220                        w0.set_length( len ); 
     221                        w0 = 1.0 / len; 
     222                } 
     223 
     224                // TODO asi lze nacitat primocare do w a coms, jen co bude hotovy validate() 
     225                set_parameters( w0, Coms0 ); 
    219226        } 
    220227}; 
     
    527534        //!@} 
    528535        void from_setting ( const Setting &set ) { 
    529                 UI::get ( Coms, set, "pdfs", UI::compulsory ); 
     536                UI::get ( Coms, set, "pdfs", UI::compulsory );   
     537 
     538                // TODO ma byt zde, ci ve validate()? 
     539                if (Coms.length()>0){ 
     540                        set_rv(Coms(0)->_rv()); 
     541                        dim = rv._dsize(); 
     542                        set_rvc(Coms(0)->_rvc()); 
     543                        dimc = rvc._dsize(); 
     544                } 
    530545 
    531546                if( !UI::get( w, set, "weights", UI::optional ) ) 
  • library/tests/emix.cfg

    r713 r716  
    11data = ( 
    22{ 
    3   class = "pdf_harness"; 
    4   pdf = { 
     3   class = "pdf_harness"; 
     4   pdf = { 
    55    class = "emix"; 
    66    pdfs = (  
    77    { 
     8                class = "egamma"; 
     9                alpha = [ 100000, 10000 ]; 
     10                beta = [ 10000, 1000 ];  
     11        }, 
     12    { 
    813                class = "enorm<ldmat>"; 
    9                 mu = [ 1.5 1.7 ]; 
    10                 R = ( "matrix", 2, 2, [ 1.2, 0.3, 0.3, 5 ] ); 
    11     }, 
    12     { 
    13                 class = "egamma"; 
    14                 alpha = [ 100000 10000 ]; 
    15                 beta = [ 10000 1000 ];   
     14                mu = [ 1.5, 1.7 ]; 
     15                R = ( "matrix", 2, 2, [ 1.2, 0.3, 0.3, 5.0 ] );          
    1616    }); 
    1717    weights = [ 0.5, 0.5 ]; 
    1818  }; 
    19   mean = [ 1.5 1.7 ]; 
    20   R = ( "matrix", 2, 2, [ 1.27572, 0.778247, 0.778247, 3.33129 ] ); 
    21 # TODO CO S TIM? R, variance 
     19  mean = [ 5.75, 5.85 ]; 
    2220  variance = [ 1.2, 5.0 ]; 
    23   tolerance = 0.1; 
     21  tolerance = 0.2; 
    2422}); 
    25  
  • library/tests/mmix.cfg

    r711 r716  
    66    pdfs = (  
    77    { 
    8                 class = "enorm<ldmat>"; 
    9                 mu = [ 0, 0 ]; 
    10                 R = ( "matrix", 2, 2, [ 1.2, 0.3, 0.3, 5 ] ); 
    11     }, 
    12     { 
    138                class = "mgamma"; 
    14                 beta = [ 1.5 1.7 ];              
     9                beta = [ 1.5, 1.7 ];             
    1510                k = 10.0;                                        
    1611                rv :  
     
    2621                        sizes = 2; 
    2722                }; 
    28     }); 
     23    }, 
     24    { 
     25                class = "enorm<ldmat>"; 
     26                mu = [ 0, 0 ]; 
     27                R = ( "matrix", 2, 2, [ 1.2, 0.3, 0.3, 5.0 ] ); 
     28    }     
     29        ); 
    2930    weights = [ 0.5, 0.5 ]; 
    3031  }; 
     32  cond = [ 1.5, 1.7 ]; 
    3133  mean = [ 0.75, 0.85 ]; 
    3234  R = ( "matrix", 2, 2, [ 1.27572, 0.778247, 0.778247, 3.33129 ] ); 
     
    3436  tolerance = 0.2; 
    3537}); 
    36  
  • library/tests/pdf_test.cpp

    r713 r716  
    2727TEST ( mmix_test ) { 
    2828        pdf_harness::test_config ( "mmix.cfg" ); 
    29         //vec tmu = 0.5 * eN->mean() + 0.5 * mu0; 
    30  
    31         /* 
    32         RV x ( "{mmixx }", "2" ); 
    33         RV y ( "{mmixy }", "2" ); 
    34         int N = 10000; //number of samples 
    35         vec mu0 ( "1.5 1.7" ); 
    36         mat V0 ( "1.2 0.3; 0.3 5" ); 
    37         ldmat R = ldmat ( V0 ); 
    38  
    39         enorm_ldmat_ptr eN; 
    40         eN->set_parameters ( mu0, R ); 
    41  
    42         mgamma_ptr mG; 
    43         double k = 10.0; 
    44         mG->set_parameters ( k, mu0 ); 
    45  
    46         mmix mMix; 
    47         pdf_array mComs ( 2 ); 
    48  
    49         // mmix::set_parameters requires the first pdf to be named 
    50         mG->set_rv(x); 
    51         mG->set_rvc(y); 
    52         mComs ( 0 ) = mG; 
    53  
    54         eN->set_mu ( vec_2 ( 0.0, 0.0 ) ); 
    55         mComs ( 1 ) = eN; 
    56  
    57         mMix.set_parameters ( vec_2 ( 0.5, 0.5 ), mComs ); 
    58  
    59         vec tmu = 0.5 * eN->mean() + 0.5 * mu0; 
    60         check_mean ( mMix, mu0, N, tmu, 0.1 ); 
    61  
    62         mat observedR ( "1.27572 0.778247; 0.778247 3.33129" ); 
    63         check_covariance( mMix, mu0, N, observedR, 0.2 ); 
    64 */ 
    6529} 
    6630 
    67 // not using pdf_harness because emix isn't configurable (yet?) 
    6831TEST ( emix_test ) { 
    6932        pdf_harness::test_config ( "emix.cfg" ); 
    70         /* 
    71         int N = 10000; //number of samples 
    72         vec mu0 ( "1.5 1.7" ); 
    73         mat V0 ( "1.2 0.3; 0.3 5" ); 
    74         ldmat R = ldmat ( V0 ); 
    75  
    76         enorm_ldmat_ptr eN; 
    77         eN->set_parameters ( mu0, R ); 
    78  
    79         vec a = "100000,10000"; 
    80         vec b = a / 10.0; 
    81         egamma_ptr eG; 
    82         eG->set_parameters ( a, b ); 
    83  
    84         emix_ptr eMix; 
    85         epdf_array Coms ( 2 ); 
    86         Coms ( 0 ) = eG; 
    87         Coms ( 1 ) = eN; 
    88  
    89         eMix->set_parameters ( vec_2 ( 0.5, 0.5 ), Coms ); 
    90         check_mean ( *eMix, mu0, N, eMix->mean(), 0.1 ); 
    91         */ 
    9233} 
    93  
    94 static void check_mean(pdf &distrib_obj, const vec &mu0, int nsamples, const vec &mean, double tolerance) { 
    95         int tc = 0; 
    96         Array<vec> actual(CurrentContext::max_trial_count); 
    97         do { 
    98                 mat smp = distrib_obj.samplecond_mat ( mu0, nsamples ); 
    99                 vec emu = smp * ones ( nsamples ) / nsamples ; 
    100                 actual( tc ) = emu; 
    101                 ++tc; 
    102         } while ( ( tc < CurrentContext::max_trial_count ) && 
    103                   !UnitTest::AreClose ( mean, actual( tc - 1 ), tolerance ) ); 
    104         if ( ( tc == CurrentContext::max_trial_count ) && 
    105              ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
    106                 UnitTest::MemoryOutStream stream; 
    107                 UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), __LINE__); 
    108                 stream << "Expected " << mean << " +/- " << tolerance << " but was " << actual; 
    109  
    110                 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
    111         } 
    112 } 
    113  
    114 static void check_covariance(mmix &distrib_obj, const vec &mu0, int nsamples, const mat &R, double tolerance) { 
    115         int tc = 0; 
    116         Array<mat> actual(CurrentContext::max_trial_count); 
    117         do { 
    118                 mat smp = distrib_obj.samplecond_mat ( mu0, nsamples ); 
    119                 vec emu = smp * ones ( nsamples ) / nsamples ; 
    120                 mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 
    121                 actual( tc ) = er; 
    122                 ++tc; 
    123         } while ( ( tc < CurrentContext::max_trial_count ) && 
    124                   !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) ); 
    125         if ( ( tc == CurrentContext::max_trial_count ) && 
    126              ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
    127                 UnitTest::MemoryOutStream stream; 
    128                 UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), __LINE__); 
    129                 stream << "Expected " << R << " +/- " << tolerance << " but was " << actual; 
    130  
    131                 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
    132        } 
    133 }