[1034] | 1 | clear all |
---|
| 2 | % load data created by the MpdfDS_example |
---|
| 3 | load pdfds_results |
---|
| 4 | |
---|
| 5 | DS.class = 'MemDS'; |
---|
| 6 | DS.Data = Data; |
---|
| 7 | DS.drv = drv; |
---|
| 8 | |
---|
[1038] | 9 | |
---|
[1034] | 10 | %%%%%% ARX estimator conditioned on frg |
---|
| 11 | |
---|
| 12 | A1.class = 'ARXpartialforg'; |
---|
| 13 | A1.yrv = y; |
---|
| 14 | A1.rv = RV({'theta','r'},[2,1]); |
---|
| 15 | A1.rgr = RVtimes([y,u],[-3,-1]) ; |
---|
| 16 | A1.log_level = 'logbounds'; |
---|
| 17 | A1.constant = 0; |
---|
| 18 | A1.name = 'A1'; |
---|
| 19 | |
---|
[1038] | 20 | Apri =A1; |
---|
| 21 | Apri.class = 'ARX'; |
---|
| 22 | DSpri = DS; |
---|
[1100] | 23 | DSpri.Data = DS.Data(:,1:6); |
---|
[1038] | 24 | % get decent prior -- estimate with data first |
---|
| 25 | [Dum,post]=estimator(DSpri,{Apri}); |
---|
| 26 | |
---|
| 27 | A1.prior = post.estimators{1}.posterior; |
---|
| 28 | |
---|
[1034] | 29 | % we have 2 parameters - i.e. 4 hypotheses |
---|
| 30 | |
---|
| 31 | %%%%%% Random walk on frg - Dirichlet |
---|
[1100] | 32 | walk.class = 'mDirich'; % random walk on coefficient phi |
---|
[1034] | 33 | walk.rv = RV({'phi'},4); % 2D random walk - frg is the first element |
---|
[1100] | 34 | walk.k = 0.001; % width of the random walk |
---|
[1034] | 35 | walk.betac = 0.1*ones(1,4); % stabilizing elememnt of random walk |
---|
| 36 | |
---|
| 37 | %%%%%% Particle |
---|
| 38 | p.class = 'MarginalizedParticle'; |
---|
| 39 | p.parameter_pdf = walk; % Random walk is the parameter evolution model |
---|
| 40 | p.bm = A1; |
---|
| 41 | |
---|
| 42 | % prior on ARX |
---|
| 43 | %%%%%% Combining estimators in Marginalized particle filter |
---|
| 44 | E.class = 'PF'; |
---|
| 45 | E.particle = p; % ARX is the analytical part |
---|
| 46 | E.res_threshold = 0.7; % resampling parameter |
---|
| 47 | E.n = 100; % number of particles |
---|
| 48 | E.prior.class = 'eBeta'; % prior on non-linear part |
---|
| 49 | E.prior.alpha = 5*ones(1,4); % |
---|
| 50 | E.prior.beta = ones(1,4); % |
---|
[1100] | 51 | E.log_level = 'logbounds,logweights'; |
---|
[1034] | 52 | E.name = 'MPF'; |
---|
| 53 | |
---|
| 54 | [M,Str]=estimator(DS,{E}); |
---|
| 55 | |
---|
| 56 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 57 | % plot results |
---|
| 58 | ndat = size(M.DS_dt_u,1); |
---|
| 59 | |
---|
| 60 | figure(1); |
---|
| 61 | subplot(2,2,1); |
---|
| 62 | plotestimates(true_theta, M.MPF_apost_mean_theta, M.MPF_apost_lbound_theta, M.MPF_apost_ubound_theta); |
---|
| 63 | title(' Regression parameters \theta') |
---|
| 64 | set(gca,'YLim',[-1.5,1]); |
---|
| 65 | |
---|
| 66 | subplot(2,2,2); |
---|
| 67 | plotestimates(true_R, M.MPF_apost_mean_r,M.MPF_apost_lbound_r,M.MPF_apost_ubound_r); |
---|
| 68 | title('Variance parameters r') |
---|
| 69 | |
---|
| 70 | subplot(2,2,3); |
---|
| 71 | plotestimates(1, M.MPF_apost_mean_phi(:,1),M.MPF_apost_lbound_phi(:,1),M.MPF_apost_ubound_phi(:,1)); |
---|
| 72 | title('Forgetting factor') |
---|
| 73 | |
---|
| 74 | |
---|