LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
mmpp2_fitc_approx.m
1function [FIT] = mmpp2_fitc_approx(a, bt1, bt2, binf, m3t2, ...
2 t1, t2)
3% Fits a second-order Marked MMPP.
4% a: arrival rate
5% bt1: IDC at scale t1
6% bt2: IDC at scale t2
7% binf: IDC for t->inf
8% m3t2: third central moment
9% t1: first time scale
10% t2: second time scale
11
12x1 = optimvar('x1'); % l1
13x2 = optimvar('x2'); % l2
14x3 = optimvar('x3'); % r1
15x4 = optimvar('x4'); % r2
16
17obj = fcn2optimexpr(@compute_obj, x1,x2,x3,x4, 'OutputSize', [1,1]);
18prob = optimproblem('Objective',obj);
19
20prob.Constraints.c1 = x1>=1e-6;
21prob.Constraints.c2 = x2>=1e-6;
22prob.Constraints.c3 = x3>=0;
23prob.Constraints.c4 = x4>=0;
24
25guess = struct;
26guess.x1 = a*3/4;
27guess.x2 = a*3/2;
28guess.x3 = 1/3;
29guess.x4 = 2/3;
30[xopt, fxopt] = solve(prob, guess);
31
32%fprintf('Unified fitting error: %f\n', fxopt);
33FIT = assemble_mmap(xopt.x1, xopt.x2, xopt.x3, xopt.x4);
34% elseif strcmp(method_d0d1,'gs_fmincon') == 1
35% problem = createOptimProblem('fmincon', ...
36% 'objective', @compute_obj, ...
37% 'x0', x0, ...
38% 'lb', lb, ...
39% 'ub', ub, ...
40% 'options', options);
41% [xopt,fxopt] = run(GlobalSearch,problem);
42% %fprintf('Unified fitting error: %f\n', fxopt);
43% FIT = assemble_mmap(xopt);
44% elseif strcmp(method_d0d1,'exact') == 1
45% FIT = mmpp2_fitc(a, bt1, bt2, binf, m3t2, t1, t2);
46% if isempty(FIT)
47% % this occurs when IDC(t) < 1
48% error('Feasibility cannot be repaired.');
49% end
50% else
51% error('Invalid method ''%s''\n', method);
52% end
53
54%fa = map_count_mean(FIT,1);
55%fprintf('Forcing exact rate: from %f to %f\n', fa, a);
56FIT = map_scale(FIT, 1/a);
57fmt2 = map_count_moment(FIT,t2,1:3);
58
59% fa = map_count_mean(FIT,1);
60% fbt1 = map_count_var(FIT,t1)/map_count_mean(FIT,t1);
61% fbt2 = map_count_var(FIT,t2)/map_count_mean(FIT,t2);
62% fbinf = map_count_var(FIT,1e8)/map_count_mean(FIT,1e8);
63% fm3t2 = fmt2(3) - 3*fmt2(2)*fmt2(1) + 2*fmt2(1)^3;
64%fprintf('Rate: input = %.3f, output = %.3f\n', a, fa);
65%fprintf('IDC(t1): input = %.3f, output = %.3f\n', bt1, fbt1);
66%fprintf('IDC(t2): input = %.3f, output = %.3f\n', bt2, fbt2);
67%fprintf('IDC(inf): input = %.3f, output = %.3f\n', binf, fbinf);
68%fprintf('M3(t2): input = %.3f, output = %.3f\n', m3t2, fm3t2);
69
70 function obj = compute_obj (l1,l2,r1,r2)
71 % compute characteristics
72 xa = (l1*r2 + l2*r1)/(r1 + r2);
73 factor = a/xa;
74
75 xbt1 = (r1*(2*l1^2*r2^2*t1*factor - 2*l2^2*r2 - 2*l1^2*r2 + 2*l2^2*r2^2*t1*factor + 4*l1*l2*r2 + 2*l1^2*r2*exp(- r1*t1*factor - r2*t1*factor) + 2*l2^2*r2*exp(- r1*t1*factor - r2*t1*factor) - 4*l1*l2*r2^2*t1*factor - 4*l1*l2*r2*exp(- r1*t1*factor - r2*t1*factor)) + r1^2*(2*r2*t1*factor*l1^2 - 4*r2*t1*factor*l1*l2 + 2*r2*t1*factor*l2^2))/(t1*factor*(r1 + r2)^3*(l1*r2 + l2*r1)) + 1;
76
77 if (t1 ~= t2)
78 xbt2 = (r1*(2*l1^2*r2^2*t2*factor - 2*l2^2*r2 - 2*l1^2*r2 + 2*l2^2*r2^2*t2*factor + 4*l1*l2*r2 + 2*l1^2*r2*exp(- r1*t2*factor - r2*t2*factor) + 2*l2^2*r2*exp(- r1*t2*factor - r2*t2*factor) - 4*l1*l2*r2^2*t2*factor - 4*l1*l2*r2*exp(- r1*t2*factor - r2*t2*factor)) + r1^2*(2*r2*t2*factor*l1^2 - 4*r2*t2*factor*l1*l2 + 2*r2*t2*factor*l2^2))/(t2*factor*(r1 + r2)^3*(l1*r2 + l2*r1)) + 1;
79 end
80
81 xbinf = ((2*r2*l1^2 - 4*r2*l1*l2 + 2*r2*l2^2)*r1^2 + (2*l1^2*r2^2 - 4*l1*l2*r2^2 + 2*l2^2*r2^2)*r1)/((r1 + r2)^3*(l1*r2 + l2*r1)) + 1;
82
83 t = t2*factor;
84 d = r1+r2;
85 p = (l1-l2)*(r1-r2);
86 xg3t = xa^3*t^3 + ...
87 3*xa^2*(xbinf-1)*t^2 + ...
88 3*xa*(xbinf-1)/d*(p/d-xa)*t + ...
89 3*xa/d^2*(xbinf-1)*(p + xa*d)*t*exp(-t*d) - ...
90 6*xa/d^3*(xbinf-1)*p*(1-exp(-t*d));
91 xm3t2 = xg3t - 3*xa*t*(xa*t-1)*xbt2 - xa*t*(xa*t-1)*(xa*t-2);
92 % compute objective
93 obj = 0;
94 obj = obj + (xa/a-1)^2;
95 obj = obj + (xbt1/bt1-1)^2;
96 if t1 ~= t2
97 obj = obj + (xbt2/bt2-1)^2;
98 end
99 obj = obj + (xbinf/binf-1)^2;
100 obj = obj + (xm3t2/m3t2-1)^2;
101
102 end
103
104
105
106 function mmap = assemble_mmap(l1,l2,r1,r2)
107 % assemble
108 D0 = [-(l1+r1), r1; r2, -(l2+r2)];
109 D1 = [l1 0; 0 l2];
110 mmap = {D0, D1};
111 end
112
113end