Changeset 737 for library/bdm/estim/arx.cpp
- Timestamp:
- 11/25/09 12:14:38 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/estim/arx.cpp
r723 r737 3 3 4 4 void ARX::bayes_weighted ( const vec &yt, const vec &cond, const double w ) { 5 6 bdm_assert_debug (yt.length()>=dimy,"ARX::bayes yt is smaller then dimc");7 bdm_assert_debug (cond.length()>=dimc,"ARX::bayes cond is smaller then dimc");5 6 bdm_assert_debug ( yt.length() >= dimy, "ARX::bayes yt is smaller then dimc" ); 7 bdm_assert_debug ( cond.length() >= dimc, "ARX::bayes cond is smaller then dimc" ); 8 8 double lnc; 9 9 //cache 10 ldmat &V =est._V();11 double &nu =est._nu();12 13 dyad.set_subvector (0,yt);14 dyad.set_subvector (dimy,cond);10 ldmat &V = est._V(); 11 double &nu = est._nu(); 12 13 dyad.set_subvector ( 0, yt ); 14 dyad.set_subvector ( dimy, cond ); 15 15 // possible "1" is there from the beginning 16 16 17 17 if ( frg < 1.0 ) { 18 18 est.pow ( frg ); // multiply V and nu 19 19 20 20 21 21 //stabilize 22 ldmat V0 =alter_est._V(); //$ copy23 double &nu0 =alter_est._nu();24 25 V0 *=(1-frg);22 ldmat V0 = alter_est._V(); //$ copy 23 double &nu0 = alter_est._nu(); 24 25 V0 *= ( 1 - frg ); 26 26 V += V0; //stabilization 27 nu += (1-frg)*nu0;28 27 nu += ( 1 - frg ) * nu0; 28 29 29 // recompute loglikelihood of new "prior" 30 30 if ( evalll ) { … … 50 50 double lll; 51 51 vec dyad_p = dyad; 52 dyad_p.set_subvector (0,yt);52 dyad_p.set_subvector ( 0, yt ); 53 53 54 54 if ( frg < 1.0 ) { … … 101 101 mlstudent* ARX::predictor_student ( ) const { 102 102 const ldmat &V = posterior()._V(); 103 103 104 104 mat mu ( dimy, V.rows() - dimy ); 105 105 mat R ( dimy, dimy ); … … 114 114 115 115 116 if ( have_constant ) { // no constant term116 if ( have_constant ) { // no constant term 117 117 //Assume the constant term is the last one: 118 118 if ( mu.cols() > 1 ) { … … 206 206 // rgrlen - including constant!!! 207 207 dimc = rrv->_dsize(); 208 208 209 209 yrv = *yrv_; 210 210 rvc = *rrv; 211 211 212 212 string opt; 213 if ( UI::get (opt, set, "options", UI::optional) ) {214 BM::set_options (opt);213 if ( UI::get ( opt, set, "options", UI::optional ) ) { 214 BM::set_options ( opt ); 215 215 } 216 216 int constant; 217 if ( !UI::get(constant, set, "constant", UI::optional)){218 have_constant =true;219 } else { 220 have_constant =constant>0;221 } 222 int rgrlen = dimc +int(have_constant==true);217 if ( !UI::get ( constant, set, "constant", UI::optional ) ) { 218 have_constant = true; 219 } else { 220 have_constant = constant > 0; 221 } 222 int rgrlen = dimc + int ( have_constant == true ); 223 223 224 224 //init 225 shared_ptr<egiw> pri =UI::build<egiw>(set, "prior", UI::optional);226 if ( pri) {227 bdm_assert (pri->_dimx()==dimy,"prior is not compatible");228 bdm_assert (pri->_V().rows()==dimy+rgrlen,"prior is not compatible");229 est.set_parameters ( pri->_dimx(),pri->_V(), pri->_nu());230 } else{231 est.set_parameters ( dimy, zeros(dimy+rgrlen));232 set_prior_default (est);233 } 234 235 shared_ptr<egiw> alt =UI::build<egiw>(set, "alternative", UI::optional);236 if ( alt) {237 bdm_assert (alt->_dimx()==dimy,"alternative is not compatible");238 bdm_assert (alt->_V().rows()==dimy+rgrlen,"alternative is not compatible");239 alter_est.set_parameters ( alt->_dimx(),alt->_V(), alt->_nu());225 shared_ptr<egiw> pri = UI::build<egiw> ( set, "prior", UI::optional ); 226 if ( pri ) { 227 bdm_assert ( pri->_dimx() == dimy, "prior is not compatible" ); 228 bdm_assert ( pri->_V().rows() == dimy + rgrlen, "prior is not compatible" ); 229 est.set_parameters ( pri->_dimx(), pri->_V(), pri->_nu() ); 230 } else { 231 est.set_parameters ( dimy, zeros ( dimy + rgrlen ) ); 232 set_prior_default ( est ); 233 } 234 235 shared_ptr<egiw> alt = UI::build<egiw> ( set, "alternative", UI::optional ); 236 if ( alt ) { 237 bdm_assert ( alt->_dimx() == dimy, "alternative is not compatible" ); 238 bdm_assert ( alt->_V().rows() == dimy + rgrlen, "alternative is not compatible" ); 239 alter_est.set_parameters ( alt->_dimx(), alt->_V(), alt->_nu() ); 240 240 } else { 241 241 alter_est = est; … … 247 247 248 248 set_parameters ( frg ); 249 249 250 250 //name results (for logging) 251 shared_ptr<RV> rv_par =UI::build<RV>(set, "rv_param",UI::optional );252 if ( !rv_par){251 shared_ptr<RV> rv_par = UI::build<RV> ( set, "rv_param", UI::optional ); 252 if ( !rv_par ) { 253 253 est.set_rv ( RV ( "{theta r }", vec_2 ( dimy*rgrlen, dimy*dimy ) ) ); 254 254 } else {