- Timestamp:
- 11/17/09 00:54:28 (15 years ago)
- Location:
- library
- Files:
-
- 9 modified
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.h
r727 r728 611 611 }; 612 612 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 } 620 628 } 621 629 } 622 630 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 } 631 643 } 632 644 } … … 1207 1219 //! Set boolean options from a string, recognized are: "logbounds,logll" 1208 1220 virtual void set_options ( const string &opt ) { 1209 if ( opt.find ( "log stat" ) != 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) ; 1211 1223 } else { 1212 1224 if ( opt.find ( "logbounds" ) != string::npos ) { -
library/bdm/base/loggers.cpp
r676 r728 49 49 void memlog::from_setting ( const Setting &set ) { 50 50 // 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"); 53 53 } 54 54 -
library/bdm/base/loggers.h
r727 r728 32 32 //! Storage 33 33 Array<mat> vectors; 34 //! name of it file to save results35 string itfilename;34 //! name of file to save results (IT file for vectors and cfg for settings) 35 string filename; 36 36 public: 37 37 //! 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 ) {} 39 39 40 40 //!Default constructor … … 66 66 //! 67 67 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 } 71 73 } 74 72 75 }; 73 76 … … 80 83 logger = { 81 84 class = "memlog"; 82 filename = "file_name .it"; // resulting filename with results in it format83 maxlen = 100; // size of memory buffer85 filename = "file_name"; // resulting filename with vectors in it format and setting in cfg 86 maxlen = 100; // size of memory buffer 84 87 } 85 88 \endcode -
library/bdm/base/user_info.cpp
r565 r728 198 198 : element.add ( name, Setting::TypeList ); 199 199 200 Setting &tag= set.add ( Setting::TypeString ); 201 tag ="matrix"; 202 200 203 Setting &cols = set.add ( Setting::TypeInt ); 201 204 cols = matrix.cols(); … … 260 263 Setting &elements = link.result[2 + data_offset]; 261 264 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 ); 265 269 266 270 int cols = cols_setting; 267 271 int rows = rows_setting; 272 int elems = elements.getLength(); 268 273 269 274 if ( cols < 0 || rows < 0 ) 270 275 throw UISettingException ( "UIException: the dimensions of a matrix has to be non-negative.", link.result ); 271 276 272 if ( elem ents.getLength()!= cols * rows )277 if ( elems != cols * rows ) 273 278 throw UISettingException ( "UIException: the count of the matrix elements is incompatible with matrix dimension.", elements ); 274 279 -
library/bdm/base/user_info.h
r710 r728 441 441 } 442 442 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. 446 template<class T> 447 static 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 443 453 //!@} 444 454 -
library/bdm/mex/config2mxstruct.h
r706 r728 31 31 mxArray* array2mxvector ( const Setting &setting ) { 32 32 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); 34 35 for ( int i = 0; i < setting.getLength(); i++ ) { 35 36 if ( setting.getType() == Setting::TypeInt ) { //TODO: tady je chyba -- zaporna cisla nejsou TypeInt 36 elements[i] = setting[i];37 elements[i] = (int) setting[i]; 37 38 } else { 38 elements[i] = ( int )setting[i];39 elements[i] = setting[i]; 39 40 } 40 41 } 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;46 42 return result; 47 43 } … … 49 45 //! Convert libconfig's array to Matlab matrix 50 46 mxArray* list2mxmatrix ( const Setting &setting ) { 51 if ( !setting.isList() || ( "matrix" != setting[0]) )47 if ( !setting.isList() || ( strcmp("matrix", setting[0])!=0 ) ) 52 48 mexErrMsgTxt ( "Given setting is not a matrix" ); 53 49 int rows = setting[1]; … … 118 114 return result; 119 115 } 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 } 122 122 } 123 123 mxArray *result = mxCreateCellMatrix ( 1, setting.getLength() ); -
library/bdm/mex/mex_logger.h
r706 r728 77 77 maxlen = root["maxlen"]; 78 78 } 79 Config& _setting_conf(){return setting_conf;} 79 80 }; 80 81 UIREGISTER ( mexlog ); -
library/bdm/stat/exp_family.h
r727 r728 280 280 void to_setting ( Setting& set ) const{ 281 281 epdf::to_setting(set); 282 string s("egiw"); 283 UI::save(s,set,"class"); 282 284 UI::save(dimx,set,"dimx"); 283 285 UI::save(V.to_mat(),set,"V"); -
library/tests/testsuite/logger_test.cpp
r727 r728 36 36 RV r = RV ( "{r }", "2" ); 37 37 38 string ls ( " test_log.bin" );38 string ls ( "memlog_test" ); 39 39 remove_all ( ls.c_str() ); 40 40 … … 58 58 logger.finalize(); 59 59 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() )); 62 62 } 63 63