[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 ); |
---|
[679] | 11 | Ar.set_constant(true); |
---|
| 12 | Ar.validate(); |
---|
[477] | 13 | |
---|
| 14 | mat mu ( 1, 1 ); |
---|
| 15 | mat R ( 1, 1 ); |
---|
[536] | 16 | Ar.posterior().mean_mat ( mu, R ); |
---|
[477] | 17 | cout << "Prior moments: mu=" << mu << ", R=" << R << endl; |
---|
| 18 | |
---|
[201] | 19 | int ndat = 200; |
---|
[477] | 20 | vec smp = randn ( ndat ); |
---|
[201] | 21 | // |
---|
[477] | 22 | mat Smp = ones ( 2, ndat ); |
---|
| 23 | Smp.set_row ( 0, smp ); |
---|
[201] | 24 | // |
---|
[682] | 25 | Ar.bayes_batch ( Smp ); |
---|
[201] | 26 | // Ar is now filled with estimates of N(0,1); |
---|
[477] | 27 | cout << "Empirical moments: mu=" << sum ( smp ) / ndat << ", R=" << sum_sqr ( smp ) / ndat - pow ( sum ( smp ) / ndat, 2 ) << endl; |
---|
[536] | 28 | Ar.posterior().mean_mat ( mu, R ); |
---|
[477] | 29 | cout << "Posterior moments: mu=" << mu << ", R=" << R << endl; |
---|
| 30 | |
---|
[201] | 31 | //////// TEST prediction |
---|
[477] | 32 | vec x = linspace ( -3.0, 3.0, 100 ); |
---|
| 33 | double xstep = 6.0 / 100.0; |
---|
| 34 | mat X ( 1, 100 ); |
---|
| 35 | mat X2 ( 2, 100 ); |
---|
| 36 | X.set_row ( 0, x ); |
---|
| 37 | X2.set_row ( 0, x ); |
---|
| 38 | |
---|
[270] | 39 | mlstudent* Ap = Ar.predictor_student(); |
---|
[679] | 40 | vec Ap_x = Ap->evallogcond_m ( X, empty_vec ); |
---|
[477] | 41 | vec ll_x = Ar.logpred_m ( X2 ); |
---|
| 42 | |
---|
| 43 | cout << "normalize : " << xstep*sum ( exp ( Ap_x ) ) << endl; |
---|
| 44 | cout << "normalize : " << xstep*sum ( exp ( ll_x ) ) << endl; |
---|
| 45 | |
---|
| 46 | it_file it ( "arx_elem_test.it" ); |
---|
| 47 | it << Name ( "Ap_x" ) << Ap_x; |
---|
| 48 | it << Name ( "ll_x" ) << ll_x; |
---|
[201] | 49 | } |
---|