16 | | mat V0 = 0.00001*eye(ord+1); V0(0.0)*= 100; // |
17 | | double nu0 = ord+4; |
18 | | |
19 | | RV thr("{theta_and_r }",vec_1(ord+1)); |
20 | | ARX Ar(thr, V0, nu0); |
21 | | const epdf& Ar_ep = Ar._epdf(); |
22 | | |
| 23 | mat V0 = 0.00001*eye ( ord+1 ); V0 ( 0.0 ) = 1; // |
| 24 | double nu0 = ord+5.0; |
| 25 | |
| 26 | RV thr ( "{theta_and_r }",vec_1 ( ord+1 ) ); // Descriptive random variable |
| 27 | ARX Ar ( thr, V0, nu0 ); // Estimator |
| 28 | const epdf& f_thr = Ar._epdf(); // refrence to posterior of the estimator |
| 29 | |
24 | | int ndat = 100; |
25 | | int t,j; |
26 | | vec Yt(ndat); |
27 | | vec LL(ndat); |
28 | | Yt.set_subvector(0,randn(ord)); //initial values |
29 | | vec rgr(ord); |
30 | | |
31 | | |
32 | | cout << Ar_ep.mean()<<endl; |
33 | | for (t=ord; t<ndat; t++) { |
34 | | for(j=0;j<(ord);j++){rgr(j)=Yt(t-j-1);} |
35 | | Yt(t) = th*rgr + sqr * NorRNG(); |
36 | | |
37 | | vec Psi = concat(Yt(t), rgr); |
38 | | Ar.bayes(Psi); |
39 | | LL(t) = Ar._ll(); |
40 | | |
41 | | cout << "y: " << Yt(t) << endl; |
42 | | mlstudent* Pr = Ar.predictor_student(RV("{y }"),RV("{y1 y2 y3 y4 }")); |
43 | | cout << Ar._ll() <<" , " << log(Pr->evallogcond(vec_1(Yt(t)),rgr)) <<endl; |
| 31 | int ndat = 100; // number of data records |
| 32 | vec Yt ( ndat ); // Store generated data |
| 33 | Yt.set_subvector ( 0,randn ( ord ) ); //initial values |
| 34 | vec rgr ( ord ); // regressor |
| 35 | vec Psi ( ord+1 ); // extended regressor |
| 36 | |
| 37 | //print moments of the prior distribution |
| 38 | cout << "prior mean: " << f_thr.mean() <<endl; |
| 39 | cout << "prior variance: " << f_thr.variance() <<endl; |
| 40 | |
| 41 | // cycle over time: |
| 42 | for ( int t=ord; t<ndat; t++ ) { |
| 43 | //Generate regressor |
| 44 | for ( int j=0;j< ( ord );j++ ) {rgr ( j ) =Yt ( t-j-1 );} |
| 45 | //model |
| 46 | Yt ( t ) = th*rgr + sqr * NorRNG(); |
| 47 | |
| 48 | Psi = concat ( Yt ( t ), rgr ); // Inefficient! Used for compatibility with Matlab! |
| 49 | Ar.bayes ( Psi ); // Bayes rule |
| 50 | |
| 51 | // Build predictor |
| 52 | mlstudent* Pr = Ar.predictor_student ( RV ( "{y }" ),RV ( "{y1 y2 y3 y4 }" ) ); |
| 53 | // Test similarity of likelihoods from the Bayes rule and the predictor |
| 54 | cout << "BR log-lik: " << Ar._ll(); |
| 55 | cout <<" , predictor ll: " << Pr->evallogcond ( vec_1 ( Yt ( t ) ),rgr ) <<endl; |