root/applications/bdmtoolbox/tutorial/userguide/dist_estim_example.m @ 1111

Revision 934, 1.7 kB (checked in by smidl, 14 years ago)

use clear all + new mex

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