Revision 384, 1.1 kB
(checked in by mido, 16 years ago)
|
possibly broken?
|
-
Property svn:eol-style set to
native
|
Rev | Line | |
---|
[384] | 1 | #include "estim/arx.h" |
---|
[254] | 2 | using namespace bdm; |
---|
[201] | 3 | |
---|
| 4 | int main() { |
---|
| 5 | // Setup model : ARX for 1D Gaussian |
---|
| 6 | //Test constructor |
---|
| 7 | mat V0 = 0.00001*eye(2); V0(0,0)= 0.1; // |
---|
[270] | 8 | ARX Ar; Ar.set_statistics(1, V0, -1.0); |
---|
[201] | 9 | |
---|
| 10 | mat mu(1,1); |
---|
| 11 | mat R(1,1); |
---|
| 12 | Ar._e()->mean_mat(mu,R); |
---|
| 13 | cout << "Prior moments: mu="<< mu << ", R=" << R <<endl; |
---|
| 14 | |
---|
| 15 | int ndat = 200; |
---|
| 16 | vec smp=randn(ndat); |
---|
| 17 | // |
---|
| 18 | mat Smp=ones(2,ndat); |
---|
| 19 | Smp.set_row(0,smp); |
---|
| 20 | // |
---|
| 21 | Ar.bayesB(Smp); |
---|
| 22 | // Ar is now filled with estimates of N(0,1); |
---|
| 23 | cout << "Empirical moments: mu=" << sum(smp)/ndat << ", R=" << sum_sqr(smp)/ndat - pow(sum(smp)/ndat,2) << endl; |
---|
| 24 | Ar._e()->mean_mat(mu,R); |
---|
| 25 | cout << "Posterior moments: mu="<< mu << ", R=" << R <<endl; |
---|
| 26 | |
---|
| 27 | //////// TEST prediction |
---|
| 28 | vec x=linspace(-3.0,3.0,100); |
---|
| 29 | double xstep = 6.0/100.0; |
---|
| 30 | mat X(1,100); |
---|
| 31 | mat X2(2,100); |
---|
| 32 | X.set_row(0,x); |
---|
| 33 | X2.set_row(0,x); |
---|
| 34 | |
---|
[270] | 35 | mlstudent* Ap = Ar.predictor_student(); |
---|
[211] | 36 | vec Ap_x=Ap->evallogcond_m(X,vec_1(1.0)); |
---|
[201] | 37 | vec ll_x = Ar.logpred_m(X2); |
---|
| 38 | |
---|
[270] | 39 | cout << "normalize : " << xstep*sum(exp(Ap_x)) << endl; |
---|
[201] | 40 | cout << "normalize : " << xstep*sum(exp(ll_x)) << endl; |
---|
| 41 | |
---|
| 42 | it_file it("arx_elem_test.it"); |
---|
| 43 | it << Name("Ap_x") << Ap_x; |
---|
| 44 | it << Name("ll_x") << ll_x; |
---|
| 45 | } |
---|