1function [FIT] = m3pp22_fitc_approx_cov_multiclass(mmpp, ai, st3, t3)
2% Fits a M3PP(2,2) given the underlying MMPP(2).
4% - mmpp: underlying mmpp(2)
6% - st3: count covariance between the two
classes at scale t3
7% - t3: third time scale
13 error('No more than two
classes supported');
18% degenerate case: poisson process
35 FIT = {FIT{1},FIT{2},FIT{2}};
45w0 = (2*r1*(1 - exp(-(r1+r2)*t)- (r1+r2)*t)*(a1^2*(r1+r2)-a1*r2*(l1-l2)))/(r2*(r1+r2)^3);
46w1 = -(2*r1*(1 - exp(-(r1+r2)*t)- (r1+r2)*t)*(2*a1*l2*(r1+r2)-l2*r2*(l1-l2)))/(r2*(r1 + r2)^3);
47w2 = ((2*l2^2*r2*t)*(r1+r2) + 2*l2^2*r1*(1 - exp(-(r1+r2)*t)))/(r2*(r1 + r2)^2) - (2*l2^2*t)/r2;
51% bounds
for the first and the second root
55%
if set to 1, the first (second) root
is never feasible
59% defined
for convenience
62% impose square root argument
is >= 0
89 U1 = min(U1, z + tmp^2/(4*w2));
95 L2 = max(L2, z + tmp^2/(4*w2));
104 U1 = min(U1, z + tmp^2/(4*w2));
110 L2 = max(L2, z + tmp^2/(4*w2));
116tmp = (2*a1*w2*w3-2*w2*w4+w1);
119 L1 = max(L1, z + tmp^2/(4*w2));
125 U2 = min(U2, z + tmp^2/(4*w2));
130if infeasible1 && infeasible2
131 error(
'Empty feasibility region. This should not happen.');
134% compute feasible covariance
136 sigma = max(min(st3,U1), L1);
139 sigma = max(min(st3,U2), L2);
142 sigma1 = max(min(st3,U1), L1);
143 sigma2 = max(min(st3,U2), L2);
144 if abs(sigma1-st3) < abs(sigma2-st3)
155 q2 = (-w1 + sqrt(w1^2 - 4*w2*(w0-sigma)) )/(2*w2);
157 q2 = (-w1 - sqrt(w1^2 - 4*w2*(w0-sigma)) )/(2*w2);
159q1 = ( a1*(r1 + r2) - l2*q2*r1 )/(l1*r2);
161% check feasibility just to be sure
163if (q1 >= tol && q1 <= 1+tol) && (q2 >= tol && q2 <= 1+tol)
164 q1 = min(max(q1,0),1);
165 q2 = min(max(q2,0),1);
167 error(
'Parameters are infeasible. This should not happen.');
173FIT = {D0, D1, D1 .* [q1 0; 0 q2], D1 .* [(1-q1) 0; 0 (1-q2)]};
175% print per-
class rates and covariance
176% fai = mmap_count_mean(FIT,1);
178% fprintf(
'Rate class %d: input = %.3f, output = %.3f\n', ...
181% fsigma = 1/2*( map_count_var(FIT,t3) - sum(mmap_count_var(FIT,t3)) );
182% fprintf(
'Covariance(t3): input = %.4f, output = %.4f\n', st3, fsigma);