1 | clear all; |
---|
2 | % name random variables |
---|
3 | y1 = RV({'y1'},1); |
---|
4 | y2 = RV({'y2'},1); |
---|
5 | y3 = RV({'y3'},1); |
---|
6 | u1 = RV({'u1'},1); |
---|
7 | u2 = RV({'u2'},1); |
---|
8 | |
---|
9 | % create f(y_t| y_{t-3}, u_{t-1}) |
---|
10 | fy.class = 'mlnorm<ldmat>'; |
---|
11 | fy.rv = RVjoin([y1,y2,y3]); |
---|
12 | fy.rvc = RVtimes([y1,y2,y3,u1,u1,u2,u2], [-1, -1, -1, 0, -1, 0, -1]); |
---|
13 | fy.A = [0.8 , 0.2 , 0.0 , -0.3 , 0.4 , 0 , 0;... |
---|
14 | -0.2 , 0.5 , -0.8 , 0.2 , 0.5 , -0.2 , -0.5;... |
---|
15 | 0.0 , 1.1 , -0.5 , 0 , 0 , -0.2 , 0.3]; |
---|
16 | fy.const = [0;0;0]; |
---|
17 | fy.R = 0.1*eye(3); |
---|
18 | |
---|
19 | DS.class = 'PdfDS'; |
---|
20 | DS.pdf = fy; |
---|
21 | |
---|
22 | % create ARX estimator |
---|
23 | A1.class = 'ARX'; |
---|
24 | A1.rv = RVjoin([y1,y2]); |
---|
25 | A1.rgr = RVtimes([y1,y2,u1,u1],[-1, -1, 0, -1]) ; % correct structure is {y,y} |
---|
26 | A1.log_level ={'logbounds','loglikelihood'}; |
---|
27 | A1.constant=0; |
---|
28 | A1.frg = 0.99; |
---|
29 | |
---|
30 | A2=A1; |
---|
31 | A2.rv = RVjoin([y2,y3]); |
---|
32 | A2.rgr = RVtimes([y2,y3,u2,u2],[-1, -1, 0, -1]) ; % correct structure is {y,y} |
---|
33 | |
---|
34 | Ag=A1; |
---|
35 | Ag.rv = RVjoin([y1,y2,y3]); |
---|
36 | Ag.rgr = RVtimes([y1,y2,y3,u1,u1,u2,u2],[-1, -1, -1, 0, -1, 0, -1]) ; % correct structure is {y,y} |
---|
37 | Ag.log_level = {'full'}; |
---|
38 | |
---|
39 | C1.class = 'LQG_ARX'; |
---|
40 | C1.ARX = A1; |
---|
41 | C1.Qu = 0.01; |
---|
42 | C1.Qy = 10*eye(2); |
---|
43 | C1.yreq = [0;1]; %y2=1 |
---|
44 | C1.horizon = 300; |
---|
45 | C1.windsurfer = 0; |
---|
46 | |
---|
47 | C2=C1; |
---|
48 | C2.ARX = A2; |
---|
49 | C2.yreq = [1;0]; %y2=1 |
---|
50 | |
---|
51 | Cg.class = 'LQG_ARX'; |
---|
52 | Cg.ARX = Ag; |
---|
53 | Cg.Qu = 0.01*eye(2); |
---|
54 | Cg.Qy = 10*eye(3); |
---|
55 | Cg.yreq = [0;1;0]; %y2=1 |
---|
56 | Cg.horizon = 300; |
---|
57 | |
---|
58 | P1.class = 'ARXAgent'; |
---|
59 | P1.name = 'P1'; |
---|
60 | P1.lqg_arx = C1; |
---|
61 | P1.lqg_arx.class = 'LQG_ARX'; |
---|
62 | P1.merger.class = 'merger_mix'; |
---|
63 | P1.merger.method = 'geometric'; |
---|
64 | %P1.merger.dbg_file = 'mp.it'; |
---|
65 | P1.merger.ncoms = 1; |
---|
66 | P1.merger.stop_niter= 5; |
---|
67 | P1.neighbours = {};%{'P2'}; |
---|
68 | |
---|
69 | P2=P1; |
---|
70 | P2.name = 'P2'; |
---|
71 | P2.lqg_arx = C2; |
---|
72 | P2.neighbours = {}; |
---|
73 | |
---|
74 | Pg=P1; |
---|
75 | Pg.name = 'Pg'; |
---|
76 | Pg.lqg_arx = Cg; |
---|
77 | Pg.neighbours = {}; |
---|
78 | |
---|
79 | exper.Ndat = 200; |
---|
80 | exper.burnin = 10; |
---|
81 | exper.burn_pdf.class = 'enorm<ldmat>'; |
---|
82 | exper.burn_pdf.mu = [0;0]; |
---|
83 | exper.burn_pdf.R = 0.01*eye(2); |
---|
84 | |
---|
85 | |
---|
86 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MONTE CARLO %%%%%%%%%%%%%%%%%%% |
---|
87 | |
---|
88 | Ntrials = 1; |
---|
89 | loss_non_coop = zeros(1,Ntrials); |
---|
90 | for i=1:Ntrials |
---|
91 | M= arena(DS,{P1,P2},exper); |
---|
92 | |
---|
93 | Y = [M.DS_y1 M.DS_y2 M.DS_y3]; |
---|
94 | Yreq = ones(size(M.DS_y1))*[0 1 0]; |
---|
95 | loss_non_coop(i) = trace((Y-Yreq)*Cg.Qy*(Y-Yreq)') + M.DS_u1'*C1.Qu*M.DS_u1 + M.DS_u2'*C1.Qu*M.DS_u2; |
---|
96 | if loss_non_coop(i)>100 |
---|
97 | % keyboard |
---|
98 | end |
---|
99 | end |
---|
100 | mean(loss_non_coop) |
---|
101 | |
---|
102 | loss_glob = zeros(1,Ntrials); |
---|
103 | for i=1:Ntrials |
---|
104 | [M,Set]= controlloop(DS,{Cg},exper); |
---|
105 | |
---|
106 | Y = [M.DS_y1 M.DS_y2 M.DS_y3]; |
---|
107 | Yreq = ones(size(M.DS_y1))*[0 1 0]; |
---|
108 | loss_glob(i) = trace((Y-Yreq)*Cg.Qy*(Y-Yreq)') + M.DS_u1'*C1.Qu*M.DS_u1 + M.DS_u2'*C1.Qu*M.DS_u2; |
---|
109 | if (~isfinite(loss_glob(i))) |
---|
110 | keyboard |
---|
111 | end |
---|
112 | end |
---|
113 | mean(loss_glob) |
---|