Changeset 1064 for library/tests/stresssuite/arx_stress.cpp
- Timestamp:
- 06/09/10 14:00:40 (15 years ago)
- Files:
-
- 1 modified
-
library/tests/stresssuite/arx_stress.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
library/tests/stresssuite/arx_stress.cpp
r766 r1064 17 17 18 18 TEST ( arx_stress ) { 19 // Setup model20 vec th ( "0.8 -0.3 0.4 0.01" );21 int ord = th.length(); //auxiliary variable22 double sqr = 0.1;19 // Setup model 20 vec th ( "0.8 -0.3 0.4 0.01" ); 21 int ord = th.length(); //auxiliary variable 22 double sqr = 0.1; 23 23 24 //Test constructor25 mat V0 = 0.00001 * eye ( ord + 1 );26 V0 ( 0 ) = 1; //27 double nu0 = ord + 5.0;24 //Test constructor 25 mat V0 = 0.00001 * eye ( ord + 1 ); 26 V0 ( 0 ) = 1; // 27 double nu0 = ord + 5.0; 28 28 29 ARX Ar;30 Ar.set_statistics ( 1, V0, nu0 ); // Estimator31 Ar.set_constant ( false );32 Ar.validate();33 const epdf& f_thr = Ar.posterior(); // refrence to posterior of the estimator29 ARX Ar; 30 Ar.set_statistics ( 1, V0, nu0 ); // Estimator 31 Ar.set_constant ( false ); 32 Ar.validate(); 33 const epdf& f_thr = Ar.posterior(); // refrence to posterior of the estimator 34 34 35 //Test estimation36 int ndat = 100; // number of data records37 vec Yt ( ndat ); // Store generated data38 Yt.set_subvector ( 0, randn ( ord ) ); //initial values39 vec rgr ( ord ); // regressor35 //Test estimation 36 int ndat = 100; // number of data records 37 vec Yt ( ndat ); // Store generated data 38 Yt.set_subvector ( 0, randn ( ord ) ); //initial values 39 vec rgr ( ord ); // regressor 40 40 41 //print moments of the prior distribution42 cout << "prior mean: " << f_thr.mean() << endl;43 cout << "prior variance: " << f_thr.variance() << endl;41 //print moments of the prior distribution 42 cout << "prior mean: " << f_thr.mean() << endl; 43 cout << "prior variance: " << f_thr.variance() << endl; 44 44 45 // cycle over time:46 for ( int t = ord; t < ndat; t++ ) {47 //Generate regressor48 for ( int j = 0; j < ( ord ); j++ ) {49 rgr ( j ) = Yt ( t - j - 1 );50 }51 //model52 Yt ( t ) = th * rgr + sqr * NorRNG();45 // cycle over time: 46 for ( int t = ord; t < ndat; t++ ) { 47 //Generate regressor 48 for ( int j = 0; j < ( ord ); j++ ) { 49 rgr ( j ) = Yt ( t - j - 1 ); 50 } 51 //model 52 Yt ( t ) = th * rgr + sqr * NorRNG(); 53 53 54 Ar.bayes ( vec_1 ( Yt ( t ) ), rgr ); // Bayes rule54 Ar.bayes ( vec_1 ( Yt ( t ) ), rgr ); // Bayes rule 55 55 56 // Build predictor57 mlstudent* Pr = Ar.predictor_student ( );58 // Test similarity of likelihoods from the Bayes rule and the predictor59 cout << "BR log-lik: " << Ar._ll();60 cout << " , predictor ll: " << Pr->evallogcond ( vec_1 ( Yt ( t ) ), rgr ) << endl;61 delete Pr;62 }63 //print posterior moments64 cout << "posterior mean: " << f_thr.mean() << endl;65 cout << "posterior variance: " << f_thr.variance() << endl;56 // Build predictor 57 mlstudent* Pr = Ar.predictor_student ( ); 58 // Test similarity of likelihoods from the Bayes rule and the predictor 59 cout << "BR log-lik: " << Ar._ll(); 60 cout << " , predictor ll: " << Pr->evallogcond ( vec_1 ( Yt ( t ) ), rgr ) << endl; 61 delete Pr; 62 } 63 //print posterior moments 64 cout << "posterior mean: " << f_thr.mean() << endl; 65 cout << "posterior variance: " << f_thr.variance() << endl; 66 66 67 // Test brute-froce structure estimation67 // Test brute-froce structure estimation 68 68 69 cout << "Structure estimation: " << endl;70 cout << Ar.structure_est ( egiw ( 1, V0, nu0 ) ) << endl;69 cout << "Structure estimation: " << endl; 70 cout << Ar.structure_est ( egiw ( 1, V0, nu0 ) ) << endl; 71 71 }
