1 | % name random variables |
---|
2 | y = RV({'y'},1); |
---|
3 | z = RV({'z'},1); |
---|
4 | u = RV({'u'},1); |
---|
5 | |
---|
6 | % create f(y_t| z_{t-1}, z_{t-2}) |
---|
7 | fy.class = 'mlnorm<ldmat>'; |
---|
8 | fy.rv = y; |
---|
9 | fy.rvc = RVtimes([z,z], [0, -1]); |
---|
10 | fy.A = [1.8, -0.9]; |
---|
11 | fy.const = 0.2; |
---|
12 | fy.R = 1e-2; |
---|
13 | |
---|
14 | fz.class = 'mlnorm<ldmat>'; |
---|
15 | fz.rv = z; |
---|
16 | fz.rvc = RVtimes([u,u], [0, -1]); |
---|
17 | fz.A = [1.8, -0.9]; |
---|
18 | fz.const = 0.2; |
---|
19 | fz.R = 1e-2; |
---|
20 | |
---|
21 | fu.class = 'enorm<ldmat>'; |
---|
22 | fu.rv = u; |
---|
23 | fu.mu = [0]; |
---|
24 | fu.R = 0.001; |
---|
25 | |
---|
26 | f.class = 'mprod'; |
---|
27 | f.pdfs = {fy,fz,fu}; |
---|
28 | |
---|
29 | DS.class = 'PdfDS'; |
---|
30 | DS.pdf = f; |
---|
31 | |
---|
32 | % create ARX estimator |
---|
33 | A1.class = 'ARX'; |
---|
34 | A1.rv = y; |
---|
35 | A1.rgr = RVtimes([z,z],[0,-1]) ; % correct structure is {y,y} |
---|
36 | A1.options ='logfull,logll'; |
---|
37 | A1.rv_param = RV({'a','b','c','r'}); |
---|
38 | A1.frg = 0.95; |
---|
39 | A1.constant = 1; |
---|
40 | |
---|
41 | A2=A1; |
---|
42 | A2.rv = z; |
---|
43 | A2.rv_param = RV({'a','b','c','r'}); |
---|
44 | A2.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 | |
---|
50 | Merger.class='merger_mix'; |
---|
51 | Merger.method='lognormal'; |
---|
52 | Merger.beta=1.2; |
---|
53 | Merger.ncoms=20; |
---|
54 | Merger.stop_niter=10; |
---|
55 | Merger.effss_coef=0.9; |
---|
56 | %Merger.dbg_file = 'm.it'; |
---|
57 | |
---|
58 | M2.class = 'merger_base'; |
---|
59 | M2.method='lognormal'; |
---|
60 | M2.beta=1.2; |
---|
61 | |
---|
62 | support.class='discrete_support'; |
---|
63 | support.epdf= struct('class','enorm<ldmat>','mu',[2,-1,0,0.1],'R',eye(4)); |
---|
64 | support.npoints=[300]; |
---|
65 | |
---|
66 | support2.class='rectangular_support'; |
---|
67 | support2.ranges= {[0,5],[-2,2],[-2,2],[0.001,3]}; |
---|
68 | support2.gridsizes = [10,10,10,10]; |
---|
69 | |
---|
70 | |
---|
71 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
72 | % plot results |
---|
73 | ndat = size(M.DS_u,1); |
---|
74 | |
---|
75 | true_theta1 = [fy.A fy.const]; |
---|
76 | true_theta2 = [fz.A fy.const]; |
---|
77 | true_R = fy.R; |
---|
78 | |
---|
79 | A1_mean = zeros(4,ndat); |
---|
80 | A2_mean = zeros(4,ndat); |
---|
81 | MG_mean = zeros(4,ndat); |
---|
82 | |
---|
83 | for 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); |
---|
95 | end; |
---|
96 | |
---|
97 | |
---|
98 | figure(1); |
---|
99 | subplot(3,1,1); |
---|
100 | plot(M.DS_y); |
---|
101 | title('y'); |
---|
102 | |
---|
103 | subplot(3,1,2); |
---|
104 | plot(M.DS_z); |
---|
105 | title('z') |
---|
106 | |
---|
107 | subplot(3,1,2); |
---|
108 | plot(M.DS_u); |
---|
109 | title('u') |
---|
110 | |
---|
111 | |
---|
112 | figure(2) |
---|
113 | plot(A1_mean',':'); |
---|
114 | hold on; |
---|
115 | plot(A2_mean','--'); |
---|
116 | plot(MG_mean'); |
---|