1function mmpp = mmpp2_fitc(mu, bt1, bt2, binf, m3t2, t1, t2)
2% Fits a MMPP according to [Heffes and Lucantoni, 1986].
7% m3t2: third central moment
11if abs(binf-1) < 1e-8 && abs(binf-bt1) < 1e-8
12 % degenerate
case, r2 = 0
13 % therefore never goes back to state 1
14 % fit a marked poisson process
15 %fprintf(
'Warning: marked Poisson process, constant IDC(t) = 1\n');
20if ~(binf>bt1 && bt1>1)
21 %fprintf(
'Warning: no valid MMPP(2), infeasible IDC(t): IDC(%.2f) = %.3f, IDC(inf) = %.3f\n', t1, bt1, binf);
28c = (binf-1)/(binf-bt1);
29% according to WolframAlpha
30% the solution can be written as (ProductLog[-c e^(-c)]+c)/t1
32w = fsolve(@(w) z-w*exp(w), 1, optimset(
'Display',
'none',...
34 'MaxFunEvals',10000,...
40k2 = 3*mu^2*(binf-1)*t2^2;
41k3 = 3*mu*(binf-1)/x*t2;
42k4 = 3*mu/x^2*(binf-1)*t2*exp(-x*t2);
43k5 = 6*mu/x^3*(binf-1)*(1-exp(-x*t2));
44g1t2 = m3t2 + 3*mu*t2*(mu*t2-1)*bt2 + mu*t2*(mu*t2-1)*(mu*t2-2);
45h = (g1t2 - k1 - k2 - k3*(-mu) - k4*mu*x) / ((k3/x) + k4 -k5);
46if abs(h) < 1e-4 % h=0
case
49 l2 = mu - 1/2 * sqrt(2*(binf-1)*mu*x);
50 l1 = mu + 1/2 * sqrt(2*(binf-1)*mu*x);
52 y = (binf-1)*mu*x^3/(2*h^2);
53 r1 = x/2 * (1 + 1/sqrt(4*y + 1));
61 w_min = -mu/r1*(r1+r2);
62 w_max = mu/r2*(r1+r2);
63 if (w < w_min || w > w_max)
64 %fprintf(
'Warning: ignoring third moment to achieve feasibility\n');
66 u = x*z/(2*mu^2*x^2+z);
69 delta = sqrt(z/(2*r1*r2));
70 l2 = mu - r2/x * delta;
73 l2 = mu - h/(r1-r2)*(r2/(r1+r2));
78mmpp = {[-(r1+l1) r1; r2 -(r2+l2)], [l1 0; 0 l2]};