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;
13end
14
15if length(limit) ~= 1
16 error('Invalid parameter');
17end
18
19% lag must be set for any limit: it was previously assigned only in the
20% nargin<2 branch, so passing limit explicitly errored for MAPs of order > 2
21lag = 1:(limit/10):limit;
22
23n = size(MAP{1}, 1);
24
25if n == 1
26 % poisson process: no correlation
27 GAMMA = 0;
28elseif n == 2
29 % second-order MAP: geometric ACF
30 if abs(map_acf(MAP,1)) < 1e-8
31 % phase-type
32 GAMMA = 0;
33 else
34 GAMMA = map_acf(MAP,2) / map_acf(MAP,1);
35 end
36else
37 % higher-order MAP: non-geometric
38
39 M1 = map_mean(MAP);
40 M2 = map_moment(MAP, 2);
41 VAR = M2-M1^2;
42 SCV = VAR/M1^2;
43 RHO0 = 1/2 * (1 - 1/SCV);
44
45 rho = map_acf(MAP, lag)';
46
47 %problem.Variables = 1;
48 %problem.LB = -1;
49 %problem.UB = 0.999;
50 %problem.ObjFunction = @(x) sum((geometric(x,lag)-rho).^2);
51 %GAMMA = PSwarm(problem);
52
53 opt = statset('nlinfit');
54 opt.MaxIter = 1e5;
55 opt.Display = 'off';
56 opt.RobustWgtFun = 'fair';
57 try
58 [GAMMA,RESIDUALS] = nlinfit(lag, rho, @geometric, 0.99, opt);
59 catch ME
60 warning('Non linear regression for ACF decay rate failed, trying lsqcurvefit');
61 GAMMA = lsqcurvefit(@geometric, 0.99, lag, rho, -1, 1);
62 end
63end
64
65 function rhok = geometric(gamma,k)
66 rhok = (RHO0 * gamma.^k)';
67 end
68
69end
Definition Station.m:245