root/tests/arx_elem_test.cpp @ 201

Revision 201, 1.3 kB (checked in by smidl, 16 years ago)

oprava ARX a prejmenovani sampleN na sample_m

Line 
1#include <estim/arx.h>
2#include <stat/libEF.h>
3using namespace itpp;
4
5//These lines are needed for use of cout and endl
6using std::cout;
7using std::endl;
8
9int main() {
10        // Setup model : ARX for 1D Gaussian   
11        //Test constructor
12        mat V0 = 0.00001*eye(2); V0(0,0)= 0.1; //
13        RV thr("{th r }");
14        ARX Ar(thr, V0, -1.0);
15                               
16        mat mu(1,1);
17        mat R(1,1);
18        Ar._e()->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.bayesB(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._e()->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(RV("{y }"),RV("{1 }"));
42        vec Ap_x=Ap->evalcond_m(X,vec_1(1.0));
43        vec ll_x = Ar.logpred_m(X2);
44       
45        cout << "normalize : " << xstep*sum(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}
Note: See TracBrowser for help on using the browser.