1function [FIT] = mmpp2_fitc_approx(a, bt1, bt2, binf, m3t2, ...
3% Fits a second-order Marked MMPP.
8% m3t2: third central moment
10% t2: second time scale
12x1 = optimvar(
'x1'); % l1
13x2 = optimvar(
'x2'); % l2
14x3 = optimvar(
'x3'); % r1
15x4 = optimvar(
'x4'); % r2
17obj = fcn2optimexpr(@compute_obj, x1,x2,x3,x4,
'OutputSize', [1,1]);
18prob = optimproblem(
'Objective',obj);
20prob.Constraints.c1 = x1>=1e-6;
21prob.Constraints.c2 = x2>=1e-6;
22prob.Constraints.c3 = x3>=0;
23prob.Constraints.c4 = x4>=0;
30[xopt, fxopt] = solve(prob, guess);
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, ...
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);
47% %
this occurs when IDC(t) < 1
48% error(
'Feasibility cannot be repaired.');
51% error(
'Invalid method ''%s''\n', method);
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);
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);
70 function obj = compute_obj (l1,l2,r1,r2)
71 % compute characteristics
72 xa = (l1*r2 + l2*r1)/(r1 + r2);
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;
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;
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;
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);
94 obj = obj + (xa/a-1)^2;
95 obj = obj + (xbt1/bt1-1)^2;
97 obj = obj + (xbt2/bt2-1)^2;
99 obj = obj + (xbinf/binf-1)^2;
100 obj = obj + (xm3t2/m3t2-1)^2;
106 function mmap = assemble_mmap(l1,l2,r1,r2)
108 D0 = [-(l1+r1), r1; r2, -(l2+r2)];