1 | #include "estim/arx.h" |
---|
2 | using namespace bdm; |
---|
3 | |
---|
4 | int main() { |
---|
5 | // Setup model : ARX for 1D Gaussian |
---|
6 | //Test constructor |
---|
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 ); |
---|
14 | Ar.posterior().mean_mat ( mu, R ); |
---|
15 | cout << "Prior moments: mu=" << mu << ", R=" << R << endl; |
---|
16 | |
---|
17 | int ndat = 200; |
---|
18 | vec smp = randn ( ndat ); |
---|
19 | // |
---|
20 | mat Smp = ones ( 2, ndat ); |
---|
21 | Smp.set_row ( 0, smp ); |
---|
22 | // |
---|
23 | Ar.bayesB ( Smp ); |
---|
24 | // Ar is now filled with estimates of N(0,1); |
---|
25 | cout << "Empirical moments: mu=" << sum ( smp ) / ndat << ", R=" << sum_sqr ( smp ) / ndat - pow ( sum ( smp ) / ndat, 2 ) << endl; |
---|
26 | Ar.posterior().mean_mat ( mu, R ); |
---|
27 | cout << "Posterior moments: mu=" << mu << ", R=" << R << endl; |
---|
28 | |
---|
29 | //////// TEST prediction |
---|
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 | |
---|
37 | mlstudent* Ap = Ar.predictor_student(); |
---|
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; |
---|
47 | } |
---|