LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
mamap22_fit_gamma_bs.m
1function MMAP = mamap22_fit_gamma_bs(M1, M2, M3, GAMMA, P, B, S)
2% Performs approximate fitting of a MMAP given the underlying MAP,
3% the class probabilities (always fitted exactly), the backward moments,
4% and the one-step class transition probabilities.
5% Input
6% - M1,M2,M3: moments of the inter-arrival times
7% - GAMMA: auto-correlation decay rate of the inter-arrival times
8% - P: class probabilities
9% - B: first-order backward moments
10% - S: one-step class transition probabilities
11% Output
12% - mmap: fitted MAMAP[2]
13
14if size(B,1) == 1
15 B = B';
16end
17
18% fit underlying AMAP(2)
19[~,MAPS] = amap2_fit_gamma(M1, M2, M3, GAMMA);
20
21% If Poisson (1 state), try to convert to second-order process
22% with constraint (h1 - h2 + h2*r1 = 0) for backward moment fitting
23if length(MAPS) == 1 && size(MAPS{1}{1},1) == 1
24 M2a = M2 * (1 + 1e-4);
25 M3a = M3 * (M2a/M2)^(3/2);
26 MAPS2 = amap2_fitall_gamma(M1, M2a, M3a, GAMMA);
27 if ~isempty(MAPS2)
28 for j = 1:length(MAPS2)
29 MAPS2{j} = map_normalize(MAPS2{j});
30 end
31 MAPS = MAPS2;
32 else
33 MAP = MAPS{1};
34 m = length(P);
35 MMAP = cell(1,2+m);
36 MMAP{1} = MAP{1};
37 MMAP{2} = MAP{2};
38 for c = 1:m
39 MMAP{2+c} = MMAP{2} .* P(c);
40 end
41 return;
42 end
43end
44
45% fit the MAMAP(2,m) using the underlying AMAP(2) form which produces the
46% least error
47MMAPS = cell(1,length(MAPS));
48ERRORS = zeros(1,length(MAPS));
49for j = 1:length(MAPS)
50 [MMAPS{j},fB,fS] = mamap22_fit_bs_multiclass(MAPS{j}, P, B, S);
51 ERRORS(j) = sum((fB(1)./B(1) - 1).^2) + sum((fS(1,1)./S(1,1) - 1).^2);
52end
53[~,BEST] = min(ERRORS);
54
55MMAP = MMAPS{BEST};
56
57end