root/applications/bdmtoolbox/tutorial/mpdm/dist_estim_example.m @ 759

Revision 759, 1.9 kB (checked in by smidl, 14 years ago)

improved version (almost SYSID)

Line 
1% name random variables
2y = RV({'y'},1);
3z = RV({'z'},1);
4u = RV({'u'},1);
5
6% create f(y_t| z_{t-1}, z_{t-2})
7fy.class = 'mlnorm<ldmat>';
8fy.rv    = y;
9fy.rvc   = RVtimes([z,z], [0, -1]);
10fy.A     = [1.8, -0.9];
11fy.const = 0.2;
12fy.R     = 1e-2;
13
14fz.class = 'mlnorm<ldmat>';
15fz.rv    = z;
16fz.rvc   = RVtimes([u,u], [0, -1]);
17fz.A     = [1.8, -0.9];
18fz.const = -0.2;
19fz.R     = 1e-2;
20
21fu.class = 'enorm<ldmat>';
22fu.rv    = u;
23fu.mu    = [0];
24fu.R     = 0.001;
25
26f.class = 'mprod';
27f.pdfs  = {fy,fz,fu};
28
29DS.class = 'PdfDS';
30DS.pdf = f;
31
32% create ARX estimator
33A1.class = 'ARX';
34A1.rv = y;
35A1.rgr = RVtimes([z,z],[0,-1]) ; % correct structure is {y,y}
36A1.options ='logfull,logll';
37A1.frg = 0.95;
38A1.constant = 1;
39
40A2=A1;
41A2.rv  = z;
42A2.rgr = RVtimes([u,u],[0,-1]) ; % correct structure is {y,y}
43
44[M,Set]=estimator(DS,{A1,A2},struct('ndat',100));
45
46%% post-merging
47
48Merger.class='merger_mix';
49Merger.method='lognormal';
50Merger.beta=1.2;
51Merger.ncoms=20;
52Merger.stop_niter=10;
53Merger.effss_coef=0.9;
54
55support.class='discrete_support';
56support.epdf= struct('class','enorm<ldmat>','mu',[1,1,1,1,0.1],'R',eye(5));
57support.npoints=[100];
58
59
60
61%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62% plot results
63ndat = size(M.DS_u,1);
64
65true_theta1 = [fy.A fy.const];
66true_theta2 = [fz.A fy.const];
67true_R = fy.R;
68
69A1_mean = zeros(4,ndat);
70A2_mean = zeros(4,ndat);
71MG_mean = zeros(5,ndat);
72
73for t=1:ndat
74    f1=Set.Est0_apost{t};
75    f1.rv = RV({'a','b','c','r'});
76    f2=Set.Est1_apost{t};
77    f2.rv = RV({'a','b','d','r'});
78   
79    [res,ftilde] = merger({f1,f2},support,Merger);
80   
81    A1_mean(:,t) = epdf_mean(f1);
82    A2_mean(:,t) = epdf_mean(f2);
83    MG_mean(:,t) = epdf_mean(ftilde);
84end;
85
86
87figure(1);
88subplot(3,1,1);
89plot(M.DS_y);
90title('y');
91
92subplot(3,1,2);
93plot(M.DS_z);
94title('z')
95
96subplot(3,1,2);
97plot(M.DS_u);
98title('u')
99
100
101figure(2)
102subplot(2,2,1);
103plot(A1_mean');
104subplot(2,2,2);
105plot(A2_mean');
106subplot(2,2,3);
107plot(MG_mean');
Note: See TracBrowser for help on using the browser.