Changeset 737 for library/bdm/base/bdmbase.h
- Timestamp:
- 11/25/09 12:14:38 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.h
r733 r737 149 149 friend std::ostream &operator<< ( std::ostream &os, const RV &rv ); 150 150 151 string to_string() const {ostringstream o; o << *this; return o.str();} 152 151 string to_string() const { 152 ostringstream o; 153 o << *this; 154 return o.str(); 155 } 156 153 157 //! total size of a random variable 154 158 int _dsize() const { … … 183 187 //! returns name of a scalar at position scalat, i.e. it can be in the middle of vector name, in that case it adds "_%d" to it 184 188 std::string scalarname ( int scalat ) const { 185 bdm_assert(scalat<dsize,"Wrong input index"); 186 int id=0; 187 int scalid=0; 188 while (scalid+SIZES(ids(id))<=scalat) { scalid+=SIZES(ids(id)); id++;}; 189 bdm_assert ( scalat < dsize, "Wrong input index" ); 190 int id = 0; 191 int scalid = 0; 192 while ( scalid + SIZES ( ids ( id ) ) <= scalat ) { 193 scalid += SIZES ( ids ( id ) ); 194 id++; 195 }; 189 196 //now id is the id of variable of interest 190 if ( size(id)==1)197 if ( size ( id ) == 1 ) 191 198 return NAMES ( ids ( id ) ); 192 199 else 193 return NAMES ( ids ( id ) ) + "_" + num2str(scalat-scalid);200 return NAMES ( ids ( id ) ) + "_" + num2str ( scalat - scalid ); 194 201 195 202 } … … 233 240 } 234 241 //! create new RV from the current one with time shifted by given value 235 RV copy_t (int dt) const {236 RV tmp =*this;237 tmp.t_plus (dt);242 RV copy_t ( int dt ) const { 243 RV tmp = *this; 244 tmp.t_plus ( dt ); 238 245 return tmp; 239 246 } … … 266 273 //! Minimum time-offset 267 274 int mint() const { 268 return times.length() >0 ? min (times) : 0;275 return times.length() > 0 ? min ( times ) : 0; 269 276 } 270 277 //! Minimum time-offset of ids of given RVs 271 int mint (const RV &rv) const {272 bvec belong =zeros_b(len);273 for ( int r=0; r<rv.length(); r++){274 belong = belong | ( ids == rv.id(r));275 } 276 return times.length() >0 ? min (get_from_bvec(times,belong)) : 0;278 int mint ( const RV &rv ) const { 279 bvec belong = zeros_b ( len ); 280 for ( int r = 0; r < rv.length(); r++ ) { 281 belong = belong | ( ids == rv.id ( r ) ); 282 } 283 return times.length() > 0 ? min ( get_from_bvec ( times, belong ) ) : 0; 277 284 } 278 285 //!@} … … 281 288 282 289 \code 283 class = 'RV'; 290 class = 'RV'; 284 291 names = {'a', 'b', 'c', ...}; // UNIQUE IDENTIFIER same names = same variable 285 // names are also used when storing results 292 // names are also used when storing results 286 293 --- optional --- 287 294 sizes = [1, 2, 3, ...]; // size of each name. default = ones() … … 292 299 void from_setting ( const Setting &set ); 293 300 294 void to_setting ( Setting &set ) const;301 void to_setting ( Setting &set ) const; 295 302 296 303 //! Invalidate all named RVs. Use before initializing any RV instances, with care... … … 312 319 */ 313 320 class logger : public root { 314 protected: 315 //! RVs of all logged variables. 316 Array<RV> entries; 317 //! Names of logged quantities, e.g. names of algorithm variants 318 Array<string> names; 319 //!separator of prefixes of entries 320 const string separator; 321 //! Root Setting for storing Settings 322 Config setting_conf; 323 //! list of Settings for specific ids 324 Array<Setting*> settings; 325 public: 326 //!Default constructor 327 logger(const string separator0) : entries ( 0 ), names ( 0 ), separator(separator0) {} 328 329 //! returns an identifier which will be later needed for calling the \c logit() function 330 //! For empty RV it returns -1, this entry will be ignored by \c logit(). 331 virtual int add_vector ( const RV &rv, string prefix = "" ) { 332 int id; 333 if ( rv._dsize() > 0 ) { 334 id = entries.length(); 335 names = concat ( names, prefix ); // diff 336 entries.set_length ( id + 1, true ); 337 entries ( id ) = rv; 338 } else { 339 id = -1; 340 } 341 return id; // identifier of the last entry 342 } 343 virtual int add_setting(const string &prefix){ 344 Setting &root=setting_conf.getRoot(); 345 int id=root.getLength(); //root must be group!! 346 if (prefix.length()>0){ 347 settings.set_length(id+1,true); 348 settings(id) = &root.add(prefix, Setting::TypeList); 349 } else {id=-1;} 350 return id; 351 } 352 353 //! log this vector 354 virtual void log_vector ( int id, const vec &v ) { 355 bdm_error ( "Not implemented" ); 356 }; 357 358 virtual Setting & log_to_setting (int id){ 359 return settings(id)->add(Setting::TypeGroup); 360 } 361 362 //! log this double 363 virtual void logit ( int id, const double &d ) { 364 bdm_error ( "Not implemented" ); 365 }; 366 367 //! Shifts storage position for another time step. 368 virtual void step() { 369 bdm_error ( "Not implemneted" ); 370 }; 371 372 //! Finalize storing information 373 virtual void finalize() {}; 374 375 //! Initialize the storage 376 virtual void init() {}; 377 378 //!separator of prefixes for this logger 379 const string& prefix_sep() {return separator;} 321 protected: 322 //! RVs of all logged variables. 323 Array<RV> entries; 324 //! Names of logged quantities, e.g. names of algorithm variants 325 Array<string> names; 326 //!separator of prefixes of entries 327 const string separator; 328 //! Root Setting for storing Settings 329 Config setting_conf; 330 //! list of Settings for specific ids 331 Array<Setting*> settings; 332 public: 333 //!Default constructor 334 logger ( const string separator0 ) : entries ( 0 ), names ( 0 ), separator ( separator0 ) {} 335 336 //! returns an identifier which will be later needed for calling the \c logit() function 337 //! For empty RV it returns -1, this entry will be ignored by \c logit(). 338 virtual int add_vector ( const RV &rv, string prefix = "" ) { 339 int id; 340 if ( rv._dsize() > 0 ) { 341 id = entries.length(); 342 names = concat ( names, prefix ); // diff 343 entries.set_length ( id + 1, true ); 344 entries ( id ) = rv; 345 } else { 346 id = -1; 347 } 348 return id; // identifier of the last entry 349 } 350 virtual int add_setting ( const string &prefix ) { 351 Setting &root = setting_conf.getRoot(); 352 int id = root.getLength(); //root must be group!! 353 if ( prefix.length() > 0 ) { 354 settings.set_length ( id + 1, true ); 355 settings ( id ) = &root.add ( prefix, Setting::TypeList ); 356 } else { 357 id = -1; 358 } 359 return id; 360 } 361 362 //! log this vector 363 virtual void log_vector ( int id, const vec &v ) { 364 bdm_error ( "Not implemented" ); 365 }; 366 367 virtual Setting & log_to_setting ( int id ) { 368 return settings ( id )->add ( Setting::TypeGroup ); 369 } 370 371 //! log this double 372 virtual void logit ( int id, const double &d ) { 373 bdm_error ( "Not implemented" ); 374 }; 375 376 //! Shifts storage position for another time step. 377 virtual void step() { 378 bdm_error ( "Not implemneted" ); 379 }; 380 381 //! Finalize storing information 382 virtual void finalize() {}; 383 384 //! Initialize the storage 385 virtual void init() {}; 386 387 //!separator of prefixes for this logger 388 const string& prefix_sep() { 389 return separator; 390 } 380 391 }; 381 392 … … 429 440 //! @{ 430 441 431 pdf() : dimc ( 0 ), rvc(), dim (0), rv() { }432 433 pdf ( const pdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), dim ( m.dim), rv( m.rv ) { }434 442 pdf() : dimc ( 0 ), rvc(), dim ( 0 ), rv() { } 443 444 pdf ( const pdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), dim ( m.dim ), rv ( m.rv ) { } 445 435 446 //! copy of the current object - make sure to implement 436 virtual pdf* _copy_() const {return new pdf(*this);} 447 virtual pdf* _copy_() const { 448 return new pdf ( *this ); 449 } 437 450 //!@} 438 451 … … 488 501 489 502 //! access function 490 void set_dim(int d) {dim=d;} 503 void set_dim ( int d ) { 504 dim = d; 505 } 491 506 //! access function 492 void set_dimc(int d) {dimc=d;} 507 void set_dimc ( int d ) { 508 dimc = d; 509 } 493 510 //! Load from structure with elements: 494 511 //! \code … … 535 552 @{*/ 536 553 epdf() {}; 537 epdf ( const epdf &e ) : pdf (e) {};554 epdf ( const epdf &e ) : pdf ( e ) {}; 538 555 void set_parameters ( int dim0 ) { 539 556 dim = dim0; 540 557 } 541 epdf* _copy_() const {return new epdf(*this);} 558 epdf* _copy_() const { 559 return new epdf ( *this ); 560 } 542 561 //!@} 543 562 … … 603 622 //! #1 mean 604 623 //! #2 mean + lower & upper bound 605 void log_register (logger &L, const string &prefix){624 void log_register ( logger &L, const string &prefix ) { 606 625 RV r; 607 626 if ( isnamed() ) { … … 610 629 r = RV ( "", dimension() ); 611 630 }; 612 root::log_register (L,prefix);613 631 root::log_register ( L, prefix ); 632 614 633 // log full data 615 if ( log_level==10) {616 logrec->ids.set_size (1);617 logrec->ids (0) = logrec->L.add_setting(prefix);634 if ( log_level == 10 ) { 635 logrec->ids.set_size ( 1 ); 636 logrec->ids ( 0 ) = logrec->L.add_setting ( prefix ); 618 637 } 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" );638 // log only 639 logrec->ids.set_size ( 3 ); 640 if ( log_level > 0 ) { 641 logrec->ids ( 0 ) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep() + "mean" ); 623 642 } 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" );643 if ( log_level > 1 ) { 644 logrec->ids ( 1 ) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep() + "lb" ); 645 logrec->ids ( 2 ) = logrec->L.add_vector ( r, prefix + logrec->L.prefix_sep() + "ub" ); 627 646 } 628 647 } 629 648 } 630 649 void log_write() const { 631 if ( log_level==10){632 to_setting (logrec->L.log_to_setting(logrec->ids(0)));650 if ( log_level == 10 ) { 651 to_setting ( logrec->L.log_to_setting ( logrec->ids ( 0 ) ) ); 633 652 } else { 634 if ( log_level>0) {635 logrec->L.log_vector ( logrec->ids(0), mean() );653 if ( log_level > 0 ) { 654 logrec->L.log_vector ( logrec->ids ( 0 ), mean() ); 636 655 } 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 ); 656 if ( log_level > 1 ) { 657 vec lb; 658 vec ub; 659 qbounds ( lb, ub ); 660 logrec->L.log_vector ( logrec->ids ( 1 ), lb ); 661 logrec->L.log_vector ( logrec->ids ( 2 ), ub ); 642 662 } 643 663 } … … 704 724 //! Efficient version of samplecond 705 725 virtual mat samplecond_mat ( const vec &cond, int N ); 706 726 707 727 void validate() { 708 728 iepdf.validate(); 709 if (rv._dsize()< iepdf._rv()._dsize()) {rv=iepdf._rv();}; 729 if ( rv._dsize() < iepdf._rv()._dsize() ) { 730 rv = iepdf._rv(); 731 }; 710 732 dim = iepdf.dimension(); 711 733 } … … 789 811 } 790 812 //! for future use 791 virtual ~datalink() {}813 virtual ~datalink() {} 792 814 }; 793 815 … … 829 851 if ( v2h_up.length() > 0 ) { 830 852 history.shift_right ( 0, v2h_up.length() ); 831 history.set_subvector ( 0, val_up(v2h_up) );853 history.set_subvector ( 0, val_up ( v2h_up ) ); 832 854 } 833 855 } … … 854 876 ivec valid_ids = rv.findself_ids ( rv_up ); 855 877 RV rv_hist = rv.subselect ( find ( valid_ids >= 0 ) ); // select only rvs that are in rv_up 856 RV rv_hist0 = rv_hist.remove_time();// these RVs will form history at time =0878 RV rv_hist0 = rv_hist.remove_time(); // these RVs will form history at time =0 857 879 // now we need to know what is needed from Up 858 880 rv_hist = rv_hist.expand_delayes(); // full regressor - including time 0 859 Hrv =rv_hist.subt(rv_hist0); // remove time 0881 Hrv = rv_hist.subt ( rv_hist0 ); // remove time 0 860 882 history = zeros ( Hrv._dsize() ); 861 883 862 884 // decide if we need to copy val to history 863 if ( Hrv._dsize() >0) {864 v2h_up = rv_hist0.dataind (rv_up); // indeces of elements of rv_up to be copied885 if ( Hrv._dsize() > 0 ) { 886 v2h_up = rv_hist0.dataind ( rv_up ); // indeces of elements of rv_up to be copied 865 887 } // else v2h_up is empty 866 888 867 889 Hrv.dataind ( rv, h2v_hist, h2v_down ); 868 890 … … 871 893 } 872 894 //! set history of variable given by \c rv1 to values of \c hist. 873 void set_history (const RV& rv1, const vec &hist0){874 bdm_assert (rv1._dsize()==hist0.length(),"hist is not compatible with given rv1");895 void set_history ( const RV& rv1, const vec &hist0 ) { 896 bdm_assert ( rv1._dsize() == hist0.length(), "hist is not compatible with given rv1" ); 875 897 ivec ind_H; 876 898 ivec ind_h0; 877 Hrv.dataind (rv1, ind_H, ind_h0); // find indeces of rv in878 set_subvector (history, ind_H, hist0(ind_h0)); // copy given hist to appropriate places899 Hrv.dataind ( rv1, ind_H, ind_h0 ); // find indeces of rv in 900 set_subvector ( history, ind_H, hist0 ( ind_h0 ) ); // copy given hist to appropriate places 879 901 } 880 902 }; … … 957 979 vec get_cond ( const vec &val_up, const vec &cond_up ) { 958 980 vec tmp ( condsize ); 959 fill_cond ( val_up, cond_up, tmp );981 fill_cond ( val_up, cond_up, tmp ); 960 982 return tmp; 961 983 } 962 //! fill condition 963 void fill_cond ( const vec &val_up, const vec &cond_up, vec& cond_out ){964 bdm_assert_debug (cond_out.length()>=condsize,"dl.fill_cond: cond_out is too small");984 //! fill condition 985 void fill_cond ( const vec &val_up, const vec &cond_up, vec& cond_out ) { 986 bdm_assert_debug ( cond_out.length() >= condsize, "dl.fill_cond: cond_out is too small" ); 965 987 set_subvector ( cond_out, v2c_lo, val_up ( v2c_up ) ); 966 988 set_subvector ( cond_out, c2c_lo, cond_up ( c2c_up ) ); … … 976 998 /*! \brief Abstract class for discrete-time sources of data. 977 999 978 The class abstracts operations of: 979 \li data aquisition, 980 \li data-preprocessing, such as scaling of data, 1000 The class abstracts operations of: 1001 \li data aquisition, 1002 \li data-preprocessing, such as scaling of data, 981 1003 \li data resampling from the task of estimation and control. 982 1004 Moreover, for controlled systems, it is able to receive the desired control action and perform it in the next step. (Or as soon as possible). 983 1005 984 1006 The DataSource has three main data interaction structures: 985 \li input, \f$ u_t \f$, 1007 \li input, \f$ u_t \f$, 986 1008 \li output \f$ y_t \f$, 987 1009 \li data, \f$ d_t=[y_t,u_t, \ldots ]\f$ a collection of all inputs and outputs and possibly some internal variables too. … … 991 1013 class DS : public root { 992 1014 protected: 993 1015 //! size of data returned by \c getdata() 994 1016 int dtsize; 995 1017 //! size of data 996 1018 int utsize; 997 998 1019 //!size of output 1020 int ytsize; 999 1021 //!Description of data returned by \c getdata(). 1000 1022 RV Drv; 1001 1023 //!Description of data witten by by \c write(). 1002 1024 RV Urv; // 1003 1004 1025 //!Description of output data 1026 RV Yrv; // 1005 1027 public: 1006 1028 //! default constructors 1007 DS() : dtsize(0),utsize(0),ytsize(0),Drv(), Urv(),Yrv() {log_level=1;}; 1029 DS() : dtsize ( 0 ), utsize ( 0 ), ytsize ( 0 ), Drv(), Urv(), Yrv() { 1030 log_level = 1; 1031 }; 1008 1032 1009 1033 //! Returns maximum number of provided data, by default it is set to maximum allowed length, shorter DS should overload this method! See, MemDS.max_length(). 1010 virtual int max_length() {return std::numeric_limits< int >::max();} 1034 virtual int max_length() { 1035 return std::numeric_limits< int >::max(); 1036 } 1011 1037 //! Returns full vector of observed data=[output, input] 1012 1038 virtual void getdata ( vec &dt ) const { … … 1019 1045 1020 1046 //! Accepts action variable and schedule it for application. 1021 virtual void write ( const vec &ut ) {1047 virtual void write ( const vec &ut ) { 1022 1048 bdm_error ( "abstract class" ); 1023 1049 } 1024 1050 1025 1051 //! Accepts action variables at specific indeces 1026 virtual void write ( const vec &ut, const ivec &indeces ) {1052 virtual void write ( const vec &ut, const ivec &indeces ) { 1027 1053 bdm_error ( "abstract class" ); 1028 1054 } 1029 1055 1030 1056 //! Moves from \f$ t \f$ to \f$ t+1 \f$, i.e. perfroms the actions and reads response of the system. 1031 virtual void step() 1032 { 1057 virtual void step() { 1033 1058 bdm_error ( "abstract class" ); 1034 1059 } 1035 1060 1036 1061 //! Register DS for logging into logger L 1037 virtual void log_register ( logger &L, const string &prefix ) {1062 virtual void log_register ( logger &L, const string &prefix ) { 1038 1063 bdm_assert ( ytsize == Yrv._dsize(), "invalid DS: ytsize (" + num2str ( ytsize ) + ") different from Drv " + num2str ( Yrv._dsize() ) ); 1039 1064 bdm_assert ( utsize == Urv._dsize(), "invalid DS: utsize (" + num2str ( utsize ) + ") different from Urv " + num2str ( Urv._dsize() ) ); 1040 1065 1041 root::log_register (L,prefix);1042 //we know that 1043 if ( log_level >0){1044 logrec->ids.set_size (2);1045 logrec->ids (0) = logrec->L.add_vector ( Yrv, prefix );1046 logrec->ids (1) = logrec->L.add_vector ( Urv, prefix );1066 root::log_register ( L, prefix ); 1067 //we know that 1068 if ( log_level > 0 ) { 1069 logrec->ids.set_size ( 2 ); 1070 logrec->ids ( 0 ) = logrec->L.add_vector ( Yrv, prefix ); 1071 logrec->ids ( 1 ) = logrec->L.add_vector ( Urv, prefix ); 1047 1072 } 1048 1073 } 1049 1074 //! Register DS for logging into logger L 1050 1075 virtual void log_write ( ) const { 1051 if ( log_level >0) {1052 vec tmp ( Yrv._dsize() + Urv._dsize() );1076 if ( log_level > 0 ) { 1077 vec tmp ( Yrv._dsize() + Urv._dsize() ); 1053 1078 getdata ( tmp ); 1054 1079 // d is first in getdata 1055 logrec->L.log_vector ( logrec->ids (0), tmp.left ( Yrv._dsize() ) );1080 logrec->L.log_vector ( logrec->ids ( 0 ), tmp.left ( Yrv._dsize() ) ); 1056 1081 // u follows after d in getdata 1057 logrec->L.log_vector ( logrec->ids (1), tmp.mid ( Yrv._dsize(), Urv._dsize() ) );1082 logrec->L.log_vector ( logrec->ids ( 1 ), tmp.mid ( Yrv._dsize(), Urv._dsize() ) ); 1058 1083 } 1059 1084 } … … 1071 1096 } 1072 1097 //! set random variables 1073 virtual void set_drv ( const RV &yrv, const RV &urv) {1098 virtual void set_drv ( const RV &yrv, const RV &urv ) { 1074 1099 Yrv = yrv; 1075 Drv = concat (yrv,urv);1100 Drv = concat ( yrv, urv ); 1076 1101 Urv = urv; 1077 1102 } … … 1085 1110 \f] 1086 1111 where: 1087 * \f$ y_t \f$ is the variable 1112 * \f$ y_t \f$ is the variable 1088 1113 Access to the resulting posterior density is via function \c posterior(). 1089 1114 … … 1109 1134 //! size of the conditioning vector 1110 1135 int dimc; 1111 1136 1112 1137 //!Logarithm of marginalized data likelihood. 1113 1138 double ll; … … 1119 1144 //! @{ 1120 1145 1121 BM() : yrv(), dimy(0),rvc(),dimc(0), ll ( 0 ), evalll ( true ) { };1146 BM() : yrv(), dimy ( 0 ), rvc(), dimc ( 0 ), ll ( 0 ), evalll ( true ) { }; 1122 1147 // BM ( const BM &B ) : yrv ( B.yrv ), dimy(B.dimy), rvc ( B.rvc ),dimc(B.dimc), ll ( B.ll ), evalll ( B.evalll ) {} 1123 1148 //! \brief Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually! 1124 1149 //! Prototype: \code BM* _copy_() const {return new BM(*this);} \endcode 1125 virtual BM* _copy_() const { return NULL; }; 1150 virtual BM* _copy_() const { 1151 return NULL; 1152 }; 1126 1153 //!@} 1127 1154 … … 1132 1159 @param dt vector of input data 1133 1160 */ 1134 virtual void bayes ( const vec &yt, const vec &cond =empty_vec ) = 0;1161 virtual void bayes ( const vec &yt, const vec &cond = empty_vec ) = 0; 1135 1162 //! Batch Bayes rule (columns of Dt are observations) 1136 virtual void bayes_batch ( const mat &Dt, const vec &cond =empty_vec );1163 virtual void bayes_batch ( const mat &Dt, const vec &cond = empty_vec ); 1137 1164 //! Batch Bayes rule (columns of Dt are observations, columns of Cond are conditions) 1138 1165 virtual void bayes_batch ( const mat &Dt, const mat &Cond ); 1139 1166 //! Evaluates predictive log-likelihood of the given data record 1140 //! I.e. marginal likelihood of the data with the posterior integrated out. 1141 //! This function evaluates only \f$ y_t \f$, condition is assumed to be the last used in bayes(). 1167 //! I.e. marginal likelihood of the data with the posterior integrated out. 1168 //! This function evaluates only \f$ y_t \f$, condition is assumed to be the last used in bayes(). 1142 1169 //! See bdm::BM::predictor for conditional version. 1143 1170 virtual double logpred ( const vec &yt ) const { … … 1170 1197 //! \name Access to attributes 1171 1198 //!@{ 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1199 //! access function 1200 const RV& _rvc() const { 1201 return rvc; 1202 } 1203 //! access function 1204 int dimensionc() const { 1205 return dimc; 1206 } 1207 //! access function 1208 int dimensiony() const { 1209 return dimy; 1210 } 1211 //! access function 1212 int dimension() const { 1213 return posterior().dimension(); 1214 } 1215 //! access function 1189 1216 const RV& _yrv() const { 1190 1217 return yrv; … … 1196 1223 //! access to rv of the posterior 1197 1224 void set_rv ( const RV &rv ) { 1198 const_cast<epdf&> (posterior()).set_rv ( rv );1225 const_cast<epdf&> ( posterior() ).set_rv ( rv ); 1199 1226 } 1200 1227 //! access function 1201 1228 void set_dim ( int dim ) { 1202 const_cast<epdf&> (posterior()).set_dim ( dim );1229 const_cast<epdf&> ( posterior() ).set_dim ( dim ); 1203 1230 } 1204 1231 //! return internal log-likelihood of the last data vector … … 1220 1247 virtual void set_options ( const string &opt ) { 1221 1248 if ( opt.find ( "logfull" ) != string::npos ) { 1222 const_cast<epdf&> (posterior()).set_log_level(10) ;1249 const_cast<epdf&> ( posterior() ).set_log_level ( 10 ) ; 1223 1250 } else { 1224 1251 if ( opt.find ( "logbounds" ) != string::npos ) { 1225 const_cast<epdf&> (posterior()).set_log_level(2) ;1252 const_cast<epdf&> ( posterior() ).set_log_level ( 2 ) ; 1226 1253 } else { 1227 const_cast<epdf&> (posterior()).set_log_level(1) ;1254 const_cast<epdf&> ( posterior() ).set_log_level ( 1 ) ; 1228 1255 } 1229 1256 if ( opt.find ( "logll" ) != string::npos ) { … … 1238 1265 //! * x = level of the posterior (typically 0/1/2 for nothing/mean/bounds) 1239 1266 virtual void log_register ( logger &L, const string &prefix = "" ) { 1240 root::log_register (L,prefix);1241 1242 const_cast<epdf&> (posterior()).log_register(L, prefix+L.prefix_sep()+"apost");1243 1244 if ( (log_level) > 0){1245 logrec->ids.set_size (1);1246 logrec->ids (0) = L.add_vector(RV("",1), prefix+L.prefix_sep()+"ll");1267 root::log_register ( L, prefix ); 1268 1269 const_cast<epdf&> ( posterior() ).log_register ( L, prefix + L.prefix_sep() + "apost" ); 1270 1271 if ( ( log_level ) > 0 ) { 1272 logrec->ids.set_size ( 1 ); 1273 logrec->ids ( 0 ) = L.add_vector ( RV ( "", 1 ), prefix + L.prefix_sep() + "ll" ); 1247 1274 } 1248 1275 } … … 1250 1277 virtual void log_write ( ) const { 1251 1278 posterior().log_write(); 1252 if (log_level >0) { logrec->L.logit ( logrec->ids ( 0 ), ll );} 1279 if ( log_level > 0 ) { 1280 logrec->L.logit ( logrec->ids ( 0 ), ll ); 1281 } 1253 1282 } 1254 1283 //!@} … … 1264 1293 shared_ptr<RV> r3 = UI::build<RV> ( set, "rv", UI::optional ); 1265 1294 if ( r3 ) { 1266 set_rv (*r3);1267 } 1268 1295 set_rv ( *r3 ); 1296 } 1297 1269 1298 string opt; 1270 1299 if ( UI::get ( opt, set, "options", UI::optional ) ) {