root/applications/bdmtoolbox/tutorial/mpdm/dist_ctrl_lss.m @ 1211

Revision 888, 2.5 kB (checked in by smidl, 15 years ago)

m files in bdmtoolbox

Line 
1clear all;
2% name random variables
3y1 = RV({'y1'},1);
4y2 = RV({'y2'},1);
5y3 = RV({'y3'},1);
6u1 = RV({'u1'},1);
7u2 = RV({'u2'},1);
8
9% create f(y_t| y_{t-3}, u_{t-1})
10fy.class = 'mlnorm<ldmat>';
11fy.rv    = RVjoin([y1,y2,y3]);
12fy.rvc   = RVtimes([y1,y2,y3,u1,u1,u2,u2], [-1, -1, -1, 0, -1, 0, -1]);
13fy.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];
16fy.const = [0;0;0];
17fy.R     = 0.1*eye(3);
18
19DS.class = 'PdfDS';
20DS.pdf = fy;
21
22% create ARX estimator
23A1.class = 'ARX';
24A1.rv = RVjoin([y1,y2]);
25A1.rgr = RVtimes([y1,y2,u1,u1],[-1, -1, 0, -1]) ; % correct structure is {y,y}
26A1.log_level ={'logbounds','loglikelihood'};
27A1.constant=0;
28A1.frg = 0.99;
29
30A2=A1;
31A2.rv = RVjoin([y2,y3]);
32A2.rgr = RVtimes([y2,y3,u2,u2],[-1, -1, 0, -1]) ; % correct structure is {y,y}
33
34Ag=A1;
35Ag.rv = RVjoin([y1,y2,y3]);
36Ag.rgr = RVtimes([y1,y2,y3,u1,u1,u2,u2],[-1, -1, -1, 0, -1, 0, -1]) ; % correct structure is {y,y}
37Ag.log_level = {'full'};
38
39C1.class = 'LQG_ARX';
40C1.ARX = A1;
41C1.Qu = 0.01;
42C1.Qy = 10*eye(2);
43C1.yreq = [0;1]; %y2=1
44C1.horizon = 300;
45C1.windsurfer = 0;
46
47C2=C1;
48C2.ARX = A2;
49C2.yreq = [1;0]; %y2=1
50
51Cg.class = 'LQG_ARX';
52Cg.ARX = Ag;
53Cg.Qu = 0.01*eye(2);
54Cg.Qy = 10*eye(3);
55Cg.yreq = [0;1;0]; %y2=1
56Cg.horizon = 300;
57
58P1.class = 'ARXAgent';
59P1.name = 'P1';
60P1.lqg_arx = C1;
61P1.lqg_arx.class = 'LQG_ARX';
62P1.merger.class = 'merger_mix';
63P1.merger.method = 'geometric';
64%P1.merger.dbg_file = 'mp.it';
65P1.merger.ncoms = 1;
66P1.merger.stop_niter= 5;
67P1.neighbours = {};%{'P2'};
68
69P2=P1;
70P2.name = 'P2';
71P2.lqg_arx = C2;
72P2.neighbours = {};
73
74Pg=P1;
75Pg.name = 'Pg';
76Pg.lqg_arx = Cg;
77Pg.neighbours = {};
78
79exper.Ndat = 200;
80exper.burnin = 10;
81exper.burn_pdf.class = 'enorm<ldmat>';
82exper.burn_pdf.mu = [0;0];
83exper.burn_pdf.R  = 0.01*eye(2);
84
85
86%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MONTE CARLO %%%%%%%%%%%%%%%%%%%
87
88Ntrials = 1;
89loss_non_coop = zeros(1,Ntrials);
90for 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
99end
100mean(loss_non_coop)
101
102loss_glob = zeros(1,Ntrials);
103for 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
112end
113mean(loss_glob)
Note: See TracBrowser for help on using the browser.