Changeset 728

Show
Ignore:
Timestamp:
11/17/09 00:54:28 (14 years ago)
Author:
smidl
Message:

logger now has ability to store settings - used in estimator. New mexfunction epdf_mean

Files:
1 added
11 modified
1 moved

Legend:

Unmodified
Added
Removed
  • applications/bdmtoolbox/mex/CMakeLists.txt

    r704 r728  
     1 
     2## SCENARIOS 
    13 
    24MEX(merger) 
     
    1416MEX(config2mxstruct) 
    1517MEX(mxstruct2config) 
     18 
     19## WRAPPERS 
     20 
     21MEX(epdf_mean) 
  • applications/bdmtoolbox/mex/estimator.cpp

    r723 r728  
    209209                if ( n_output<1 ) mexErrMsgTxt ( "Wrong number of output variables!" ); 
    210210                output[0] = mL->toCell(); 
     211                if (n_output>1) { 
     212                        UImxConfig UIc(mL->_setting_conf().getRoot()); 
     213                        output[1]=UIc.mxconfig; 
     214                } 
    211215        } 
    212216#endif 
  • library/bdm/base/bdmbase.h

    r727 r728  
    611611                }; 
    612612                root::log_register(L,prefix); 
    613                 logrec->ids.set_size(3); 
    614                 if (log_level >0){ 
    615                         logrec->ids(0) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep()+ "mean" ); 
    616                 } 
    617                 if (log_level >1){ 
    618                         logrec->ids(1) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep()+ "lb" ); 
    619                         logrec->ids(2) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep()+ "ub" ); 
     613                 
     614                // log full data 
     615                if (log_level==10) { 
     616                        logrec->ids.set_size(1); 
     617                        logrec->ids(0) = logrec->L.add_setting(prefix); 
     618                } else { 
     619                        // log only  
     620                        logrec->ids.set_size(3); 
     621                        if (log_level >0){ 
     622                                logrec->ids(0) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep()+ "mean" ); 
     623                        } 
     624                        if (log_level >1){ 
     625                                logrec->ids(1) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep()+ "lb" ); 
     626                                logrec->ids(2) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep()+ "ub" ); 
     627                        } 
    620628                } 
    621629        } 
    622630        void log_write() const { 
    623                 if (log_level>0) { 
    624                         logrec->L.log_vector( logrec->ids(0), mean() ); 
    625                 } 
    626                 if (log_level>1) { 
    627                         vec lb; vec ub; 
    628                         qbounds(lb,ub); 
    629                         logrec->L.log_vector( logrec->ids(1), lb ); 
    630                         logrec->L.log_vector( logrec->ids(2), ub ); 
     631                if (log_level==10){ 
     632                        to_setting(logrec->L.log_to_setting(logrec->ids(0))); 
     633                } else { 
     634                        if (log_level>0) { 
     635                                logrec->L.log_vector( logrec->ids(0), mean() ); 
     636                        } 
     637                        if (log_level>1) { 
     638                                vec lb; vec ub; 
     639                                qbounds(lb,ub); 
     640                                logrec->L.log_vector( logrec->ids(1), lb ); 
     641                                logrec->L.log_vector( logrec->ids(2), ub ); 
     642                        } 
    631643                } 
    632644        } 
     
    12071219        //! Set boolean options from a string, recognized are: "logbounds,logll" 
    12081220        virtual void set_options ( const string &opt ) { 
    1209                 if ( opt.find ( "logstat" ) != string::npos ) { 
    1210                         const_cast<epdf&>(posterior()).set_log_level(3) ; 
     1221                if ( opt.find ( "logfull" ) != string::npos ) { 
     1222                        const_cast<epdf&>(posterior()).set_log_level(10) ; 
    12111223                } else { 
    12121224                        if ( opt.find ( "logbounds" ) != string::npos ) { 
  • library/bdm/base/loggers.cpp

    r676 r728  
    4949void memlog::from_setting ( const Setting &set ) { 
    5050        // TODO tady se natvrdo ocekava existence stringu, nejsou zadne defaulty.. je to tak OK? 
    51         string itfilename = ( const char* ) set["filename"]; 
    52         maxlen = set["maxlen"]; 
     51        UI::get(maxlen,  set,"maxlen",UI::compulsory); 
     52        UI::get(filename,set,"filename"); 
    5353} 
    5454 
  • library/bdm/base/loggers.h

    r727 r728  
    3232        //! Storage 
    3333        Array<mat> vectors; 
    34         //! name of it file to save results 
    35         string itfilename; 
     34        //! name of  file to save results (IT file for vectors and cfg for settings) 
     35        string filename; 
    3636public: 
    3737        //! convenience constructor 
    38         memlog ( int maxlen0, string itf = "" ) :logger("_"), maxlen ( maxlen0 ), ind ( 0 ), vectors ( 0 ), itfilename ( itf ) {} 
     38        memlog ( int maxlen0, string fn = "" ) :logger("_"), maxlen ( maxlen0 ), ind ( 0 ), vectors ( 0 ), filename ( fn ) {} 
    3939 
    4040        //!Default constructor 
     
    6666        //! 
    6767        void finalize() { 
    68                 if ( itfilename.length() > 0 ) itsave ( itfilename.c_str() ); 
    69                 if (settings.length()>0){ 
    70                         setting_conf.writeFile("memlog_setting.cfg"); 
     68                if ( filename.length() > 0 ) { 
     69                        itsave ( (filename+".it").c_str()); 
     70                        if (settings.length()>0){ 
     71                                setting_conf.writeFile( (filename+".cfg").c_str()); 
     72                        } 
    7173                } 
     74                 
    7275        }; 
    7376 
     
    8083        logger = { 
    8184                class = "memlog"; 
    82                 filename = "file_name.it"; // resulting filename with results in it format 
    83                 maxlen = 100;          // size of memory buffer 
     85                filename = "file_name"; // resulting filename with vectors in it format and setting in cfg 
     86                maxlen = 100;           // size of memory buffer 
    8487        } 
    8588        \endcode 
  • library/bdm/base/user_info.cpp

    r565 r728  
    198198                       : element.add ( name, Setting::TypeList ); 
    199199 
     200                                   Setting &tag= set.add ( Setting::TypeString ); 
     201                                   tag ="matrix"; 
     202                                    
    200203        Setting &cols = set.add ( Setting::TypeInt ); 
    201204        cols = matrix.cols(); 
     
    260263                Setting &elements = link.result[2 + data_offset]; 
    261264 
    262                 assert_type ( cols_setting, Setting::TypeInt ); 
    263                 assert_type ( rows_setting, Setting::TypeInt ); 
    264                 assert_type ( elements, Setting::TypeArray ); 
     265                // vvv ----- not working in matlab!! 
     266                //assert_type ( cols_setting, Setting::TypeInt ); 
     267                //assert_type ( rows_setting, Setting::TypeInt ); 
     268                //assert_type ( elements, Setting::TypeArray ); 
    265269 
    266270                int cols = cols_setting; 
    267271                int rows = rows_setting; 
     272                int elems = elements.getLength(); 
    268273 
    269274                if ( cols < 0 || rows < 0 ) 
    270275                        throw UISettingException ( "UIException: the dimensions of a matrix has to be non-negative.", link.result ); 
    271276 
    272                 if ( elements.getLength() != cols * rows ) 
     277                if ( elems != cols * rows ) 
    273278                        throw UISettingException ( "UIException: the count of the matrix elements is incompatible with matrix dimension.", elements ); 
    274279 
  • library/bdm/base/user_info.h

    r710 r728  
    441441        } 
    442442 
     443//! The new instance of type T* is constructed and initialized with values stored in the given Setting  
     444//! 
     445//! Handy in mex files. Use with care. 
     446template<class T> 
     447static shared_ptr<T> build ( const Setting &element, SettingPresence settingPresence = optional ) {      
     448        shared_ptr<T> instance; 
     449        from_setting<T> ( instance,  element  ); 
     450        return instance; 
     451} 
     452 
    443453        //!@} 
    444454 
  • library/bdm/mex/config2mxstruct.h

    r706 r728  
    3131        mxArray* array2mxvector ( const Setting &setting )  { 
    3232                if ( !setting.isArray() ) mexErrMsgTxt ( "Given setting is not an array" ); 
    33                 double *elements = new double[setting.getLength() ]; 
     33                mxArray *result = mxCreateDoubleMatrix ( 1, setting.getLength(), mxREAL ); 
     34                double *elements = mxGetPr(result); 
    3435                for ( int i = 0; i < setting.getLength(); i++ ) { 
    3536                        if ( setting.getType() == Setting::TypeInt ) { //TODO: tady je chyba -- zaporna cisla nejsou TypeInt 
    36                                 elements[i] = setting[i]; 
     37                                elements[i] = (int) setting[i]; 
    3738                        } else { 
    38                                 elements[i] = ( int ) setting[i]; 
     39                                elements[i] = setting[i]; 
    3940                        } 
    4041                } 
    41                 vec &v = * ( new vec ( elements, setting.getLength() ) ); 
    42                 mxArray *result = mxCreateDoubleMatrix ( 1, setting.getLength(), mxREAL ); 
    43                 vec2mxArray ( v, result ); 
    44                 delete &v; 
    45                 delete [] elements; 
    4642                return result; 
    4743        } 
     
    4945        //! Convert libconfig's array to Matlab matrix 
    5046        mxArray* list2mxmatrix ( const Setting &setting )  { 
    51                 if ( !setting.isList() || ( "matrix" != setting[0] ) ) 
     47                if ( !setting.isList() || ( strcmp("matrix", setting[0])!=0 ) ) 
    5248                        mexErrMsgTxt ( "Given setting is not a matrix" ); 
    5349                int rows = setting[1]; 
     
    118114                        return result; 
    119115                } 
    120                 if ( ( setting[0].getType() == Setting::TypeString ) && ( "matrix" == setting[0] ) ) { 
    121                         return list2mxmatrix ( setting ); 
     116                 
     117                if ( ( setting[0].getType() == Setting::TypeString )){ 
     118                        string s=(setting[0]); 
     119                        if (s=="matrix") { 
     120                                return list2mxmatrix ( setting ); 
     121                        } 
    122122                } 
    123123                mxArray *result = mxCreateCellMatrix ( 1, setting.getLength() ); 
  • library/bdm/mex/mex_logger.h

    r706 r728  
    7777                maxlen = root["maxlen"]; 
    7878        } 
     79        Config& _setting_conf(){return setting_conf;} 
    7980}; 
    8081UIREGISTER ( mexlog ); 
  • library/bdm/stat/exp_family.h

    r727 r728  
    280280                void to_setting ( Setting& set ) const{ 
    281281                        epdf::to_setting(set); 
     282                        string s("egiw"); 
     283                        UI::save(s,set,"class"); 
    282284                        UI::save(dimx,set,"dimx"); 
    283285                        UI::save(V.to_mat(),set,"V"); 
  • library/tests/testsuite/logger_test.cpp

    r727 r728  
    3636        RV r = RV ( "{r }", "2" ); 
    3737 
    38         string ls ( "test_log.bin" ); 
     38        string ls ( "memlog_test" ); 
    3939        remove_all ( ls.c_str() ); 
    4040 
     
    5858        logger.finalize(); 
    5959 
    60         CHECK_EQUAL ( get_file_size ( "logger_test.matrix" ), get_file_size ( ls.c_str() ) ); 
    61         CHECK_EQUAL ( get_file_size ( "memlog_setting.cfg.check" ), get_file_size ( "memlog_setting.cfg" ) ); 
     60        CHECK_EQUAL ( get_file_size ( "logger_test.matrix" ), get_file_size ( (ls+".it").c_str() ) ); 
     61        CHECK_EQUAL ( get_file_size ( (ls+".cfg.check").c_str() ), get_file_size ( (ls+".cfg" ).c_str() )); 
    6262} 
    6363