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.
7% - limit: maximum lag considered (optional,
default = 1000)
9% - GAMMA: autocorrelation decay rate
16 error(
'Invalid parameter');
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;
26 % poisson process: no correlation
29 % second-order MAP: geometric ACF
30 if abs(map_acf(MAP,1)) < 1e-8
34 GAMMA = map_acf(MAP,2) / map_acf(MAP,1);
37 % higher-order MAP: non-geometric
40 M2 = map_moment(MAP, 2);
43 RHO0 = 1/2 * (1 - 1/SCV);
45 rho = map_acf(MAP, lag)
';
47 %problem.Variables = 1;
50 %problem.ObjFunction = @(x) sum((geometric(x,lag)-rho).^2);
51 %GAMMA = PSwarm(problem);
53 opt = statset('nlinfit
');
56 opt.RobustWgtFun = 'fair
';
58 [GAMMA,RESIDUALS] = nlinfit(lag, rho, @geometric, 0.99, opt);
60 warning('Non linear regression
for ACF decay rate failed, trying lsqcurvefit
');
61 GAMMA = lsqcurvefit(@geometric, 0.99, lag, rho, -1, 1);
65 function rhok = geometric(gamma,k)
66 rhok = (RHO0 * gamma.^k)';