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