LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
amap2_fit_gamma.m
1function [AMAP,AMAPS] = amap2_fit_gamma(M1, M2, M3, GAMMA)
2% Finds an AMAP(2) fitting the given characteristics.
3% Input:
4% - M1, M2, M3: moments of the inter-arrival times
5% - GAMMA: auto-correlation decay rate of the inter-arrival times
6% Output:
7% - AMAP: the fitted AMAP(2)
8% - AMAPS: all the fitted AMAP(2)
9
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');
13 AMAP = {-1/M1, 1/M1};
14 AMAPS = {AMAP};
15 return;
16end
17
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});
22end
23
24% if no solutions is found, perform approximate fitting
25if isempty(AMAPS)
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);
30% if isempty(AMAPS)
31% error('Fitting AMAP(2): feasibility could not be restored');
32% else
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);
37% end
38else
39% fprintf('Fitting AMAP(2): %d exact solutions\n', length(AMAPS));
40end
41
42AMAP = AMAPS{1};
43
44end