188 | | std::string scalarname ( int scalat ) const { |
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 | | }; |
196 | | //now id is the id of variable of interest |
197 | | if ( size ( id ) == 1 ) |
198 | | return NAMES ( ids ( id ) ); |
199 | | else |
200 | | return NAMES ( ids ( id ) ) + "_" + num2str ( scalat - scalid ); |
201 | | |
202 | | } |
| 188 | std::string scalarname ( int scalat ) const; |
| 189 | |
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 | | } |
| 316 | virtual int add_vector ( const RV &rv, string prefix = "" ); |
| 317 | |
| 318 | virtual int add_setting ( const string &prefix ); |
624 | | void log_register ( logger &L, const string &prefix ) { |
625 | | RV r; |
626 | | if ( isnamed() ) { |
627 | | r = _rv(); |
628 | | } else { |
629 | | r = RV ( "", dimension() ); |
630 | | }; |
631 | | root::log_register ( L, prefix ); |
632 | | |
633 | | // log full data |
634 | | if ( log_level == 10 ) { |
635 | | logrec->ids.set_size ( 1 ); |
636 | | logrec->ids ( 0 ) = logrec->L.add_setting ( prefix ); |
637 | | } else { |
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" ); |
642 | | } |
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" ); |
646 | | } |
647 | | } |
648 | | } |
649 | | void log_write() const { |
650 | | if ( log_level == 10 ) { |
651 | | to_setting ( logrec->L.log_to_setting ( logrec->ids ( 0 ) ) ); |
652 | | } else { |
653 | | if ( log_level > 0 ) { |
654 | | logrec->L.log_vector ( logrec->ids ( 0 ), mean() ); |
655 | | } |
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 ); |
662 | | } |
663 | | } |
664 | | } |
| 582 | void log_register ( logger &L, const string &prefix ); |
| 583 | |
| 584 | void log_write() const; |
870 | | void set_connection ( const RV &rv, const RV &rv_up ) { |
871 | | // create link between up and down |
872 | | datalink_part::set_connection ( rv, rv_up.remove_time() ); // only non-delayed version |
873 | | |
874 | | // create rvs of history |
875 | | // we can store only what we get in rv_up - everything else is removed |
876 | | ivec valid_ids = rv.findself_ids ( rv_up ); |
877 | | RV rv_hist = rv.subselect ( find ( valid_ids >= 0 ) ); // select only rvs that are in rv_up |
878 | | RV rv_hist0 = rv_hist.remove_time(); // these RVs will form history at time =0 |
879 | | // now we need to know what is needed from Up |
880 | | rv_hist = rv_hist.expand_delayes(); // full regressor - including time 0 |
881 | | Hrv = rv_hist.subt ( rv_hist0 ); // remove time 0 |
882 | | history = zeros ( Hrv._dsize() ); |
883 | | |
884 | | // decide if we need to copy val to history |
885 | | if ( Hrv._dsize() > 0 ) { |
886 | | v2h_up = rv_hist0.dataind ( rv_up ); // indeces of elements of rv_up to be copied |
887 | | } // else v2h_up is empty |
888 | | |
889 | | Hrv.dataind ( rv, h2v_hist, h2v_down ); |
890 | | |
891 | | downsize = v2v_down.length() + h2v_down.length(); |
892 | | upsize = v2v_up.length(); |
893 | | } |
| 790 | void set_connection ( const RV &rv, const RV &rv_up ); |
| 791 | |
895 | | void set_history ( const RV& rv1, const vec &hist0 ) { |
896 | | bdm_assert ( rv1._dsize() == hist0.length(), "hist is not compatible with given rv1" ); |
897 | | ivec ind_H; |
898 | | ivec ind_h0; |
899 | | 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 |
901 | | } |
| 793 | void set_history ( const RV& rv1, const vec &hist0 ); |
1062 | | virtual void log_register ( logger &L, const string &prefix ) { |
1063 | | bdm_assert ( ytsize == Yrv._dsize(), "invalid DS: ytsize (" + num2str ( ytsize ) + ") different from Drv " + num2str ( Yrv._dsize() ) ); |
1064 | | bdm_assert ( utsize == Urv._dsize(), "invalid DS: utsize (" + num2str ( utsize ) + ") different from Urv " + num2str ( Urv._dsize() ) ); |
1065 | | |
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 ); |
1072 | | } |
1073 | | } |
| 954 | virtual void log_register ( logger &L, const string &prefix ); |
1247 | | virtual void set_options ( const string &opt ) { |
1248 | | if ( opt.find ( "logfull" ) != string::npos ) { |
1249 | | const_cast<epdf&> ( posterior() ).set_log_level ( 10 ) ; |
1250 | | } else { |
1251 | | if ( opt.find ( "logbounds" ) != string::npos ) { |
1252 | | const_cast<epdf&> ( posterior() ).set_log_level ( 2 ) ; |
1253 | | } else { |
1254 | | const_cast<epdf&> ( posterior() ).set_log_level ( 1 ) ; |
1255 | | } |
1256 | | if ( opt.find ( "logll" ) != string::npos ) { |
1257 | | log_level = 1; |
1258 | | } |
1259 | | } |
1260 | | } |
| 1119 | virtual void set_options ( const string &opt ); |
1266 | | virtual void log_register ( logger &L, const string &prefix = "" ) { |
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" ); |
1274 | | } |
1275 | | } |
| 1125 | virtual void log_register ( logger &L, const string &prefix = "" ); |
| 1126 | |