1function [AMAP,AMAPS] = amap2_fit_gamma(M1, M2, M3, GAMMA)
2% Finds an AMAP(2) fitting the given characteristics.
4% - M1, M2, M3: moments of the inter-arrival times
5% - GAMMA: auto-correlation decay rate of the inter-arrival times
7% - AMAP: the fitted AMAP(2)
8% - AMAPS: all the fitted AMAP(2)
10% if coefficient of variation
is equal to 1, fit marked poisson
11if abs(M2 - 2 * M1^2) < 1e-6
12% fprintf('Fitting AMAP(2): CV = 1, fitting a Poisson process\n');
18% find all solutions
for the parameters
19AMAPS = amap2_fitall_gamma(M1, M2, M3, GAMMA);
20for j = 1:length(AMAPS)
21 AMAPS{j} = map_normalize(AMAPS{j});
24%
if no solutions
is found, perform approximate fitting
26 % find feasible characteristics
27 [M2a, M3a, GAMMAa] = amap2_adjust_gamma(M1, M2, M3, GAMMA);
28 % fit (should found at least one solution)
29 AMAPS = amap2_fitall_gamma(M1, M2a, M3a, GAMMAa);
31% error(
'Fitting AMAP(2): feasibility could not be restored');
33% fprintf(
'Fitting AMAP(2): %d approximate solutions\n', length(AMAPS));
34% fprintf(
'Fitting AMAP(2): M2 = %f -> %f\n', M2, M2a);
35% fprintf(
'Fitting AMAP(2): M3 = %f -> %f\n', M3, M3a);
36% fprintf(
'Fitting AMAP(2): GAMMA = %f -> %f\n', GAMMA, GAMMAa);
39% fprintf(
'Fitting AMAP(2): %d exact solutions\n', length(AMAPS));