LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
mamap2m_fit_gamma_fb.m
1function MMAP = mamap2m_fit_gamma_fb(M1, M2, M3, GAMMA, P, F, B)
2% Computes the second-order MAMAP[m] fitting the given ordinary moments
3% (of order up to three), the autocorrelation decay rate,
4% the class probabilities (always fitted exactly), the forward moments,
5% and the backward moments.
6%
7% Input
8% - M1,M2,M3: moments of the inter-arrival times
9% - GAMMA: auto-correlation decay rate of the inter-arrival times
10% - P: class probabilities
11% - F: first-order forward moments
12% - B: first-order backward moments
13% Output
14% - mmap: fitted MAMAP[m]
15
16if size(F,1) == 1
17 F = F';
18end
19
20if size(B,1) == 1
21 B = B';
22end
23
24% fit underlying AMAP(2)
25% up to four equivalent AMAP(2) representations may be found
26[~,MAPS] = amap2_fit_gamma(M1, M2, M3, GAMMA);
27
28% fit marked Poisson process
29if length(MAPS) == 1 && size(MAPS{1}{1},1) == 1
30 MAP = MAPS{1};
31 % number of classes
32 m = length(P);
33 % fit class probabilities
34 MMAP = cell(1,2+m);
35 MMAP{1} = MAP{1};
36 MMAP{2} = MAP{2};
37 for c = 1:m
38 MMAP{2+c} = MMAP{2} .* P(c);
39 end
40 return;
41end
42
43% use the underlying AMAP(2) form which produces the least error
44MMAPS = cell(1,length(MAPS));
45ERRORS = zeros(1,length(MAPS));
46for j = 1:length(MAPS)
47 [MMAPS{j},fF,fB] = mamap2m_fit_fb_multiclass(MAPS{j}, P, F, B);
48 ERRORS(j) = sum((fF./F - 1).^2) + sum((fB./B - 1).^2);
49end
50[~,BEST] = min(ERRORS);
51%fprintf('Fitting MAMAP(2,m) F+B: minimum error is %e\n', ERRORS(BEST));
52
53MMAP = MMAPS{BEST};
54
55end