1 | #include "estim/arx.h" |
---|
2 | #include "../mat_checks.h" |
---|
3 | |
---|
4 | using namespace bdm; |
---|
5 | |
---|
6 | TEST ( arx_elem_stress ) { |
---|
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(); |
---|
15 | |
---|
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; |
---|
20 | |
---|
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; |
---|
32 | |
---|
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 ); |
---|
40 | |
---|
41 | mlstudent* Ap = Ar.predictor_student(); |
---|
42 | vec Ap_x = Ap->evallogcond_mat ( X, empty_vec ); |
---|
43 | vec ll_x = Ar.logpred_mat ( X2 ); |
---|
44 | |
---|
45 | cout << "normalize : " << xstep*sum ( exp ( Ap_x ) ) << endl; |
---|
46 | cout << "normalize : " << xstep*sum ( exp ( ll_x ) ) << endl; |
---|
47 | |
---|
48 | it_file it ( "arx_elem_test.it" ); |
---|
49 | it << Name ( "Ap_x" ) << Ap_x; |
---|
50 | it << Name ( "ll_x" ) << ll_x; |
---|
51 | } |
---|