| 1 | % load data created by the MpdfDS_example | 
|---|
| 2 | load pdfds_results | 
|---|
| 3 |  | 
|---|
| 4 | DS.class   = 'MemDS'; | 
|---|
| 5 | DS.Data    = Data; | 
|---|
| 6 | DS.drv     = drv; | 
|---|
| 7 |  | 
|---|
| 8 | %%%%%% ARX estimator conditioned on frg | 
|---|
| 9 |  | 
|---|
| 10 | A1.class = 'ARXfrg'; | 
|---|
| 11 | A1.rv = y; | 
|---|
| 12 | A1.rgr = RVtimes([y,u],[-3,-1]) ;  | 
|---|
| 13 | A1.log_level = 'logbounds'; | 
|---|
| 14 | A1.frg = 0.98; | 
|---|
| 15 | A1.name = 'A1'; | 
|---|
| 16 |  | 
|---|
| 17 |  | 
|---|
| 18 | %%%%%% Random walk on frg - Dirichlet  | 
|---|
| 19 | phi_pdf.class = 'mDirich';         % random walk on coefficient phi | 
|---|
| 20 | phi_pdf.rv    = RV({'phi','1_phi'});       % 2D random walk - frg is the first element | 
|---|
| 21 | phi_pdf.k     = 0.01;              % width of the random walk | 
|---|
| 22 | phi_pdf.betac = [0.1 0.1];         % stabilizing elememnt of random walk | 
|---|
| 23 |  | 
|---|
| 24 | %%%%%% Particle | 
|---|
| 25 | p.class = 'MarginalizedParticle'; | 
|---|
| 26 | p.parameter_pdf = phi_pdf;         % Random walk is the parameter evolution model | 
|---|
| 27 | p.bm    = A1; | 
|---|
| 28 |  | 
|---|
| 29 | % prior on ARX | 
|---|
| 30 | %%%%%% Combining estimators in Marginalized particle filter | 
|---|
| 31 | E.class = 'PF'; | 
|---|
| 32 | E.particle = p;                    % ARX is the analytical part | 
|---|
| 33 | E.res_threshold = 1.0;             % resampling parameter | 
|---|
| 34 | E.n = 100;                          % number of particles | 
|---|
| 35 | E.prior.class = 'eDirich';         % prior on non-linear part | 
|---|
| 36 | E.prior.beta  = [2 1]; %  | 
|---|
| 37 | E.log_level = 'logbounds'; | 
|---|
| 38 | E.name = 'MPF'; | 
|---|
| 39 |  | 
|---|
| 40 | [M,Str]=estimator(DS,{E}); | 
|---|
| 41 |  | 
|---|
| 42 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
|---|
| 43 | % plot results | 
|---|
| 44 | ndat = size(M.DS_dt_u,1); | 
|---|
| 45 |  | 
|---|
| 46 | figure(1); | 
|---|
| 47 | subplot(2,2,1); | 
|---|
| 48 | plotestimates(true_theta, M.MPF_apost_mean_theta, M.MPF_apost_lbound_theta, M.MPF_apost_ubound_theta); | 
|---|
| 49 | title(' Regression parameters \theta') | 
|---|
| 50 | set(gca,'YLim',[-1.5,1]); | 
|---|
| 51 |  | 
|---|
| 52 | subplot(2,2,2); | 
|---|
| 53 | plotestimates(true_R, M.MPF_apost_mean_r,M.MPF_apost_lbound_r,M.MPF_apost_ubound_r); | 
|---|
| 54 | title('Variance parameters r') | 
|---|
| 55 |  | 
|---|
| 56 | subplot(2,2,3); | 
|---|
| 57 | plotestimates(1, M.MPF_apost_mean_phi(:,1),M.MPF_apost_lbound_phi(:,1),M.MPF_apost_ubound_phi(:,1)); | 
|---|
| 58 | title('Forgetting factor') | 
|---|
| 59 |  | 
|---|