- Timestamp:
- 05/21/10 00:44:04 (15 years ago)
- Location:
- library/bdm
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/estim/arx.cpp
r896 r964 4 4 void ARX::bayes_weighted ( const vec &yt, const vec &cond, const double w ) { 5 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" );6 bdm_assert_debug ( yt.length() == dimy, "ARX::bayes yt is smaller then dimensiony()" ); 7 bdm_assert_debug ( (cond.length() == rgrlen - int(have_constant==true)) , "ARX::bayes dimension of cond is not rgrlen" ); 8 8 double lnc; 9 9 //cache … … 217 217 BMEF::from_setting(set); 218 218 219 shared_ptr<RV> yrv_ = UI::build<RV> ( set, "rv", UI::compulsory ); 220 shared_ptr<RV> rrv = UI::build<RV> ( set, "rgr", UI::compulsory ); 221 dimy = yrv_->_dsize(); 219 RV rrv; 220 UI::get (rrv, set, "rgr", UI::compulsory ); 221 222 dimy = yrv._dsize(); 223 bdm_assert(dimy>0,"ARX::yrv should not be empty"); 222 224 // rgrlen - including constant!!! 223 dimc = rrv->_dsize(); 224 225 yrv = *yrv_; 226 rvc = *rrv; 225 rgrlen = rrv._dsize(); 227 226 228 227 int constant; … … 232 231 have_constant = constant > 0; 233 232 } 234 int rgrlen = dimc + int ( have_constant == true ); 233 dimc = rgrlen; 234 rvc = rrv; 235 rgrlen += int ( have_constant == true ); 235 236 236 237 //init … … 259 260 // frg handled by BMEF 260 261 261 //name results (for logging) 262 shared_ptr<RV> rv_par = UI::build<RV> ( set, "rv_param", UI::optional ); 263 if ( !rv_par ) { 264 est.set_rv ( RV ( "{theta r }", vec_2 ( dimy*rgrlen, dimy*dimy ) ) ); 265 } else { 266 est.set_rv ( *rv_par ); 267 } 268 } 269 270 } 271 262 } 263 264 } 265 -
library/bdm/estim/arx.h
r896 r964 47 47 //! vector of dyadic update 48 48 vec dyad; 49 //! length of the regressor 50 int rgrlen; 49 51 //! posterior density 50 52 egiw est; … … 54 56 //! \name Constructors 55 57 //!@{ 56 ARX ( const double frg0 = 1.0 ) : BMEF ( frg0 ), have_constant ( true ), dyad(), est(), alter_est() {};57 ARX ( const ARX &A0 ) : BMEF ( A0 ), have_constant ( A0.have_constant ), dyad ( A0.dyad ), est ( A0.est ), alter_est ( A0.alter_est ) { };58 ARX ( const double frg0 = 1.0 ) : BMEF ( frg0 ), have_constant ( true ), dyad(), rgrlen(),est(), alter_est() {}; 59 ARX ( const ARX &A0 ) : BMEF ( A0 ), have_constant ( A0.have_constant ), dyad ( A0.dyad ),rgrlen(A0.rgrlen), est ( A0.est ), alter_est ( A0.alter_est ) { }; 58 60 59 61 ARX* _copy() const; … … 115 117 \code 116 118 class = 'ARX'; 117 rv= RV({names_of_dt} ) // description of output variables119 yrv = RV({names_of_dt} ) // description of output variables 118 120 rgr = RV({names_of_regressors}, [-1,-2]} // description of regressor variables 119 121 constant = 1; // 0/1 switch if the constant term is modelled or not … … 125 127 frg = 1.0; // forgetting, default frg=1.0 126 128 127 rv _param = RV({names_of_parameters}}// description of parametetr names128 // default: [" theta_i" and "r_i"]129 rv = RV({names_of_parameters}} // description of parametetr names 130 // default: [""] 129 131 \endcode 130 132 */ … … 133 135 void validate() { 134 136 BMEF::validate(); 135 137 est.validate(); 136 138 //if dimc not set set it from V 137 139 if ( dimc == 0 ) { … … 192 194 193 195 void bayes ( const vec &val, const vec &cond ) { 194 frg = cond ( dimc - 1 ); // last in cond is phi 195 ARX::bayes ( val, cond ); 196 int arx_cond_size=rgrlen -int(have_constant==true); 197 bdm_assert_debug(cond.size()>arx_cond_size, "ARXfrg: Insufficient conditioning, frg not given."); 198 frg = cond ( arx_cond_size ); // the first part after rgrlen 199 ARX::bayes ( val, cond.left(arx_cond_size) ); 196 200 } 197 201 void validate() { -
library/bdm/estim/kalman.h
r963 r964 147 147 R = []; // Matrix R 148 148 prior = struct('class','epdf_offspring'); // Prior density - will be converted to gaussian 149 rvy= RV('some_names'); // Description of required observations149 yrv = RV('some_names'); // Description of required observations 150 150 rvc = RV('some_names'); // Description of required inputs 151 151 \endcode -
library/bdm/estim/particles.h
r951 r964 323 323 //set drv 324 324 325 set_yrv ( bm0->_rv() );326 325 rvc = bm0->_rvc(); 326 dimc = bm0->dimensionc(); 327 327 BM::set_rv(bm0->_rv()); 328 328 yrv=bm0->_yrv(); 329 dimy = bm0->dimensiony(); 329 330 } 330 331 … … 339 340 } 340 341 } 342 if (log_level[logvars]){ 343 for (int i=0; i<particles.length(); i++){ 344 L.add_vector( log_level, logvars, RV ( particles(i)->dimension() ), prefix , i); 345 } 346 } 341 347 }; 342 348 void log_write ( ) const { … … 347 353 if (log_level[logmeans]){ 348 354 for (int i=0; i<particles.length(); i++){ 349 log_level.store( logmeans, particles(i)->posterior().mean(), i); 355 log_level.store( logmeans, particles(i)->posterior().mean(), i); 356 } 357 } 358 if (log_level[logvars]){ 359 for (int i=0; i<particles.length(); i++){ 360 log_level.store( logvars, particles(i)->posterior().variance(), i); 350 361 } 351 362 } -
library/bdm/stat/emix.cpp
r956 r964 53 53 //non-central moment 54 54 vec mom2 = zeros ( dim ); 55 vec mom1 = zeros ( dim ); 56 55 57 for ( int i = 0; i < w.length(); i++ ) { 56 mom2 += w ( i ) * ( component( i )->variance() + pow ( component ( i )->mean(), 2 ) ); 58 vec vi=component( i )->variance(); 59 vec mi=component ( i )->mean(); 60 mom2 += w ( i ) * ( vi + pow ( mi, 2 ) ); 61 mom1 += w(i) * mi; 57 62 } 58 63 //central moment 59 return mom2 - pow ( m ean(), 2 );64 return mom2 - pow ( mom1, 2 ); 60 65 } 61 66 -
library/bdm/stat/exp_family.h
r958 r964 449 449 */ 450 450 void from_setting ( const Setting &set ); 451 //! see egiw::from_setting 451 452 void to_setting ( Setting& set ) const; 452 453 void validate();