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

Revision 871, 2.1 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);
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.log_level ='logfull,logevidence';
37A1.rv_param = RV({'a','b','c','r'});
38A1.frg = 0.95;
39A1.constant = 1;
40
41A2=A1;
42A2.rv  = z;
43A2.rv_param = RV({'a','b','c','r'});
44A2.rgr = RVtimes([u,u],[0,-1]) ; % correct structure is {y,y}
45
46[M,Set]=estimator(DS,{A1,A2},struct('ndat',100));
47
48%% post-merging
49
50Merger.class='merger_mix';
51Merger.method='lognormal';
52Merger.beta=1.2;
53Merger.ncoms=20;
54Merger.stop_niter=10;
55Merger.effss_coef=0.9;
56%Merger.dbg_file = 'm.it';
57
58M2.class = 'merger_base';
59M2.method='lognormal';
60M2.beta=1.2;
61
62support.class='discrete_support';
63support.epdf= struct('class','enorm<ldmat>','mu',[2,-1,0,0.1],'R',eye(4));
64support.npoints=[300];
65
66support2.class='rectangular_support';
67support2.ranges= {[0,5],[-2,2],[-2,2],[0.001,3]};
68support2.gridsizes = [10,10,10,10];
69
70
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% plot results
73ndat = size(M.DS_u,1);
74
75true_theta1 = [fy.A fy.const];
76true_theta2 = [fz.A fy.const];
77true_R = fy.R;
78
79A1_mean = zeros(4,ndat);
80A2_mean = zeros(4,ndat);
81MG_mean = zeros(4,ndat);
82
83for t=1:ndat
84    f1=Set.Est0_apost{t};
85    f2=Set.Est1_apost{t};
86    if t>5
87%        support.epdf = f1;
88    end
89
90    [res,ftilde] = merger({f1,f2},support,Merger);
91
92    A1_mean(:,t) = epdf_mean(f1);
93    A2_mean(:,t) = epdf_mean(f2);
94    MG_mean(:,t) = epdf_mean(ftilde);
95end;
96
97
98figure(1);
99subplot(3,1,1);
100plot(M.DS_y);
101title('y');
102
103subplot(3,1,2);
104plot(M.DS_z);
105title('z')
106
107subplot(3,1,2);
108plot(M.DS_u);
109title('u')
110
111
112figure(2)
113plot(A1_mean',':');
114hold on;
115plot(A2_mean','--');
116plot(MG_mean');
Note: See TracBrowser for help on using the browser.