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% m3a_printf('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% m3a_printf('Fitting AMAP(2): %d approximate solutions\n', length(AMAPS));
34% m3a_printf('Fitting AMAP(2): M2 = %f -> %f\n', M2, M2a);
35% m3a_printf('Fitting AMAP(2): M3 = %f -> %f\n', M3, M3a);
36% m3a_printf('Fitting AMAP(2): GAMMA = %f -> %f\n', GAMMA, GAMMAa);
37% end
38else
39% m3a_printf('Fitting AMAP(2): %d exact solutions\n', length(AMAPS));
40end
41
42% if feasibility could not be restored (e.g. extreme moments from a
43% near-null flow), fall back to a Poisson process matching the mean, as in
44% the CV=1 branch above. This keeps the mean exact and yields a valid
45% order-1 representation that downstream marked-fitting consumes.
46if isempty(AMAPS)
47 AMAP = {-1/M1, 1/M1};
48 AMAPS = {AMAP};
49 return;
50end
51
52AMAP = AMAPS{1};
53
54end
Definition Station.m:245