LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_le.m
1%{
2%{
3 % @file pfqn_le.m
4 % @brief Logistic expansion (LE) asymptotic approximation for normalizing constant.
5%}
6%}
7
8%{
9%{
10 % @brief Logistic expansion (LE) asymptotic approximation for normalizing constant.
11 % @fn pfqn_le(L, N, Z)
12 % @param L Service demand matrix (MxR).
13 % @param N Population vector (1xR).
14 % @param Z Think time vector (1xR).
15 % @return Gn Estimated normalizing constant.
16 % @return lGn Logarithm of normalizing constant.
17%}
18%}
19function [Gn,lGn]=pfqn_le(L,N,Z)
20% [GN,LGN]=PFQN_LE(L,N,Z)
21
22% PFQN_LE Asymptotic solution of closed product-form queueing networks by
23% logistic expansion
24%
25% [Gn,lGn]=pfqn_le(L,N,Z)
26% Input:
27% L : MxR demand matrix. L(i,r) is the demand of class-r at queue i
28% N : 1xR population vector. N(r) is the number of jobs in class r
29% Z : 1xR think time vector. Z(r) is the total think time of class r
30%
31% Output:
32% Gn : estimated normalizing constat
33% lGn: logarithm of Gn. If Gn exceeds the floating-point range, only lGn
34% will be correctly estimated.
35%
36% Reference:
37% G. Casale. Accelerating performance inference over closed systems by
38% asymptotic methods. ACM SIGMETRICS 2017.
39% Availble at: http://dl.acm.org/citation.cfm?id=3084445
40
41
42[M,R]=size(L);
43
44if isempty(L) || isempty(N) || sum(N)==0 || sum(L(:))<1e-4
45 lGn = - sum(factln(N)) + sum(N.*log(sum(Z,1)));
46 Gn=exp(lGn);
47elseif nargin<3%~exist('Z','var')
48 umax=pfqn_le_fpi(L,N);
49 A=pfqn_le_hessian(L,N,umax'); % slightly faster than pfqn_le_hessianZ
50 S=0;
51 for r=1:R
52 S=S+N(r)*log(umax'*L(:,r));
53 end
54 lGn = multinomialln([N,M-1]) + factln(M-1) + (M-1)*log(sqrt(2*pi)) - log(sqrt(det(A))) + sum(log(umax)) + S;
55 Gn=exp(lGn);
56else % Z>0
57 [umax,vmax]=pfqn_le_fpiZ(L,N,Z);
58 A=pfqn_le_hessianZ(L,N,Z,umax',vmax);
59 S=0;
60 for r=1:R
61 S=S+N(r)*log(Z(r)+vmax*umax'*L(:,r));
62 end
63 lGn = -sum(factln(N)) -vmax + M*log(vmax) + M*log(sqrt(2*pi)) - log(sqrt(det(A))) + sum(log(umax)) + S;
64 Gn=exp(lGn);
65end
66end
67
68function [u,d]=pfqn_le_fpi(L,N)
69% [U,D]=PFQN_LE_FPI(L,N)
70
71% find location of mode of gaussian
72[M,R]=size(L);
73u=ones(M,1)/M;
74u_1=Inf*u;
75d=[];
76while norm(u-u_1,1)>1e-10
77 u_1=u;
78 for i=1:M
79 u(i)=1/(sum(N)+M);
80 for r=1:R
81 u(i)=u(i)+N(r)/(sum(N)+M)*L(i,r)*u_1(i)/(u_1'*L(:,r));
82 end
83 end
84 d(end+1,:)=abs(u-u_1)';
85end
86end
87
88function [u,v,d]=pfqn_le_fpiZ(L,N,Z)
89% [U,V,D]=PFQN_LE_FPIZ(L,N,Z)
90
91% find location of mode of gaussian
92[M,R]=size(L);
93eta = sum(N)+M;
94u=ones(M,1)/M;
95v=eta+1;
96u_1=Inf*u;
97v_1=Inf*v; %#ok<NASGU>
98d=[];
99while norm(u-u_1,1)>1e-10
100 u_1=u;
101 v_1=v;
102 for ist=1:M
103 u(ist)=1/eta;
104 for r=1:R
105 u(ist)=u(ist)+(N(r)/eta)*(Z(r)+v*L(ist,r))*u_1(ist)/(Z(r)+v*u_1'*L(:,r));
106 end
107 end
108 for r=1:R
109 xi(r)=N(r)/(Z(r)+v*u_1(:)'*L(:,r));
110 end
111 v=eta+1;
112 for r=1:R
113 v=v-xi(r)*Z(r);
114 end
115 d(end+1,:)=abs(u-u_1)'+abs(v-v_1);
116end
117
118end
119
120function hu=pfqn_le_hessian(L,N,u0)
121% HU=PFQN_LE_HESSIAN(L,N,U0)
122
123% find hessian of gaussian
124[M,R]=size(L);
125Ntot=sum(N);
126hu=zeros(M-1);
127for i=1:(M-1)
128 for j=1:(M-1)
129 if i~=j
130 hu(i,j)=-(Ntot+M)*u0(i)*u0(j);
131 for r=1:R
132 hu(i,j)=hu(i,j)+N(r)*L(i,r)*L(j,r)*(u0(i)*u0(j))/(u0*L(:,r))^2;
133 end
134 else % i=j
135 hu(i,j)=(Ntot+M)*u0(i)*sum(allbut(u0,i));
136 for r=1:R
137 hu(i,j)=hu(i,j)-N(r)*L(i,r)*u0(i)*(allbut(u0,i)*L(allbut(1:M,i),r))/(u0*L(:,r))^2;
138 end
139 end
140 end
141end
142end
143
144function A=pfqn_le_hessianZ(L,N,Z,u,v)
145% A=PFQN_LE_HESSIANZ(L,N,Z,U,V)
146
147% find hessian of gaussian
148[K,R]=size(L);
149Ntot=sum(N);
150A=zeros(K);
151csi = zeros(1,R);
152for r=1:R
153 csi(r)=N(r)/(Z(r)+v*u*L(:,r));
154end
155Lhat = zeros(K,R);
156for k=1:K
157 for r=1:R
158 Lhat(k,r)=Z(r)+v*L(k,r);
159 end
160end
161eta=Ntot+K;
162for i=1:K
163 for j=1:K
164 if i~=j
165 A(i,j)=-eta*u(i)*u(j);
166 for r=1:R
167 A(i,j)=A(i,j)+csi(r)^2*Lhat(i,r)*Lhat(j,r)*(u(i)*u(j))/N(r);
168 end
169 end
170 end
171end
172for i=1:K
173 A(i,i)=-sum(allbut(A(i,:),i));
174end
175A=A(1:(K-1),1:(K-1));
176A(K,K)=1;
177for r=1:R
178 A(K,K)=A(K,K)-(csi(r)^2/N(r))*Z(r)*u*L(:,r);
179end
180A(K,K)=v*A(K,K);
181for i=1:(K-1)
182 A(i,K)=0;
183 for r=1:R
184 A(i,K)=A(i,K)+v*u(i)*((csi(r)^2/N(r))*Lhat(i,r)*(u*L(:,r))-csi(r)*L(i,r));
185 end
186 A(K,i)=A(i,K);
187end
188end
189
190function y=allbut(y,xset)
191% Y=ALLBUT(Y,XSET)
192
193y=y(setdiff(1:length(y),xset));
194end
195
196function mln=multinomialln(n)
197% MLN=MULTINOMIALLN(N)
198
199mln = factln(sum(n))- sum(factln(n));
200end
201
202function lf=factln(n)
203% LF=FACTLN(N)
204
205lf = gammaln(1+n);
206end