1function [fit,m3pps] = m3pp_interleave_fitc(av, btv, binfv, ...
2 acc, gtcc, t, tinf, ...
4% Fits k second-order M3PP[m_j] and interleaves them into a
5% M3PP[m] of order k+1, with m = \sum_j=1^k m_j.
8% av: vector of length k with the per-process rate
9% btv: vector of length k with the per-process IDC(t)
10% binfv: vector of length k with the per-process IDC(inf)
11% acc: cell-array of length k; j-th element
is a vector of length m_j
12% with the per-
class rates in the j-th M3PP
13% gtcc: cell-array of length k; j-th element
is a vector of length m_j
14% with the per-
class variance + marginal_covariance in the j-th
17% tinf: near-infinite time scale
18% mapping: binary m x k matrix mapping
classes to processes
19% reorder: (optional,
default = 1), enables reordering
22% fit: result of the interleaving, M3PP[m] of order k+1
23% m3pps: cell-array with the fitted and interleaved second-order
30% get number of partitions
33% number of
classes for each partition
36 mv(j) = length(acc{j});
44 if abs(av(j)-sum(acc{j})) > 1e-8
45 error(
'Inconsistent per-class rates in the %-th partition', j);
49% vector of lower bounds
for the upper off-diagonal elements
51% vector of upper bounds
for the upper off-diagonal elements
54% compute bounds
for the upper off-diagonal elment of each mmpp(2)
57 d = compute_d(btv(j), binfv(j)*(1+1e-4), t);
59 d = compute_d(btv(j), binfv(j), t);
61 z = (binfv(j)-1)*d^3*av(j);
62 u = d*z/(2*av(j)^2*d^2+z);
67% find feasible values for off diagonal elements
69 [r,tran] = compute_feasible_interleave(uv,dv);
72 [r,tran,order] = compute_feasible_interleave_reorder(uv,dv);
75% compute position of each class
78 % process modeling this class
79 j = find(mapping(c,:) == 1);
80 % position of the process
81 jpos = find(order == j);
82 % compute class position
86 cpos(c) = cpos(c) + sum(mapping(:,h));
88 cpos(c) = cpos(c) + sum(mapping(1:c,j));
91% fit m3pp[m_j] processes
94 % get process in o-th position
96 % fit underlying mmpp(2)
106 z = (binfv(j)-1)*d^3*av(j);
107 delta = sqrt(z/(2*r1*r2));
108 l2 = av(j) - r2/d * delta;
123 drates = -sum(mmpp{1}+mmpp{2},2);
125 mmpp{1}(h,h) = drates(h);
127 % get vectors of per-
class characteristics
131 m3pps{o} = m3pp2m_fitc_approx_ag_multiclass(mmpp, acj, gtcj, t);
137 m = m + length(acc{j});
140% compute interleaving
141fit_unordered = m3pp2m_interleave(m3pps);
145fit{1} = fit_unordered{1};
146fit{2} = fit_unordered{2};
148 fit{2+i} = fit_unordered{2+cpos(i)};
151% check feasibility and normalize
152if ~mmap_isfeasible(fit, 1e-10)
153 warning('Fitted
MMAP infeasibile at tolerance 1e-10\n');
155fit = mmap_normalize(fit);
157% find mapping of
classes to the m3pps
161 j = find(mapping(i,:) == 1);
162 o = sum(mapping(1:i,j));
169fa = map_count_mean(fit,1);
174 ac(i) = acc{J(i)}(O(i));
176fac = mmap_count_mean(fit,1);
178% compare characteristics
179fprintf(
'Rate: input = %f, %f\n', a, fa);
181 fprintf(
'Class %d, rate: input = %f, output = %f\n', i, ac(i), fac(i));
188 m3pp2{3} = zeros(k+1,k+1);
191 m3pp2{3} = m3pp2{3} + fit{2+i};
194 m3pp2{4} = m3pp2{2}-m3pp2{3};
195 fvj = mmap_count_var(m3pp2,t);
196 fbtv(j) = fvj(1)/(av(j)*t);
199 fprintf(
'Partition %d, IDC(%.2f): input = %f, output = %f\n', j, t, btv(j), fbtv(j));
202fbinfv_limit = zeros(k,1);
207 m3pp2{3} = zeros(k+1,k+1);
210 m3pp2{3} = m3pp2{3} + fit{2+i};
213 m3pp2{4} = m3pp2{2}-m3pp2{3};
214 fvj = mmap_count_var(m3pp2,tinf);
215 fbinfv(j) = fvj(1)/(av(j)*tinf);
216 fvj = mmap_count_var(m3pp2, 1e6);
217 fbinfv_limit(j) = fvj(1)/(av(j)*1e6);
220 fprintf(
'Partition %d, IDC(inf = %.2f): input = %f, output = %f, output_limit = %f\n', j, tinf, binfv(j), fbinfv(j), fbinfv_limit(j));
222fvtc = mmap_count_var(fit,t);
231 m3pp3{4} = zeros(k+1,k+1);
233 if h ~= i && mapping(h,j) == 1
238 covji = mmap_count_mcov(
m3pp3, t);
239 fprintf(
'gamma(%d): ', i);
240 fprintf(
'input = %f, output = %f\n', gtcc{j}(n), fvtc(i) + covji(1,2));
246 % solve non-linear equation to fit underlying mmpp(2)
247 function d = compute_d(bt1,binf,t1)
248 if ~(binf>bt1 && bt1>1)
249 error('No solution, infeasible IDC(t): IDC(%.2f) = %.3f, IDC(inf) = %.3f\n',...
253 g = (binf-1)/(binf-bt1);
254 % according to WolframAlpha
255 % the solution can be written as (ProductLog[-c e^(-c)]+c)/t1
257 w = fsolve(@(w) z-w*exp(w), 1, optimset('Display','none',...
259 'MaxFunEvals',10000,...
260 'TolFun', 1.0e-12,...