| 1 | % name random variables |
|---|
| 2 | y = RV({'y'},1); |
|---|
| 3 | u1 = RV({'u1'},1); |
|---|
| 4 | u2 = RV({'u2'},1); |
|---|
| 5 | |
|---|
| 6 | % create f(y_t| y_{t-3}, u_{t-1}) |
|---|
| 7 | fy.class = 'mlnorm<ldmat>'; |
|---|
| 8 | fy.rv = y; |
|---|
| 9 | fy.rvc = RVtimes([y,u1,u2], [-3, 0, 0]); |
|---|
| 10 | fy.A = [0.5, -0.9, 0.9]; |
|---|
| 11 | fy.const = 0; |
|---|
| 12 | fy.R = 1e-2; |
|---|
| 13 | |
|---|
| 14 | fu.class = 'enorm<ldmat>'; |
|---|
| 15 | fu.rv = RVjoin([u1,u2]); |
|---|
| 16 | fu.mu = [0,0]; |
|---|
| 17 | fu.R = 0.1*eye(2); |
|---|
| 18 | |
|---|
| 19 | f.class = 'mprod'; |
|---|
| 20 | f.pdfs = {fy,fu}; |
|---|
| 21 | |
|---|
| 22 | DS.class = 'PdfDS'; |
|---|
| 23 | DS.pdf = f; |
|---|
| 24 | |
|---|
| 25 | % create ARX estimator |
|---|
| 26 | A1.class = 'ARX'; |
|---|
| 27 | A1.rv = y; |
|---|
| 28 | A1.rgr = RVtimes([y,u1],[-3,0]) ; % correct structure is {y,y} |
|---|
| 29 | A1.options ='logbounds,logevidence'; |
|---|
| 30 | A1.frg = 0.95; |
|---|
| 31 | A1.constant = 0; |
|---|
| 32 | |
|---|
| 33 | A2=A1; |
|---|
| 34 | A2.rgr = RVtimes([y,u2],[-3,0]) ; % correct structure is {y,y} |
|---|
| 35 | |
|---|
| 36 | M=estimator(DS,{A1,A2},struct('ndat',100)); |
|---|
| 37 | |
|---|
| 38 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 39 | % plot results |
|---|
| 40 | ndat = size(M.DS_u1,1); |
|---|
| 41 | |
|---|
| 42 | true_theta1 = fy.A([1,2]); |
|---|
| 43 | true_theta2 = fy.A([1,3]); |
|---|
| 44 | true_R = fy.R; |
|---|
| 45 | |
|---|
| 46 | figure(1); |
|---|
| 47 | subplot(2,1,1); |
|---|
| 48 | plot(M.DS_y); |
|---|
| 49 | title('Output'); |
|---|
| 50 | |
|---|
| 51 | subplot(2,1,2); |
|---|
| 52 | plot(M.DS_u1); |
|---|
| 53 | hold on |
|---|
| 54 | plot(M.DS_u2); |
|---|
| 55 | title('Input'); |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | figure(2) |
|---|
| 59 | hold off; |
|---|
| 60 | subplot(2,2,1); |
|---|
| 61 | hold off |
|---|
| 62 | plotestimates(true_theta1, ... |
|---|
| 63 | M.Est0_apost_mean_theta, ... |
|---|
| 64 | M.Est0_apost_lb_theta, ... |
|---|
| 65 | M.Est0_apost_ub_theta); |
|---|
| 66 | set(gca,'YLim',[-1.5,1]); |
|---|
| 67 | |
|---|
| 68 | subplot(2,2,2); |
|---|
| 69 | hold off |
|---|
| 70 | plotestimates(true_R, ... |
|---|
| 71 | M.Est0_apost_mean_r, ... |
|---|
| 72 | M.Est0_apost_lb_r, ... |
|---|
| 73 | M.Est0_apost_ub_r); |
|---|
| 74 | |
|---|
| 75 | title('Variance parameters r') |
|---|
| 76 | |
|---|
| 77 | subplot(2,2,3); |
|---|
| 78 | hold off |
|---|
| 79 | plotestimates(true_theta2, ... |
|---|
| 80 | M.Est1_apost_mean_theta, ... |
|---|
| 81 | M.Est1_apost_lb_theta, ... |
|---|
| 82 | M.Est1_apost_ub_theta); |
|---|
| 83 | set(gca,'YLim',[-1.5,1]); |
|---|
| 84 | |
|---|
| 85 | subplot(2,2,4); |
|---|
| 86 | hold off |
|---|
| 87 | plotestimates(true_R, ... |
|---|
| 88 | M.Est1_apost_mean_r, ... |
|---|
| 89 | M.Est1_apost_lb_r, ... |
|---|
| 90 | M.Est1_apost_ub_r); |
|---|
| 91 | |
|---|
| 92 | title('Variance parameters r') |
|---|