1function MAP=map_anfit(ls,rho,H,n,ds,SA,SAlags, iter_max, iter_tol)
2% MAP_ANFIT - Andersen and Nielsen MAP Fitting Algorithm
3% From A.T.Andersen and B.F.Nielsen,
"A Markovian Approach for Modeling Packet Traffic with Long-Range Dependence", IEEE JSAC 16(5), 1998.
4% ls - mean arrival rate
5% rho - lag-1 autocorrelation of the counting process
6% H - Hurst coefficient (counting process)
7% n - number of time scales to be modeled
8% ds - number of IPP to be used
9% SA - set of autocorrelation coefficients of interarrival times
10% SAlags - lags used in SA
13% lstar=1; rho=0.8; H=0.92; n=5; ds=4; SA=[0.3,0.28]; SAlags=[1,2];
14% MAP=map_anfit(lstar,rho,H,n,ds,SA,SAlags);
17if nargin>5 %
if SA and SAlags are given in input, then perform least square fit of SA
36 d0=0; phi(d)=1; i=1; a=10^(n/(d-1));
40 S=S+phi(d-j)^2*exp(1-a^(i-j));
72 k(2,i)=a^(1-i)*k(2,1);
74if ~(k(2,1)<1 && rho<0.5)
75 fprintf(
'warning: if necessary adjust k(2,1) and/or rho\n')
81 S=S+phi(i)^2*kappa^(-2)*((1-e)^2-2*rho*(kappa-(1-e)));
83eta=sqrt(4*rho*ls)/sqrt(S);
88 c(1,i)=L^2/(ls^2+L^2)*k(2,i);
90 l(i)=phi(i)*(ls^2+L^2)/(ls*sum(phi(1:d)));
103 %% No Least Square Fit, compose and
return
104 MAP=map_exponential(lP);
106 D0=[0,c(1,i);c(2,i),0];
108 IPP=map_normalize({D0,D1});
109 MAP=map_super(MAP,IPP);
111 MAP=map_normalize(MAP);
117 k(1,i)=(l(i)-0)^2*(c(1,i)*c(2,i))/(c(1,i)+c(2,i))^3;
118 ls(i)=(c(2,i)*l(i))/(c(1,i)+c(2,i));
123 r0(end+1)=1+k(1,i)*k(2,i)/ls(i)^2;
125 [f,r]=minimize(@objfun,@nnlcon,r0, iter_max, iter_tol);
126 MAP=MAP0; %
return the last MAP found in the lsq algorithm
128 function [c,ceq]=nnlcon(r)
132 c(end+1)=-(ls(i)-sqrt(k(1,i)*k(2,i)/r(i)));
138 D0=[0,k(2,i)*r(i)/(1+r(i));k(2,i)/(1+r(i)),0];
139 D1=[ls(i)+sqrt(k(1,i)*k(2,i)*r(i)),0;0,ls(i)-sqrt(k(1,i)*k(2,i)/r(i))];
140 IPP=map_normalize({D0,D1});
141 MAP0=map_super(MAP0,IPP);
143 f=norm(map_acf(MAP0,SAlags)-SA
',2);
149%% MINIMIZE encapsulates MATLAB's nonlinear optimization solver
150% objfun - objective function
151% nnlcon - nonlinear constraints
152% x0 - initial solution
153% MAXITER - maximum number of iterations
154% TOL - constraint feasibility tolerance
155function [f,x]=minimize(objfun,nnlcon,x0,MAXITER,TOL)
157options = optimset(
'LargeScale',
'off',
'MaxIter',MAXITER,
'MaxFunEvals',1e10,
'MaxSQPIter',500,
'TolCon',TOL,
'Display',
'off');
160[x,f]=fmincon(objfun,x0,[],[],[],[],xlb,[],nnlcon,options);
163%% MAP_NORMALIZE normalizes the diagonal element of D0 and prevents the solver to step into complex numbers
164% MAP - 2x1 cell, element 1
is the matrix D0, element 2
is D1
165function [MAP]=map_normalize(MAP)
166nStates=size(MAP{1},1);
172 MAP{1}(n,n)=MAP{1}(n,n)-sum(MAP{b}(n,:));
177 MAP{1}(i,j)=real(MAP{1}(i,j));
178 MAP{2}(i,j)=real(MAP{2}(i,j));
183%% MAP_SUPER creates the superposed process MAPa \oplus MAPb
184%% (oplus=Kronecker sum)
185% MAPa - 2x1 cell, element 1
is the matrix D0, element 2
is D1
186% MAPb - 2x1 cell, element 1
is the matrix D0, element 2
is D1
187function MAP=map_super(MAPa,MAPb)
188D0s=krons(MAPa{1},MAPb{1});
189D1s=krons(MAPa{2},MAPb{2});
191MAP=map_normalize(MAP);
194%% KRONS - Kronecker sum
195function AB=krons(A,B)
196AB=kron(A,eye(size(B)))+kron(eye(size(A)),B);
199%% MAP_PROB - MAP equilibrium probabilities from D0 and D1
200function p=map_prob(MAP)
205%% CTMC_SOLVE solve Markov process by global balance
206function p=ctmc_solve(Q)
207% Q - infinitesimal generator of the process
208% p - steady state probabilities
209zerocol=find(sum(abs(Q))==0);
211 warning(
'two cols of Q are composed by zeros only.');
212 b=zeros(size(Q,1),1);
213elseif length(zerocol)==0
216b=zeros(size(Q,1),1); b(zerocol)=1;
217Q(:,zerocol)=1; % add normalization condition
218p=(Q
')\b; % compute steady state probability vector
219p=p'; % p
is a row vector
222%% MAP_ACF autocorrelation coefficents of inter-arrival times
223% MAP - 2x1 cell, element 1
is the matrix D0, element 2
is D1
224% lagset - set of lag coefficients
225function acfun=map_acf(MAP,lagset)
226p=map_prob(MAP); %steady state probabilities
227lambda=p*MAP{2}*ones(size(MAP{2},2),1); % arrival rate
228e=ones(size(MAP{1},1),1);
233 acfun(end+1)=lambda*p*(
P^lag)*invD0*e;
235acfun=(acfun-1)./map_scv(MAP);