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

Revision 871, 1.7 kB (checked in by mido, 14 years ago)

adaptation of /applications to new version of LOG_LEVEL
also, a cosmetic change made in enumerations: logub -> logubound, loglb -> loglbound

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