LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
m3pp22_interleave_fitc.m
1function [fit,m3pps] = m3pp22_interleave_fitc(av, btv, binfv, stv, t)
2% Fits L pairs of classes into a single MMAP, obtained by lumped
3% superposition of L different M3PP[2] processes.
4% INPUT
5% - av: Matrix of size Lx2 containing the per-class rates.
6% - btv: Vector of length L containing the IDC at resolution t for each
7% pairs of classes.
8% - binfv: Vector of length L containing the asymptotic IDC for each pair
9% of classes.
10% - stv: Vector of length L containing the count covariance, at
11% resolution t, between each pair of classes.
12% OUTPUT
13% - fit: The lumped superposition of the M3PP[2] processes.
14% - m3pps: Cell-array of length L containing the M3PP[2] processes.
15
16% number of pairs
17L = size(av,1);
18
19% vector of lower bounds for the upper off-diagonal elements
20uv = zeros(L,1);
21% vector of upper bounds for the upper off-diagonal elements
22dv = zeros(L,1);
23
24% compute bounds for the upper off-diagonal elment of each mmpp(2)
25for i = 1:L
26 a = sum(av(i,:));
27 d = compute_d(btv(i), binfv(i), t);
28 z = (binfv(i)-1)*d^3*a;
29 u = d*z/(2*a^2*d^2+z);
30 uv(i) = u;
31 dv(i) = d;
32end
33
34% find feasible values for off diagonal elements
35A = zeros(2*L,2*L);
36b = zeros(2*L,1);
37for i = 1:L
38 base = 2*(i-1);
39 for j = 1:L
40 if j >= i
41 A(base+1,j) = 1;
42 A(base+2,j) = -1;
43 end
44 end
45 b(base+1) = dv(i)-1e-6;
46 b(base+2) = -uv(i)-1e-6;
47end
48Aeq = zeros(L,2*L);
49beq = zeros(L,1);
50for i = 1:L
51 for j = 1:L
52 if j >= i
53 Aeq(i,j) = 1;
54 end
55 end
56 for j = 1:L
57 if j <= i
58 Aeq(i,j+L) = 1;
59 end
60 end
61 beq(i) = dv(i);
62end
63f = zeros(2*L,1);
64x = linprog(f, A, b, Aeq, beq, zeros(2*L,1), [], []);
65r = zeros(2,L);
66r(1,:) = x(1:L);
67r(2,:) = x((L+1):(2*L));
68
69% fit m3pp[2] processes
70m3pps = cell(L,1);
71for i = 1:L
72 % fit underling mmpp(2)
73 r1 = 0;
74 r2 = 0;
75 for j = 1:L
76 if j >= i
77 r1 = r1 + r(1,j);
78 end
79 if j <= i
80 r2 = r2 + r(2,j);
81 end
82 end
83 mmpp = cell(1,2);
84 mmpp{1}(1,2) = r1;
85 mmpp{1}(2,1) = r2;
86 a = sum(av(i,:));
87 d = r1 + r2;
88 z = (binfv(i)-1)*d^3*a;
89 delta = sqrt(z/(2*r1*r2));
90 l2 = a - r2/d * delta;
91 l1 = l2 + delta;
92 mmpp{2}(1,1) = l1;
93 mmpp{2}(2,2) = l2;
94 drates = -sum(mmpp{1}+mmpp{2},2);
95 for j = 1:2
96 mmpp{1}(j,j) = drates(j);
97 end
98 % variance
99 v = map_count_var(mmpp, t);
100 fprintf('MMPP %d - Var(t): %d\n', i, v);
101 % fit m3pp(2,2)
102 m3pps{i} = m3pp22_fitc_approx_cov_multiclass(mmpp, av(i,:)', stv(i), t);
103end
104
105% fit lumped
106fit = m3pp2m_interleave(m3pps);
107
108 % solve non-linear equation to fit underlying mmpp(2)
109 function d = compute_d(bt1,binf,t1)
110 if ~(binf>bt1 && bt1>1)
111 error('No solution, infeasible IDC(t): IDC(%.2f) = %.3f, IDC(inf) = %.3f\n',...
112 t1, bt1, binf);
113 end
114 % d = r1 + r2
115 c = (binf-1)/(binf-bt1);
116 % according to WolframAlpha
117 % the solution can be written as (ProductLog[-c e^(-c)]+c)/t1
118 z = -c*exp(-c);
119 w = fsolve(@(w) z-w*exp(w), 1, optimset('Display','none',...
120 'MaxIter',10000,...
121 'MaxFunEvals',10000,...
122 'TolFun', 1.0e-12,...
123 'TolX',1.0e-12));
124 d = (w + c)/t1;
125 end
126
127end