Changeset 713

Show
Ignore:
Timestamp:
11/10/09 11:03:09 (14 years ago)
Author:
mido
Message:

_m changed to _mat

emix.cfg prepared, but it is not yet debugged!

Location:
library
Files:
1 added
15 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/bdmbase.cpp

    r700 r713  
    156156} 
    157157 
    158 mat epdf::sample_m ( int N ) const { 
     158mat epdf::sample_mat ( int N ) const { 
    159159        mat X = zeros ( dim, N ); 
    160160        for ( int i = 0; i < N; i++ ) X.set_col ( i, this->sample() ); 
     
    162162} 
    163163 
    164 vec epdf::evallog_m ( const mat &Val ) const { 
     164vec epdf::evallog_mat ( const mat &Val ) const { 
    165165        vec x ( Val.cols() ); 
    166166        for ( int i = 0; i < Val.cols(); i++ ) { 
     
    171171} 
    172172 
    173 vec epdf::evallog_m ( const Array<vec> &Avec ) const { 
     173vec epdf::evallog_mat ( const Array<vec> &Avec ) const { 
    174174        vec x ( Avec.size() ); 
    175175        for ( int i = 0; i < Avec.size(); i++ ) { 
     
    180180} 
    181181 
    182 mat pdf::samplecond_m ( const vec &cond, int N ) { 
     182mat pdf::samplecond_mat ( const vec &cond, int N ) { 
    183183        mat M ( dimension(), N ); 
    184184        for ( int i = 0; i < N; i++ ) { 
  • library/bdm/base/bdmbase.h

    r712 r713  
    429429 
    430430        //! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv 
    431         virtual mat samplecond_m ( const vec &cond, int N ); 
     431        virtual mat samplecond_mat ( const vec &cond, int N ); 
    432432 
    433433        //! Shortcut for conditioning and evaluation of the internal epdf. In some cases,  this operation can be implemented efficiently. 
     
    438438 
    439439        //! Matrix version of evallogcond 
    440         virtual vec evallogcond_m ( const mat &Yt, const vec &cond ) { 
     440        virtual vec evallogcond_mat ( const mat &Yt, const vec &cond ) { 
    441441                vec v ( Yt.cols() ); 
    442442                for ( int i = 0; i < Yt.cols(); i++ ) { 
     
    447447 
    448448        //! Array<vec> version of evallogcond 
    449         virtual vec evallogcond_m ( const Array<vec> &Yt, const vec &cond ) { 
     449        virtual vec evallogcond_mat ( const Array<vec> &Yt, const vec &cond ) { 
    450450                bdm_error ( "Not implemented" ); 
    451451                return vec(); 
     
    534534 
    535535        //! Returns N samples, \f$ [x_1 , x_2 , \ldots \ \f$  from density \f$ f_x(rv)\f$ 
    536         virtual mat sample_m ( int N ) const; 
     536        virtual mat sample_mat ( int N ) const; 
    537537 
    538538        //! Compute log-probability of argument \c val 
     
    544544 
    545545        //! Compute log-probability of multiple values argument \c val 
    546         virtual vec evallog_m ( const mat &Val ) const; 
     546        virtual vec evallog_mat ( const mat &Val ) const; 
    547547 
    548548        //! Compute log-probability of multiple values argument \c val 
    549         virtual vec evallog_m ( const Array<vec> &Avec ) const; 
     549        virtual vec evallog_mat ( const Array<vec> &Avec ) const; 
    550550 
    551551        //! Return conditional density on the given RV, the remaining rvs will be in conditioning 
     
    669669        double evallogcond ( const vec &val, const vec &cond ); 
    670670        //! Efficient version of evallogcond for matrices 
    671         virtual vec evallogcond_m ( const mat &Dt, const vec &cond ); 
     671        virtual vec evallogcond_mat ( const mat &Dt, const vec &cond ); 
    672672        //! Efficient version of evallogcond for Array<vec> 
    673         virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ); 
     673        virtual vec evallogcond_mat ( const Array<vec> &Dt, const vec &cond ); 
    674674        //! Efficient version of samplecond 
    675         virtual mat samplecond_m ( const vec &cond, int N ); 
     675        virtual mat samplecond_mat ( const vec &cond, int N ); 
    676676         
    677677        void validate() { 
     
    11171117 
    11181118        //! Matrix version of logpred 
    1119         vec logpred_m ( const mat &Yt ) const { 
     1119        vec logpred_mat ( const mat &Yt ) const { 
    11201120                vec tmp ( Yt.cols() ); 
    11211121                for ( int i = 0; i < Yt.cols(); i++ ) { 
     
    12531253 
    12541254template<class EPDF> 
    1255 mat pdf_internal<EPDF>::samplecond_m ( const vec &cond, int N ) { 
     1255mat pdf_internal<EPDF>::samplecond_mat ( const vec &cond, int N ) { 
    12561256        condition ( cond ); 
    12571257        mat temp ( dimension(), N ); 
     
    12741274 
    12751275template<class EPDF> 
    1276 vec pdf_internal<EPDF>::evallogcond_m ( const mat &Yt, const vec &cond ) { 
     1276vec pdf_internal<EPDF>::evallogcond_mat ( const mat &Yt, const vec &cond ) { 
    12771277        condition ( cond ); 
    1278         return iepdf.evallog_m ( Yt ); 
     1278        return iepdf.evallog_mat ( Yt ); 
    12791279} 
    12801280 
    12811281template<class EPDF> 
    1282 vec pdf_internal<EPDF>::evallogcond_m ( const Array<vec> &Yt, const vec &cond ) { 
     1282vec pdf_internal<EPDF>::evallogcond_mat ( const Array<vec> &Yt, const vec &cond ) { 
    12831283        condition ( cond ); 
    1284         return iepdf.evallog_m ( Yt ); 
     1284        return iepdf.evallog_mat ( Yt ); 
    12851285} 
    12861286 
  • library/bdm/stat/emix.h

    r711 r713  
    159159                return tmp; 
    160160        }; 
    161         vec evallog_m ( const mat &Val ) const { 
     161        vec evallog_mat ( const mat &Val ) const { 
    162162                vec x = zeros ( Val.cols() ); 
    163163                for ( int i = 0; i < w.length(); i++ ) { 
    164                         x += w ( i ) * exp ( Coms ( i )->evallog_m ( Val ) ); 
     164                        x += w ( i ) * exp ( Coms ( i )->evallog_mat ( Val ) ); 
    165165                } 
    166166                return log ( x ); 
    167167        }; 
     168        /* 
    168169        //! Auxiliary function that returns pdflog for each component 
    169         mat evallog_M ( const mat &Val ) const { 
     170        mat evallog_mat ( const mat &Val ) const { 
    170171                mat X ( w.length(), Val.cols() ); 
    171172                for ( int i = 0; i < w.length(); i++ ) { 
    172                         X.set_row ( i, w ( i ) *exp ( Coms ( i )->evallog_m ( Val ) ) ); 
     173                        X.set_row ( i, w ( i ) *exp ( Coms ( i )->evallog_mat ( Val ) ) ); 
    173174                } 
    174175                return X; 
    175176        }; 
     177        */ 
    176178 
    177179        shared_ptr<epdf> marginal ( const RV &rv ) const; 
     
    180182        shared_ptr<pdf> condition ( const RV &rv ) const; 
    181183 
    182 //Access methods 
     184        //Access methods 
    183185        //! returns a pointer to the internal mean value. Use with Care! 
    184186        vec& _w() { 
     
    197199                } 
    198200        } 
     201 
     202        //! Load from structure with elements: 
     203        //!  \code 
     204        //! { class='emix'; 
     205        //!   pdfs = (..., ...);     // list of pdfs in the mixture 
     206        //!   weights = ( 0.5, 0.5 ); // weights of pdfs in the mixture 
     207        //! } 
     208        //! \endcode 
     209        //!@} 
     210        void from_setting ( const Setting &set ) { 
     211                UI::get ( Coms, set, "pdfs", UI::compulsory ); 
     212 
     213                if( !UI::get( w, set, "weights", UI::optional ) ) 
     214                { 
     215                        int len = Coms.length(); 
     216                        w.set_length( len ); 
     217                        double default_weight = 1.0 / len; 
     218                        for( int i=0; i < len; i++) 
     219                                w(i) = default_weight; 
     220                } 
     221        } 
    199222}; 
    200223SHAREDPTR( emix ); 
     224UIREGISTER ( emix ); 
    201225 
    202226/*! 
     
    322346                return res; 
    323347        } 
    324         vec evallogcond_m ( const mat &Dt, const vec &cond ) { 
     348        vec evallogcond_mat ( const mat &Dt, const vec &cond ) { 
    325349                vec tmp ( Dt.cols() ); 
    326350                for ( int i = 0; i < Dt.cols(); i++ ) { 
     
    329353                return tmp; 
    330354        }; 
    331         vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ) { 
     355        vec evallogcond_mat ( const Array<vec> &Dt, const vec &cond ) { 
    332356                vec tmp ( Dt.length() ); 
    333357                for ( int i = 0; i < Dt.length(); i++ ) { 
  • library/bdm/stat/exp_family.h

    r693 r713  
    5858                } 
    5959                //!Evaluate normalized log-probability for many samples 
    60                 virtual vec evallog_m (const mat &Val) const { 
     60                virtual vec evallog_mat (const mat &Val) const { 
    6161                        vec x (Val.cols()); 
    6262                        for (int i = 0;i < Val.cols();i++) {x (i) = evallog_nn (Val.get_col (i)) ;} 
     
    6464                } 
    6565                //!Evaluate normalized log-probability for many samples 
    66                 virtual vec evallog_m (const Array<vec> &Val) const { 
     66                virtual vec evallog_mat (const Array<vec> &Val) const { 
    6767                        vec x (Val.length()); 
    6868                        for (int i = 0;i < Val.length();i++) {x (i) = evallog_nn (Val (i)) ;} 
  • library/bdm/stat/merger.cpp

    r693 r713  
    151151                        if ( pdfs ( i )->dimension() == dim ) { 
    152152                                // no need for conditioning or marginalization 
    153                                 lw_src = pdfs ( i )->evallogcond_m ( Smp , vec(0)); 
     153                                lw_src = pdfs ( i )->evallogcond_mat ( Smp , vec(0)); 
    154154                        } else { 
    155155                                // compute likelihood of marginal on the conditional variable 
  • library/tests/CMakeLists.txt

    r700 r713  
    4141# using UnitTest++ 
    4242 
    43 SET(unit_test_configurations  egiw.cfg mlnorm.cfg edirich.cfg mprod.cfg generator.cfg epdfds.cfg pdfds.cfg test_user_info_input.cfg merger.cfg erroneous.cfg egamma.cfg test_user_info_external.cfg merger_error.cfg mgamma.cfg enorm.cfg) 
     43SET(unit_test_configurations  egiw.cfg mlnorm.cfg edirich.cfg mprod.cfg generator.cfg epdfds.cfg pdfds.cfg test_user_info_input.cfg merger.cfg erroneous.cfg egamma.cfg test_user_info_external.cfg merger_error.cfg mgamma.cfg enorm.cfg mmix.cfg emix.cfg) 
    4444 
    4545add_executable(testsuite arx_straux_test.cpp datalink_test.cpp  datasource_test.cpp egiw_test.cpp emix_test.cpp epdf_test.cpp logger_test.cpp LQG_test.cpp merger_test.cpp  
  • library/tests/arx_elem_test.cpp

    r682 r713  
    3838 
    3939        mlstudent* Ap = Ar.predictor_student(); 
    40         vec Ap_x = Ap->evallogcond_m ( X, empty_vec ); 
    41         vec ll_x = Ar.logpred_m ( X2 ); 
     40        vec Ap_x = Ap->evallogcond_mat ( X, empty_vec ); 
     41        vec ll_x = Ar.logpred_mat ( X2 ); 
    4242 
    4343        cout << "normalize : " << xstep*sum ( exp ( Ap_x ) ) << endl; 
  • library/tests/emix_test.cpp

    r693 r713  
    6868 
    6969        int N = 3; 
    70         mat Smp = M2.sample_m ( N ); 
     70        mat Smp = M2.sample_mat ( N ); 
    7171 
    7272        vec exp_ll ( "-5.0 -2.53563 -2.62171" ); 
    73         vec ll = M2.evallog_m ( Smp ); 
     73        vec ll = M2.evallog_mat ( Smp ); 
    7474        CHECK_CLOSE ( exp_ll, ll, 5.0 ); 
    7575 
     
    115115        Array<vec> actual(CurrentContext::max_trial_count); 
    116116        do { 
    117                 mat smp = distrib_obj.sample_m ( nsamples ); 
     117                mat smp = distrib_obj.sample_mat ( nsamples ); 
    118118                vec emu = sum ( smp, 2 ) / nsamples; 
    119119                actual( tc ) = emu; 
     
    135135        Array<mat> actual(CurrentContext::max_trial_count); 
    136136        do { 
    137                 mat smp = distrib_obj.sample_m ( nsamples ); 
     137                mat smp = distrib_obj.sample_mat ( nsamples ); 
    138138                vec emu = sum ( smp, 2 ) / nsamples; 
    139139                mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 
  • library/tests/epdf_harness.cpp

    r706 r713  
    9595                } 
    9696 
    97                 vec lpzv_act = hepdf->evallog_m ( zero1n ); 
     97                vec lpzv_act = hepdf->evallog_mat ( zero1n ); 
    9898                CHECK_CLOSE_EX ( lpzv, lpzv_act, tolerance ); 
    9999 
     
    105105                } 
    106106 
    107                 lpzv_act = hepdf->evallog_m ( zeroa ); 
     107                lpzv_act = hepdf->evallog_mat ( zeroa ); 
    108108                CHECK_CLOSE_EX ( lpzv, lpzv_act, tolerance ); 
    109109        } 
     
    162162        Array<vec> actual(CurrentContext::max_trial_count); 
    163163        do { 
    164                 mat smp = hepdf->sample_m ( nsamples ); 
     164                mat smp = hepdf->sample_mat ( nsamples ); 
    165165                vec emu = smp * ones ( nsamples ) / nsamples; 
    166166                actual( tc ) = emu; 
     
    183183        Array<mat> actual(CurrentContext::max_trial_count); 
    184184        do { 
    185                 mat smp = hepdf->sample_m ( nsamples ); 
     185                mat smp = hepdf->sample_mat ( nsamples ); 
    186186                vec emu = smp * ones ( nsamples ) / nsamples; 
    187187                mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 
     
    208208        Array<vec> actual(CurrentContext::max_trial_count); 
    209209        do { 
    210                 mat smp = mep.samplecond_m ( vec ( 0 ), nsamples ); 
     210                mat smp = mep.samplecond_mat ( vec ( 0 ), nsamples ); 
    211211                vec emu = sum ( smp, 2 ) / nsamples; 
    212212                actual( tc ) = emu; 
     
    229229        Array<mat> actual(CurrentContext::max_trial_count); 
    230230        do { 
    231                 mat smp = mep.samplecond_m ( vec ( 0 ), nsamples ); 
     231                mat smp = mep.samplecond_mat ( vec ( 0 ), nsamples ); 
    232232                vec emu = sum ( smp, 2 ) / nsamples; 
    233233                mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 
  • library/tests/merger_2d_test.cpp

    r693 r713  
    5858        emix* MP = MM.epredictor(); //xy 
    5959 
    60         vec Res1 = M.evallog_m ( Grid ); 
    61         mat Res2 = ( MP )->evallog_M ( Grid ); 
     60        vec Res1 = M.evallog_mat ( Grid ); 
     61        mat Res2 = ( MP )->evallog_mat ( Grid ); 
    6262 
    6363        it_file it ( "merger_2d_test.it" ); 
     
    6666        it << Name ( "Res1" ) << Res1; 
    6767        it << Name ( "Res2" ) << Res2; 
    68         it << Name ( "S1" ) << f1->evallog_m ( Grid ); 
    69         it << Name ( "S2" ) << f2->evallog_m ( Grid ); 
     68        it << Name ( "S1" ) << f1->evallog_mat ( Grid ); 
     69        it << Name ( "S2" ) << f2->evallog_mat ( Grid ); 
    7070        cout << ( ( enorm<ldmat>* ) ( MP->_Coms ( 0 ).get() ) )->_R().to_mat() << endl; 
    7171} 
  • library/tests/merger_iter_test.cpp

    r693 r713  
    6060        epdf* MP = MM.epredictor();//xy 
    6161 
    62         vec Res1 = M.evallog_m ( Grid ); 
    63         mat Res2 = ( ( emix* ) MP )->evallog_M ( Grid ); 
     62        vec Res1 = M.evallog_mat ( Grid ); 
     63        mat Res2 = ( ( emix* ) MP )->evallog_mat ( Grid ); 
    6464 
    6565        it_file it ( "merger_iter_test.it" ); 
  • library/tests/merger_test.cpp

    r693 r713  
    2929        x_grid.set_row ( 0, linspace ( -10.0, 10.0 ) ); 
    3030 
    31         vec l_f1 = f1->evallog_m ( x_grid ); 
    32         vec l_f2 = f2->evallog_m ( x_grid ); 
     31        vec l_f1 = f1->evallog_mat ( x_grid ); 
     32        vec l_f2 = f2->evallog_mat ( x_grid ); 
    3333        mat lW ( 2, Npoints ); 
    3434        lW.set_row ( 0, l_f1 ); 
  • library/tests/mixtures_test.cpp

    r679 r713  
    6969        // Sample parameters 
    7070        int ndat = 100; 
    71         mat Smp = Simul.sample_m ( ndat ); 
     71        mat Smp = Simul.sample_mat ( ndat ); 
    7272 
    7373        cout << "Simulated means: " << m1 << " and " << m2 << endl; 
  • library/tests/pdf_harness.cpp

    r706 r713  
    5050        Array<vec> actual(CurrentContext::max_trial_count); 
    5151        do { 
    52                 mat smp = hpdf->samplecond_m ( cond, nsamples ); 
     52                mat smp = hpdf->samplecond_mat ( cond, nsamples ); 
    5353                vec emu = smp * ones ( nsamples ) / nsamples; 
    5454                actual( tc ) = emu; 
     
    7171        Array<mat> actual(CurrentContext::max_trial_count); 
    7272        do { 
    73                 mat smp = hpdf->samplecond_m ( cond, nsamples ); 
     73                mat smp = hpdf->samplecond_mat ( cond, nsamples ); 
    7474                vec emu = smp * ones ( nsamples ) / nsamples; 
    7575                mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 
  • library/tests/pdf_test.cpp

    r706 r713  
    1313static void check_covariance(mmix &distrib_obj, const vec &mu0, int nsamples, const mat &R, double tolerance); 
    1414 
    15 TEST ( mepdf_test ) { 
    16         pdf_harness::test_config ( "mepdf.cfg" ); 
    17 } 
    18  
    1915TEST ( mgamma_test ) { 
    2016        pdf_harness::test_config ( "mgamma.cfg" ); 
     
    2925} 
    3026 
    31 // not using pdf_harness because mmix isn't configurable (yet?) 
    3227TEST ( mmix_test ) { 
     28        pdf_harness::test_config ( "mmix.cfg" ); 
     29        //vec tmu = 0.5 * eN->mean() + 0.5 * mu0; 
     30 
     31        /* 
    3332        RV x ( "{mmixx }", "2" ); 
    3433        RV y ( "{mmixy }", "2" ); 
     
    6362        mat observedR ( "1.27572 0.778247; 0.778247 3.33129" ); 
    6463        check_covariance( mMix, mu0, N, observedR, 0.2 ); 
     64*/ 
    6565} 
    6666 
    6767// not using pdf_harness because emix isn't configurable (yet?) 
    68 TEST ( mepdf_emix_test ) { 
     68TEST ( emix_test ) { 
     69        pdf_harness::test_config ( "emix.cfg" ); 
     70        /* 
    6971        int N = 10000; //number of samples 
    7072        vec mu0 ( "1.5 1.7" ); 
     
    8789        eMix->set_parameters ( vec_2 ( 0.5, 0.5 ), Coms ); 
    8890        check_mean ( *eMix, mu0, N, eMix->mean(), 0.1 ); 
     91        */ 
    8992} 
    9093 
     
    9396        Array<vec> actual(CurrentContext::max_trial_count); 
    9497        do { 
    95                 mat smp = distrib_obj.samplecond_m ( mu0, nsamples ); 
     98                mat smp = distrib_obj.samplecond_mat ( mu0, nsamples ); 
    9699                vec emu = smp * ones ( nsamples ) / nsamples ; 
    97100                actual( tc ) = emu; 
     
    113116        Array<mat> actual(CurrentContext::max_trial_count); 
    114117        do { 
    115                 mat smp = distrib_obj.samplecond_m ( mu0, nsamples ); 
     118                mat smp = distrib_obj.samplecond_mat ( mu0, nsamples ); 
    116119                vec emu = smp * ones ( nsamples ) / nsamples ; 
    117120                mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu );