1 | % name random variables |
---|
2 | y = RV({'y'},1); |
---|
3 | u1 = RV({'u1'},1); |
---|
4 | u2 = RV({'u2'},1); |
---|
5 | |
---|
6 | % create f(y_t| y_{t-3}, u_{t-1}) |
---|
7 | fy.class = 'mlnorm<ldmat>'; |
---|
8 | fy.rv = y; |
---|
9 | fy.rvc = RVtimes([y,u1,u2], [-3, 0, 0]); |
---|
10 | fy.A = [0.5, -0.9, 0.9]; |
---|
11 | fy.const = 0; |
---|
12 | fy.R = 1e-2; |
---|
13 | |
---|
14 | DS.class = 'PdfDS'; |
---|
15 | DS.pdf = fy; |
---|
16 | |
---|
17 | % create ARX estimator |
---|
18 | A1.class = 'ARX'; |
---|
19 | A1.rv = y; |
---|
20 | A1.rgr = RVtimes([y,u1],[-3,0]) ; % correct structure is {y,y} |
---|
21 | A1.options ='logbounds,logll'; |
---|
22 | A1.frg = 0.95; |
---|
23 | |
---|
24 | A2=A1; |
---|
25 | A2.rgr = RVtimes([y,u2],[-3,0]) ; % correct structure is {y,y} |
---|
26 | |
---|
27 | |
---|
28 | C1.class = 'LQG_ARX'; |
---|
29 | C1.ARX = A1; |
---|
30 | C1.Qu = 0.01*eye(1); |
---|
31 | C1.Qy = 1*eye(1); |
---|
32 | C1.yreq = 1; |
---|
33 | C1.horizon = 1; |
---|
34 | |
---|
35 | C2=C1; |
---|
36 | C2.ARX = A2; |
---|
37 | |
---|
38 | P1.class = 'ARXAgent'; |
---|
39 | P1.name = 'P1'; |
---|
40 | P1.lqg_arx = C1; |
---|
41 | P1.lqg_arx.class = 'LQG_ARX'; |
---|
42 | P1.merger.class = 'merger_mix'; |
---|
43 | P1.merger.method = 'geometric'; |
---|
44 | %P1.merger.dbg_file = 'mp.it'; |
---|
45 | P1.merger.ncoms = 20; |
---|
46 | P1.merger.stop_niter= 5; |
---|
47 | P1.neighbours = {};%{'P2'}; |
---|
48 | |
---|
49 | P2=P1; |
---|
50 | P2.name = 'P2'; |
---|
51 | P2.lqg_arx = C2; |
---|
52 | P2.neighbours = {}; |
---|
53 | |
---|
54 | exper.Ndat = 10; |
---|
55 | exper.burnin = 3; |
---|
56 | exper.burn_pdf.class = 'enorm<ldmat>'; |
---|
57 | exper.burn_pdf.mu = [0;0]; |
---|
58 | exper.burn_pdf.R = 0.01*eye(2); |
---|
59 | |
---|
60 | |
---|
61 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MONTE CARLO %%%%%%%%%%%%%%%%%%% |
---|
62 | |
---|
63 | Ntrials = 3; |
---|
64 | loss_non_coop = zeros(1,Ntrials); |
---|
65 | for i=1:Ntrials |
---|
66 | M= arena(DS,{P1,P2},exper); |
---|
67 | |
---|
68 | loss_non_coop(i) = (M.DS_y-C1.yreq)'*C1.Qy*(M.DS_y-C1.yreq) + M.DS_u1'*C1.Qu*M.DS_u1 + M.DS_u2'*C1.Qu*M.DS_u2; |
---|
69 | if loss_non_coop(i)>100 |
---|
70 | %keyboard |
---|
71 | end |
---|
72 | end |
---|
73 | mean(loss_non_coop) |
---|
74 | |
---|
75 | loss_coop = zeros(1,Ntrials); |
---|
76 | for i=1:Ntrials |
---|
77 | P1.neighbours = {'P2'}; |
---|
78 | P2.neighbours = {'P1'}; |
---|
79 | M= arena(DS,{P1,P2},exper); |
---|
80 | |
---|
81 | loss_coop(i) = (M.DS_y-C1.yreq)'*C1.Qy*(M.DS_y-C1.yreq) + M.DS_u1'*C1.Qu*M.DS_u1 + M.DS_u2'*C1.Qu*M.DS_u2; |
---|
82 | if loss_coop(i)>100 |
---|
83 | %keyboard |
---|
84 | end |
---|
85 | end |
---|
86 | mean(loss_coop) |
---|
87 | |
---|