[934] | 1 | clear all |
---|
[888] | 2 | % name random variables |
---|
| 3 | x = RV({'x'},1); |
---|
| 4 | y = RV({'y'},1); |
---|
| 5 | u = RV({'u'},1); |
---|
| 6 | |
---|
| 7 | % create f(x_t| x_{t-1}, u_{t}) |
---|
| 8 | fx.class = 'mlnorm<ldmat>'; |
---|
| 9 | fx.rv = x; |
---|
| 10 | fx.rvc = RVtimes([x,u], [-1, 0]); |
---|
| 11 | fx.A = [0.5 -0.9]; |
---|
| 12 | fx.const = 0; |
---|
| 13 | fx.R = 0.01; |
---|
| 14 | |
---|
| 15 | % create f(y_t| y_{t-1}, u_{t-1}) |
---|
| 16 | fy.class = 'mlnorm<ldmat>'; |
---|
| 17 | fy.rv = y; |
---|
| 18 | fy.rvc = RVjoin([x,u]); |
---|
| 19 | fy.A = [1, 0.1]; |
---|
| 20 | fy.const = 0; |
---|
| 21 | fy.R = 1e-3; |
---|
| 22 | |
---|
| 23 | % create f(u_t| ) |
---|
| 24 | fu.class = 'egauss'; |
---|
| 25 | fu.rv = u; |
---|
| 26 | fu.mu = 0; |
---|
| 27 | fu.R = 1e-1; |
---|
| 28 | |
---|
| 29 | % create DS |
---|
| 30 | DS.class = 'PdfDS'; |
---|
| 31 | DS.pdf.class = 'mprod'; |
---|
| 32 | DS.pdf.pdfs = { fy, fx, fu}; |
---|
| 33 | DS.init_rv = RVtimes([x], [-1]); |
---|
| 34 | DS.init_values = [0.1]; |
---|
| 35 | |
---|
| 36 | % debug DS % MMM=simulator(DS); |
---|
| 37 | |
---|
| 38 | %%%%%% PF estimator |
---|
| 39 | |
---|
| 40 | PF.class = 'PF'; |
---|
| 41 | PF.particle.class = 'BootstrapParticle'; |
---|
| 42 | PF.particle.parameter_pdf = fx; |
---|
| 43 | PF.particle.observation_pdf = fy; |
---|
[933] | 44 | PF.log_level ='logbounds,logevidence'; |
---|
[888] | 45 | PF.prior.class = 'egauss'; |
---|
| 46 | PF.prior.mu = 0; |
---|
| 47 | PF.prior.R = 0.2; |
---|
| 48 | PF.res_threshold = 1; |
---|
| 49 | PF.n = 1000; |
---|
| 50 | |
---|
| 51 | exper.ndat =100; |
---|
| 52 | |
---|
| 53 | M=estimator(DS,{PF},exper); |
---|
| 54 | |
---|
| 55 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 56 | % plot results |
---|
[933] | 57 | ndat = size(M.DS_dt_u,1); |
---|
[888] | 58 | |
---|
[933] | 59 | plotestimates(M.DS_dt_x, ... |
---|
[888] | 60 | M.Est0_apost_mean_x, ... |
---|
[933] | 61 | M.Est0_apost_lbound_x, ... |
---|
| 62 | M.Est0_apost_ubound_x); |
---|
[888] | 63 | set(gca,'YLim',[-1.5,1]); |
---|
| 64 | |
---|
| 65 | title('Variance parameters r') |
---|