Changeset 728 for library/bdm/base

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

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

Location:
library/bdm/base
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • 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