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