Changeset 685
- Timestamp:
- 10/29/09 23:23:56 (15 years ago)
- Files:
-
- 7 modified
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/mex/estimator.cpp
r676 r685 145 145 Setting &S=Cfg; 146 146 for ( int i=0; i<Es.length(); i++ ) { 147 try { 148 UI::get ( Ename, S["estimators"][i], "name" ); 149 } catch ( UIException e ) { 147 if (!UI::get ( Ename, S["estimators"][i], "name" ,UI::optional)){ 150 148 Ename="Est"+num2str ( i ); 151 149 } … … 157 155 vec dt=zeros ( Ds->_drv()._dsize() ); //data variable 158 156 Array<datalink*> Dls ( Es.length() ); 157 Array<datalink*> Dlsc ( Es.length() ); 159 158 Array<datalink_buffered*> Dls_buf (0); 160 159 for ( int i=0; i<Es.length(); i++ ) { 161 if (Es ( i )->_drv().mint()<0){ 160 //connect actual data 161 Dls ( i ) = new datalink ( Es ( i )->_yrv(),Ds->_drv() ); //datalink between a datasource and estimator 162 //connect data in condition 163 if (Es ( i )->_rvc().mint()<0){ 162 164 //delayed values are required 163 165 … … 167 169 Dls_buf(ith_buf) = new datalink_buffered(); 168 170 //add dl to list of buffered DS 169 Dls (i) = Dls_buf(ith_buf);170 Dls (i)->set_connection ( Es ( i )->_drv(),Ds->_drv() ); //datalink between a datasource and estimator171 Dlsc(i) = Dls_buf(ith_buf); 172 Dlsc(i)->set_connection ( Es ( i )->_rvc(),Ds->_drv() ); //datalink between a datasource and estimator 171 173 172 174 } else { 173 Dls ( i ) = new datalink ( Es ( i )->_drv(),Ds->_drv() ); //datalink between a datasource and estimator175 Dlsc ( i ) = new datalink ( Es ( i )->_rvc(),Ds->_drv() ); //datalink between a datasource and estimator 174 176 } 175 177 } … … 180 182 181 183 for ( int i=0; i<Es.length(); i++ ) { 182 Es ( i )->bayes ( Dls ( i )->pushdown ( dt ) ); // update estimates184 Es ( i )->bayes ( Dls ( i )->pushdown ( dt ), Dlsc(i) ->pushdown(dt) ); // update estimates 183 185 Es ( i )->log_write (); 184 186 } … … 204 206 } 205 207 #endif 206 for (int i=0;i<Dls.length(); i++){delete Dls(i); }208 for (int i=0;i<Dls.length(); i++){delete Dls(i); delete Dlsc(i);} 207 209 } -
applications/bdmtoolbox/mex/merger.cpp
r622 r685 58 58 #endif 59 59 // Sources 60 Array<shared_ptr<mpdf> > Sources; 61 //abuse Mer to store sources 62 Setting& _Sources = Cfg.lookup ( "Sources" ); 63 int Slen = _Sources.getLength(); 64 Sources.set_size ( Slen ); 65 for ( int i = 0; i < Slen; i++ ) { 66 try { 67 shared_ptr<mpdf> mtmp = UI::build<mpdf> ( _Sources, i ); 68 Sources ( i ) = mtmp; 69 } catch ( UIException ) { 70 // it is not mpdf - see if it is epdf 71 try { 72 shared_ptr<epdf> etmp = UI::build<epdf> ( _Sources, i ); 73 if ( etmp ) { 74 Sources ( i ) = new mepdf ( etmp ); // hopefully OK 75 } 76 } catch ( UIException &e ) { 77 it_error ( "No mpdfs or epdfs found! " + string ( e.what() ) ); 78 } catch ( std::exception e ) { 79 it_error ( "Error in UI at " + _Sources[i].getPath() ); 80 } 81 } catch ( std::exception &e ) { 82 it_error ( "Error in UI at " + _Sources[i].getPath() ); 83 } 84 } 85 60 Array<shared_ptr<mpdf> > Sources; 61 UI::get(Sources, Cfg, "Sources", UI::compulsory); 86 62 shared_ptr<merger_base> Merger = UI::build<merger_base> ( Cfg, "Merger" ); 87 63 88 64 // Support 89 try { 90 shared_ptr<rectangular_support> RecSup = UI::build<rectangular_support> ( Cfg, "Support" ); 65 try{ 66 shared_ptr<rectangular_support> RecSup = UI::build<rectangular_support> ( Cfg, "Support" ,UI::optional); 67 if(RecSup){ 91 68 Merger->set_support ( *RecSup ); 92 } catch ( UIException &e ) { 93 shared_ptr<discrete_support> DisSup = UI::build<discrete_support> ( Cfg, "Support" ); 94 Merger->set_support ( *DisSup ); 69 } 70 } catch (UIException &e) { 71 shared_ptr<discrete_support> DisSup = UI::build<discrete_support> ( Cfg, "Support", UI::optional ); 72 if (DisSup){ 73 Merger->set_support ( *DisSup ); 74 } else{bdm_error("Support not defined");} 95 75 } 96 76 // COMPUTE RESULTS -
library/bdm/base/bdmbase.h
r682 r685 594 594 } 595 595 } 596 void log_write() const { 597 if (log_level>0) { 598 logrec->L.logit( logrec->ids(0), mean() ); 599 } 600 if (log_level>2) { 601 vec lb; vec ub; 602 qbounds(lb,ub); 603 logrec->L.logit( logrec->ids(1), lb ); 604 logrec->L.logit( logrec->ids(2), ub ); 605 } 606 } 596 607 //!@} 597 608 … … 951 962 public: 952 963 //! default constructors 953 DS() :Drv(), Urv(),Yrv() {log_level=1;};964 DS() : dtsize(0),utsize(0),ytsize(0),Drv(), Urv(),Yrv() {log_level=1;}; 954 965 955 966 //! 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(). … … 989 1000 if (log_level >0){ 990 1001 logrec->ids.set_size(2); 991 logrec->ids(0) = logrec->L.add ( Yrv, "");992 logrec->ids(1) = logrec->L.add ( Urv, "");1002 logrec->ids(0) = logrec->L.add ( Yrv, prefix ); 1003 logrec->ids(1) = logrec->L.add ( Urv, prefix ); 993 1004 } 994 1005 } … … 1194 1205 //!@} 1195 1206 void from_setting ( const Setting &set ) { 1196 shared_ptr<RV> r = UI::build<RV> ( set, " drv", UI::optional );1207 shared_ptr<RV> r = UI::build<RV> ( set, "yrv", UI::optional ); 1197 1208 if ( r ) { 1198 1209 set_yrv ( *r ); 1199 1210 } 1211 shared_ptr<RV> r2 = UI::build<RV> ( set, "rvc", UI::optional ); 1212 if ( r2 ) { 1213 rvc = *r2; 1214 } 1215 shared_ptr<RV> r3 = UI::build<RV> ( set, "rv", UI::optional ); 1216 if ( r3 ) { 1217 set_rv(*r3); 1218 } 1219 1200 1220 string opt; 1201 1221 if ( UI::get ( opt, set, "options", UI::optional ) ) { -
library/bdm/base/loggers.h
r676 r685 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 itf = "" ) :logger("_"), maxlen ( maxlen0 ), ind ( 0 ), vectors ( 0 ), itfilename ( itf ) {} 39 39 40 40 //!Default constructor 41 memlog() : logger(" ."), maxlen ( 0 ), ind ( 0 ), vectors ( 0 ) {}41 memlog() : logger("_"), maxlen ( 0 ), ind ( 0 ), vectors ( 0 ) {} 42 42 43 43 //! Initialize storage -
library/bdm/mex/mex_BM.h
r679 r685 80 80 mxArray *in[2]; 81 81 in[0] = data; 82 in[1] = mxCreateDoubleMatrix( dt.size(), 1, mxREAL);83 vec2mxArray( dt, in[1]);82 in[1] = mxCreateDoubleMatrix(yt.size(), 1, mxREAL); 83 vec2mxArray(yt, in[1]); 84 84 mexCallMATLAB(1, &tmp, 2, in, (name+"_bayes").c_str()); 85 85 old = data; -
library/bdm/mex/mex_datasource.h
r676 r685 91 91 \code 92 92 system={ 93 type="mexDS";93 class="mexDS"; 94 94 step_name=""; // name of function to call 95 95 input_name=""; // name of workspace variable where inputs are written 96 rv_out= {class='RV',...} // identification of outputs97 rv_in= {class='RV',...} // identification of inputs96 yrv = {class='RV',...} // identification of outputs 97 urv = {class='RV',...} // identification of inputs 98 98 }; 99 99 \endcode … … 106 106 UI::get(input_name, set, "input_name", UI::compulsory); 107 107 108 shared_ptr<RV> ry = UI::build<RV> ( set, " rv_out", UI::compulsory );109 shared_ptr<RV> ru = UI::build<RV> ( set, " rv_in", UI::compulsory);108 shared_ptr<RV> ry = UI::build<RV> ( set, "yrv", UI::compulsory ); 109 shared_ptr<RV> ru = UI::build<RV> ( set, "urv", UI::compulsory); 110 110 111 dtsize=ry->_dsize();111 ytsize=ry->_dsize(); 112 112 utsize=ru->_dsize(); 113 113 dtsize = ytsize+utsize; 114 114 115 set_drv(*ry, *ru); 116 validate(); 115 117 } 116 118 117 119 void step() { 118 120 mxArray* tmp; 119 mxArray* tmp2;121 mxArray* dummy=NULL; 120 122 // write inputs to variable input_name 121 123 mxArray* mxinp= mexGetVariable ( "global", input_name.c_str()) ; 124 if (mxinp){ 125 if((int)mxGetM(mxinp)!=utsize || (int)mxGetN(mxinp)!=utsize) { 126 // mxinp is invalid - create new one 127 mxDestroyArray(mxinp); 128 mxinp=mxCreateDoubleMatrix(utsize,1,mxREAL); 129 } 130 131 } else { 132 mxinp=mxCreateDoubleMatrix(utsize,1,mxREAL); 133 } 122 134 vec2mxArray(ut, mxinp); 135 mexPutVariable("global",input_name.c_str(),mxinp); 123 136 // call function step_name 124 mexCallMATLAB(1, &tmp, 0, (mxArray **) & tmp2, step_name.c_str());137 mexCallMATLAB(1, &tmp, 0, (mxArray **) &dummy, step_name.c_str()); 125 138 // save its results 126 dt=mxArray2vec(tmp); 139 bdm_assert_debug((int)mxGetM(tmp)==ytsize || (int)mxGetN(tmp)==ytsize,"mexDS.step() expected return vector of length " + num2str(dtsize) + 140 "got vector " + num2str((int)mxGetM(tmp)) + "x" + num2str((int)mxGetN(tmp))); 141 //write y 142 dt.set_subvector(0,mxArray2vec(tmp)); 143 //write u 144 dt.set_subvector(ytsize,ut); 127 145 } 128 void write(const vec &ut0){ ut=ut0;} 129 void getdata(vec &dt_out) const {dt_out = dt; } 146 void write(const vec &ut0){ 147 bdm_assert_debug(ut0.length()==ut.length(),"mexDS: Incompatible input vector"); 148 ut=ut0; 149 } 150 void getdata(vec &dt_out) const { 151 bdm_assert_debug(dt_out.length()==dt.length(),"mexDS: Incompatible output vector"); 152 dt_out = dt; 153 } 130 154 155 void validate() { 156 dt=zeros(dtsize); 157 ut=zeros(utsize); 158 } 131 159 132 160 // TODO dodelat void to_setting( Setting &set ) const; -
library/bdm/mex/mex_logger.h
r665 r685 62 62 istart = 0; 63 63 for ( int j = 0; j < entries ( i ).length(); j++ ) { // same for as in add!!! 64 vec_name = names ( i ) + entries ( i ).name ( j );64 vec_name = names ( i ) +prefix_sep()+ entries ( i ).name ( j ); 65 65 iend = istart + entries ( i ).size ( j ) - 1; 66 66 M = vectors ( i ).get_cols ( istart, iend );