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