- Timestamp:
- 05/26/10 23:33:28 (14 years ago)
- Location:
- library/bdm
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/estim/arx.cpp
r990 r996 3 3 4 4 void ARX::bayes_weighted ( const vec &yt, const vec &cond, const double w ) { 5 6 5 bdm_assert_debug ( yt.length() == dimy, "ARX::bayes yt is of size "+num2str(yt.length())+" expected dimension is "+num2str(dimy) ); 7 6 bdm_assert_debug ( cond.length() == rgrlen , "ARX::bayes cond is of size "+num2str(cond.length())+" expected dimension is "+num2str(rgrlen) ); 7 8 BMEF::bayes_weighted(yt,cond,w); //potential discount scheduling 9 8 10 double lnc; 9 11 //cache … … 216 218 ivec ARX::structure_est_LT ( egiw est0 ) { 217 219 //some stuff with beliefs etc. 218 // ivec ind = bdm::straux1(V,nu, est0._V(), est0._nu()); 219 return ivec();//ind; 220 ivec belief = vec_1 ( 2 ); // default belief 221 int nbest = 1; // nbest: how many regressors are returned 222 int nrep = 5; // nrep: number of random repetions of structure estimation 223 double lambda = 0.9; 224 int k = 2; 225 226 Array<str_aux> o2; 227 228 ivec ind = bdm::straux1(est._V(),est._nu(), est0._V(), est0._nu(), belief, nbest, nrep, lambda, k, o2); 229 230 return ind; 220 231 } 221 232 -
library/bdm/estim/arx.h
r990 r996 105 105 //! Smarter structure estimation by Ludvik Tesar.\return indices of accepted regressors. 106 106 ivec structure_est_LT ( egiw Eg0 ); 107 //! reduce to 108 void reduce_structure(ivec &inds_in_V){ 109 ldmat V = posterior()._V(); 110 if (max(inds_in_V)>=V.rows()) {bdm_error("Incompatible structure");} 111 112 ldmat newV(V,inds_in_V); 113 est.set_parameters(dimy,newV, posterior()._nu()); 114 validate(); 115 } 107 116 //!@} 108 117 … … 138 147 BMEF::validate(); 139 148 est.validate(); 140 //if dimc not set set it from V 141 if(dimy>0) {//statistics is assigned 142 if (posterior()._V().rows()>dimy) {//statistics is assigned 143 rgrlen=posterior()._V().rows() - dimy - int ( have_constant == true ); 144 } 145 } else{ 146 bdm_error("No posterior or yrv assigned matrix assigned"); 147 } 148 dimc =rgrlen; 149 150 if(est._dimx()==0) { // no prior 149 150 // When statistics is defined, it has priority 151 if(posterior()._dimx()>0) {//statistics is assigned 152 dimy = posterior()._dimx()>0; 153 rgrlen=posterior()._V().rows() - dimy - int ( have_constant == true ); 154 dimc = rgrlen; 155 } else{ // statistics is not assigned - build it from dimy and rgrlen 156 bdm_assert(dimy>0,"No way to validate egiw: empty statistics and empty dimy"); 151 157 est.set_parameters(dimy, zeros(dimy+rgrlen+int(have_constant==true))); 152 158 set_prior_default(est); … … 213 219 214 220 221 215 222 //////////////////// 216 223 template<class sq_T> -
library/bdm/estim/arx_straux.h
r737 r996 48 48 49 49 50 //! R plication of Ludvik Tesar original straux1 from mixtools straux150 //! Replication of Ludvik Tesar original straux1 from mixtools straux1 51 51 ivec straux1 ( ldmat Ld, double nu, ldmat Ld0, double nu0, ivec belief, int nbest, int max_nrep, double lambda, int order_k, Array<str_aux> &rgrsout ); 52 52 -
library/bdm/itpp_ext.cpp
r942 r996 55 55 } 56 56 57 //! return vector of elements at positions given by indexlist 57 58 vec get_vec ( const vec &v, const ivec &indexlist ) { 58 59 int size = indexlist.size(); -
library/bdm/stat/exp_family.cpp
r992 r996 404 404 } 405 405 406 // mat egamma::sample ( int N ) const {407 // mat Smp ( rv.count(),N );408 // int i,j;409 //410 // for ( i=0; i<rv.count(); i++ ) {411 // GamRNG.setup ( alpha ( i ),beta ( i ) );412 //413 // for ( j=0; j<N; j++ ) {414 // Smp ( i,j ) = GamRNG();415 // }416 // }417 //418 // return Smp;419 // }420 406 421 407 double egamma::evallog ( const vec &val ) const { -
library/bdm/stat/exp_family.h
r992 r996 81 81 //! cached value of lognc() in the previous step (used in evaluation of \c ll ) 82 82 double last_lognc; 83 //! factor k = [0..1] for scheduling of forgetting factor: \f$ frg_t = (1-k) * frg_{t-1} + k \f$, default 0 84 double frg_sched_factor; 83 85 public: 84 86 //! Default constructor (=empty constructor) 85 BMEF ( double frg0 = 1.0 ) : BM (), frg ( frg0 ) {}87 BMEF ( double frg0 = 1.0 ) : BM (), frg ( frg0 ), last_lognc(0.0),frg_sched_factor(0.0) {} 86 88 //! Copy constructor 87 BMEF ( const BMEF &B ) : BM ( B ), frg ( B.frg ), last_lognc ( B.last_lognc ) {}89 BMEF ( const BMEF &B ) : BM ( B ), frg ( B.frg ), last_lognc ( B.last_lognc ),frg_sched_factor(B.frg_sched_factor) {} 88 90 //!get statistics from another model 89 91 virtual void set_statistics ( const BMEF* BM0 ) NOT_IMPLEMENTED_VOID; 90 92 91 93 //! Weighted update of sufficient statistics (Bayes rule) 92 virtual void bayes_weighted ( const vec &data, const vec &cond = empty_vec, const double w = 1.0 ) {}; 94 virtual void bayes_weighted ( const vec &data, const vec &cond = empty_vec, const double w = 1.0 ) { 95 if (frg_sched_factor>0) {frg = frg*(1-frg_sched_factor)+frg_sched_factor;} 96 }; 93 97 //original Bayes 94 98 void bayes ( const vec &yt, const vec &cond = empty_vec ); … … 102 106 BM::to_setting( set ); 103 107 UI::save(frg, set, "frg"); 108 UI::save( frg_sched_factor, set, "frg_sched_factor" ); 104 109 } 105 110 … … 108 113 if ( !UI::get ( frg, set, "frg" ) ) 109 114 frg = 1.0; 115 UI::get ( frg_sched_factor, set, "frg_sched_factor",UI::optional ); 110 116 } 111 117