[717] | 1 | #include "estim/arx.h" |
---|
[721] | 2 | #include "../mat_checks.h" |
---|
| 3 | |
---|
[717] | 4 | using namespace bdm; |
---|
| 5 | |
---|
[721] | 6 | TEST ( arx_elem_stress ) { |
---|
[1064] | 7 | // Setup model : ARX for 1D Gaussian |
---|
| 8 | //Test constructor |
---|
| 9 | mat V0 = 0.00001 * eye ( 2 ); |
---|
| 10 | V0 ( 0, 0 ) = 0.1; // |
---|
| 11 | ARX Ar; |
---|
| 12 | Ar.set_statistics ( 1, V0, -1.0 ); |
---|
| 13 | Ar.set_constant ( true ); |
---|
| 14 | Ar.validate(); |
---|
[717] | 15 | |
---|
[1064] | 16 | mat mu ( 1, 1 ); |
---|
| 17 | mat R ( 1, 1 ); |
---|
| 18 | Ar.posterior().mean_mat ( mu, R ); |
---|
| 19 | cout << "Prior moments: mu=" << mu << ", R=" << R << endl; |
---|
[717] | 20 | |
---|
[1064] | 21 | int ndat = 200; |
---|
| 22 | vec smp = randn ( ndat ); |
---|
| 23 | // |
---|
| 24 | mat Smp = ones ( 2, ndat ); |
---|
| 25 | Smp.set_row ( 0, smp ); |
---|
| 26 | // |
---|
| 27 | Ar.bayes_batch ( Smp ); |
---|
| 28 | // Ar is now filled with estimates of N(0,1); |
---|
| 29 | cout << "Empirical moments: mu=" << sum ( smp ) / ndat << ", R=" << sum_sqr ( smp ) / ndat - pow ( sum ( smp ) / ndat, 2 ) << endl; |
---|
| 30 | Ar.posterior().mean_mat ( mu, R ); |
---|
| 31 | cout << "Posterior moments: mu=" << mu << ", R=" << R << endl; |
---|
[717] | 32 | |
---|
[1064] | 33 | //////// TEST prediction |
---|
| 34 | vec x = linspace ( -3.0, 3.0, 100 ); |
---|
| 35 | double xstep = 6.0 / 100.0; |
---|
| 36 | mat X ( 1, 100 ); |
---|
| 37 | mat X2 ( 2, 100 ); |
---|
| 38 | X.set_row ( 0, x ); |
---|
| 39 | X2.set_row ( 0, x ); |
---|
[717] | 40 | |
---|
[1176] | 41 | mlstudent* Ap = Ar.predictor(); |
---|
[1064] | 42 | vec Ap_x = Ap->evallogcond_mat ( X, empty_vec ); |
---|
| 43 | vec ll_x = Ar.logpred_mat ( X2 , empty_vec); |
---|
[717] | 44 | |
---|
[1064] | 45 | cout << "normalize : " << xstep*sum ( exp ( Ap_x ) ) << endl; |
---|
| 46 | cout << "normalize : " << xstep*sum ( exp ( ll_x ) ) << endl; |
---|
[717] | 47 | |
---|
[1064] | 48 | it_file it ( "arx_elem_test.it" ); |
---|
| 49 | it << Name ( "Ap_x" ) << Ap_x; |
---|
| 50 | it << Name ( "ll_x" ) << ll_x; |
---|
[717] | 51 | } |
---|