- Timestamp:
- 08/18/11 16:02:53 (13 years ago)
- Location:
- library
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/itpp/CMakeLists.txt
r812 r1383 13 13 SET(itpp_math base/math/elem_math.cpp base/math/error.cpp base/math/integration.cpp base/math/misc.cpp) 14 14 15 SET(itpp_signal signal/fastica.cpp signal/filter.cpp signal/filter_design.cpp signal/freq_filt.cpp signal/poly.cpp signal/resampling.cpp signal/source.cpp signal/transforms.cpp signal/window.cpp) 16 17 SET(itpp_stat stat/misc_stat.cpp stat/mog_diag.cpp stat/mog_diag_em.cpp stat/mog_diag_kmeans.cpp stat/mog_generic.cpp) 18 15 19 # add BDMLIB compile flag 16 20 #ADD_DEFINITIONS(-DNDEBUG) 17 21 18 22 # Normal BDM library 19 add_library (itpp STATIC ${itpp_base} ${itpp_algebra} ${itpp_bessel} ${itpp_math} )23 add_library (itpp STATIC ${itpp_base} ${itpp_algebra} ${itpp_bessel} ${itpp_math} ${itpp_signal} ${itpp_stat}) -
library/bdm/estim/arx.h
r1359 r1383 311 311 312 312 void bayes ( const vec &val, const vec &cond ) { 313 // fill window 314 Y.append_col(val); 315 Cond.append_col(cond); 316 if (Y.cols()>win_length){ 317 // shift the buffer 318 Y=Y.get_cols(1,Y.cols()-1); 319 Cond=Cond.get_cols(1,Cond.cols()-1); 313 314 if(cond.size()>0) 315 { 316 // fill window 317 Y.append_col(val); 318 Cond.append_col(cond); 319 if (Y.cols()>win_length){ 320 // shift the buffer 321 Y=Y.get_cols(1,Y.cols()-1); 322 Cond=Cond.get_cols(1,Cond.cols()-1); 323 } 324 325 est._V()=V0; 326 est._nu()=nu0; 327 for ( int t = 0; t < Y.cols(); t++ ) { 328 ARX::bayes ( Y.get_col ( t ), Cond.get_col ( t ) ); 329 } 330 } 331 else 332 { 333 Y.append_col(val); 334 335 if (Y.cols()>win_length){ 336 // shift the buffer 337 Y=Y.get_cols(1,Y.cols()-1); 338 } 339 340 est._V()=V0; 341 est._nu()=nu0; 342 343 for ( int t = 0; t < Y.cols(); t++ ) { 344 ARX::bayes (Y.get_col ( t )); 345 } 320 346 } 321 347 322 est._V()=V0; 323 est._nu()=nu0; 324 for ( int t = 0; t < Y.cols(); t++ ) { 325 ARX::bayes ( Y.get_col ( t ), Cond.get_col ( t ) ); 326 } 327 328 } 348 } 349 329 350 void from_setting(const Setting &set){ 330 351 ARX::from_setting(set); -
library/bdm/stat/exp_family.h
r1196 r1383 28 28 //! Global Gamma_RNG 29 29 extern Gamma_RNG GamRNG; 30 30 31 31 32 /*! -
library/tests/tutorial/arx_simple.cpp
r1323 r1383 1 1 #include "estim/arx.h" 2 #include <vector> 3 #include <iostream> 4 #include <fstream> 2 5 using namespace bdm; 3 6 4 7 // estimation of AR(0) model 5 int main() { 8 int main(){ 9 //data 10 vector<vector<vector<string>>> string_lists; 11 string_lists.push_back(vector<vector<string>>()); 12 string_lists.push_back(vector<vector<string>>()); 13 string_lists.push_back(vector<vector<string>>()); 14 15 char* file_strings[3] = {"c:\\ar_normal.txt", "c:\\ar_student.txt", "c:\\ar_cauchy.txt"}; 16 17 18 for(int i = 0;i<3;i++) 19 { 20 ifstream myfile(file_strings[i]); 21 if (myfile.is_open()) 22 { 23 while ( myfile.good() ) 24 { 25 string line; 26 getline(myfile,line); 27 28 vector<string> parsed_line; 29 while(line.find(',') != string::npos) 30 { 31 int loc = line.find(','); 32 parsed_line.push_back(line.substr(0,loc)); 33 line.erase(0,loc+1); 34 } 35 36 string_lists[i].push_back(parsed_line); 37 } 38 myfile.close(); 39 } 40 } 41 6 42 //prior 7 mat V0 = 0.00001 * eye ( 3 ); 8 V0 ( 0, 0 ) = 0.1; // 9 ARX Ar; 10 Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments) 11 Ar.set_constant ( false ); 12 Ar.validate(); 13 // forgetting is default: 1.0 14 Ar.bayes_batch ( randn ( 1, 3400 ), randn(2,3400) ); 43 mat V0 = 0.0001 * eye ( 3 ); 44 //V0 ( 0, 0 ) = 0.1; // 15 45 16 cout << "Expected value of Theta is: " << Ar.posterior().mean() << endl; 17 cout << "NC of posterior: " << Ar.posterior().lognc() << endl; 46 for(int j = 0;j<string_lists.size();j++) 47 { 48 49 for(int i = 0;i<string_lists[j].size();i++) 50 { 51 ARX Ar; 52 Ar.set_statistics ( 1, V0 ); //nu is default (set to have finite moments) 53 Ar.set_constant ( false ); 54 Ar.validate(); 55 // forgetting is default: 1.0 56 57 vector<vec> conditions; 58 for(int k = 1;k<string_lists[j][i].size();k++) 59 { 60 vec condition; 61 condition.ins(0,string_lists[j][i][k]); 62 conditions.push_back(condition); 63 64 if(conditions.size()>1) 65 { 66 conditions[k-2].ins(0,string_lists[j][i][k]); 67 68 } 69 70 if(conditions.size()>2) 71 { 72 conditions[k-3].ins(0,string_lists[j][i][k]); 73 74 //cout << conditions[k-3] << endl;// << conditions[k-3].left(1) << conditions[k-3].right(2); 75 76 Ar.bayes(conditions[k-3].left(1),conditions[k-3].right(2)); 77 } 78 } 79 80 ofstream myfile; 81 myfile.open("c:\\classic_ar1.txt",ios::app); 82 myfile << Ar.posterior().mean()[0] << ";"; 83 myfile.close(); 84 85 myfile.open("c:\\classic_ar2.txt",ios::app); 86 myfile << Ar.posterior().mean()[1] << ";"; 87 myfile.close(); 88 89 90 91 } 92 93 ofstream myfile; 94 myfile.open("c:\\classic_ar1.txt",ios::app); 95 myfile << endl; 96 myfile.close(); 97 98 myfile.open("c:\\classic_ar2.txt",ios::app); 99 myfile << endl; 100 myfile.close(); 101 } 18 102 } 103