LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
map_gamma.m
1function [GAMMA, RHO0, RESIDUALS] = map_gamma(MAP, limit)
2% Estimates the auto-correlation decay rate of a MAP.
3% For MAPs of order higher than 2, performs an approximation of the ACF
4% curve using non-linear least squares fitting.
5% Input:
6% - MAP: the MAP
7% - limit: maximum lag considered (optional, default = 1000)
8% Output:
9% - GAMMA: autocorrelation decay rate
10
11if nargin < 2
12 limit = 1000;
13 lag = 1:(limit/10):limit;
14end
15
16if length(limit) ~= 1
17 error('Invalid parameter');
18end
19
20n = size(MAP{1}, 1);
21
22if n == 1
23 % poisson process: no correlation
24 GAMMA = 0;
25elseif n == 2
26 % second-order MAP: geometric ACF
27 if abs(map_acf(MAP,1)) < 1e-8
28 % phase-type
29 GAMMA = 0;
30 else
31 GAMMA = map_acf(MAP,2) / map_acf(MAP,1);
32 end
33else
34 % higher-order MAP: non-geometric
35
36 M1 = map_mean(MAP);
37 M2 = map_moment(MAP, 2);
38 VAR = M2-M1^2;
39 SCV = VAR/M1^2;
40 RHO0 = 1/2 * (1 - 1/SCV);
41
42 rho = map_acf(MAP, lag)';
43
44 %problem.Variables = 1;
45 %problem.LB = -1;
46 %problem.UB = 0.999;
47 %problem.ObjFunction = @(x) sum((geometric(x,lag)-rho).^2);
48 %GAMMA = PSwarm(problem);
49
50 opt = statset('nlinfit');
51 opt.MaxIter = 1e5;
52 opt.Display = 'off';
53 opt.RobustWgtFun = 'fair';
54 try
55 [GAMMA,RESIDUALS] = nlinfit(lag, rho, @geometric, 0.99, opt);
56 catch ME
57 warning('Non linear regression for ACF decay rate failed, trying lsqcurvefit');
58 GAMMA = lsqcurvefit(@geometric, 0.99, lag, rho, -1, 1);
59 end
60end
61
62 function rhok = geometric(gamma,k)
63 rhok = (RHO0 * gamma.^k)';
64 end
65
66end