root/library/tests/arx_elem_test.cpp @ 536

Revision 536, 1.3 kB (checked in by smidl, 15 years ago)

removal of unused functions _e() and samplecond(,) and added documentation lines

  • Property svn:eol-style set to native
Line 
1#include "estim/arx.h"
2using namespace bdm;
3
4int 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}
Note: See TracBrowser for help on using the browser.