LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
m3pp2m_fitc_trace.m
1function [fit] = m3pp2m_fitc_trace(T, A, method, t1, tinf)
2% Fits the theoretical characteristics of a MMAP(n,m) with a M3PP(2,m).
3% INPUT:
4% - mmap: the MMAP(n,m) to fit with a M3PP(2,m)
5% - method: 'exact_delta', 'approx_delta', 'approx_cov' or 'approx_ag'
6
7labels = unique(A);
8m = length(labels);
9
10if nargin < 3
11 method = 'approx_delta';
12end
13
14if strcmp(method,'approx_cov') && m > 2
15 error('Approximate covariance fitting only supported for two classes.');
16end
17
18TC = cumsum(T);
19
20if nargin <= 3
21 t1 = 10*mean(T);
22 tinf = max(10*t1, (TC(end)-TC(1)) / 100);
23end
24t2 = t1+mean(T);
25t3 = tinf; % this controls the approximation - GC changed from t1 to tinf
26
27fprintf('Computing counting process at resolution %f\n', t1);
28mNt1 = mtrace_iat2counts(T, A, t1);
29mNt2 = mNt1;
30fprintf('Computing counting process at resolution %f\n', tinf);
31mNtinf = mtrace_iat2counts(T, A, tinf);
32mNt3 = mNt1;
33
34Nt1 = sum(mNt1, 2);
35Nt2 = sum(mNt2, 2);
36Ntinf = sum(mNtinf, 2);
37
38% total rate
39a = 1/mean(T);
40
41% per-class rates
42ai = zeros(m,1);
43for i = 1:m
44 ai(i) = a * sum(A == labels(i))/length(A);
45end
46
47fprintf('Rate: %f\n', a);
48
49% joint-process charactersitics
50bt1 = var(Nt1)/(a*t1);
51bt2 = bt1;
52binf = var(Ntinf)/(a*tinf);
53mt2 = [mean(Nt2), mean(Nt2.^2), mean(Nt2.^3)];
54m3t2 = mt2(3) - 3*mt2(2)*mt2(1) + 2*mt2(1)^3;
55
56if strcmp(method,'exact_delta') == 1 || strcmp(method,'approx_delta') == 1
57 % per-class variance differential
58 dvt3 = zeros(m,1);
59 for i = 1:m
60 N2 = [mNt3(:,i), sum(mNt3,2)-mNt3(:,i)];
61 Vt3 = [var(N2(:,1)), var(N2(:,2))];
62 dvt3(i) = Vt3(1)-Vt3(2);
63 end
64end
65
66if strcmp(method,'exact_delta') == 1
67 fit = m3pp2m_fitc(a, bt1, bt2, binf, m3t2, t1, t2, ai, dvt3, t3);
68elseif strcmp(method,'approx_delta') == 1
69 fit = m3pp2m_fitc_approx(a, bt1, bt2, binf, m3t2, t1, t2, ai, dvt3, t3);
70elseif strcmp(method,'approx_cov') == 1
71 V = var(sum(mNt3,2));
72 vi = [var(mNt3(:,1)), var(mNt3(:,2))];
73 s = 0.5 * (V - sum(vi));
74 fit = m3pp22_fitc_approx_cov(a, bt1, bt2, binf, m3t2, t1, t2, ai, s, t3);
75elseif strcmp(method,'approx_ag') == 1
76 vt3 = var(mNt3)';
77 st3 = zeros(m,1);
78 for i = 1:m
79 covt3 = cov(mNt3(:,i), sum(mNt3,2)-mNt3(:,i));
80 st3(i) = covt3(1,2);
81 end
82 gt3 = vt3 + st3;
83 fit = m3pp2m_fitc_approx_ag(a, bt1, bt2, binf, m3t2, t1, t2, ai, gt3, t3);
84else
85 error('Invalid method ''%s\''', method);
86end
87
88end