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=[];
76coder.varsize('d');
77while norm(u-u_1,1)>1e-10
78 u_1=u;
79 for i=1:M
80 u(i)=1/(sum(N)+M);
81 for r=1:R
82 u(i)=u(i)+N(r)/(sum(N)+M)*L(i,r)*u_1(i)/(u_1'*L(:,r));
83 end
84 end
85 d=[d; abs(u-u_1)']; %#ok<AGROW>
86end
87end
88
89function [u,v,d]=pfqn_le_fpiZ(L,N,Z)
90% [U,V,D]=PFQN_LE_FPIZ(L,N,Z)
91
92% find location of mode of gaussian
93[M,R]=size(L);
94eta = sum(N)+M;
95u=ones(M,1)/M;
96v=eta+1;
97u_1=Inf*u;
98v_1=Inf*v; %#ok<NASGU>
99d=[];
100coder.varsize('d');
101while norm(u-u_1,1)>1e-10
102 u_1=u;
103 v_1=v;
104 for ist=1:M
105 u(ist)=1/eta;
106 for r=1:R
107 u(ist)=u(ist)+(N(r)/eta)*(Z(r)+v*L(ist,r))*u_1(ist)/(Z(r)+v*u_1'*L(:,r));
108 end
109 end
110 xi = zeros(1, R);
111 for r=1:R
112 xi(r)=N(r)/(Z(r)+v*u_1(:)'*L(:,r));
113 end
114 v=eta+1;
115 for r=1:R
116 v=v-xi(r)*Z(r);
117 end
118 d=[d; abs(u-u_1)'+abs(v-v_1)]; %#ok<AGROW>
119end
120
121end
122
123function hu=pfqn_le_hessian(L,N,u0)
124% HU=PFQN_LE_HESSIAN(L,N,U0)
125
126% find hessian of gaussian
127[M,R]=size(L);
128Ntot=sum(N);
129hu=zeros(M-1);
130for i=1:(M-1)
131 for j=1:(M-1)
132 if i~=j
133 hu(i,j)=-(Ntot+M)*u0(i)*u0(j);
134 for r=1:R
135 hu(i,j)=hu(i,j)+N(r)*L(i,r)*L(j,r)*(u0(i)*u0(j))/(u0*L(:,r))^2;
136 end
137 else % i=j
138 hu(i,j)=(Ntot+M)*u0(i)*sum(allbut(u0,i));
139 for r=1:R
140 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;
141 end
142 end
143 end
144end
145end
146
147function A=pfqn_le_hessianZ(L,N,Z,u,v)
148% A=PFQN_LE_HESSIANZ(L,N,Z,U,V)
149
150% find hessian of gaussian
151[K,R]=size(L);
152Ntot=sum(N);
153A=zeros(K);
154csi = zeros(1,R);
155for r=1:R
156 csi(r)=N(r)/(Z(r)+v*u*L(:,r));
157end
158Lhat = zeros(K,R);
159for k=1:K
160 for r=1:R
161 Lhat(k,r)=Z(r)+v*L(k,r);
162 end
163end
164eta=Ntot+K;
165for i=1:K
166 for j=1:K
167 if i~=j
168 A(i,j)=-eta*u(i)*u(j);
169 for r=1:R
170 A(i,j)=A(i,j)+csi(r)^2*Lhat(i,r)*Lhat(j,r)*(u(i)*u(j))/N(r);
171 end
172 end
173 end
174end
175for i=1:K
176 A(i,i)=-sum(allbut(A(i,:),i));
177end
178A=A(1:(K-1),1:(K-1));
179A(K,K)=1;
180for r=1:R
181 A(K,K)=A(K,K)-(csi(r)^2/N(r))*Z(r)*u*L(:,r);
182end
183A(K,K)=v*A(K,K);
184for i=1:(K-1)
185 A(i,K)=0;
186 for r=1:R
187 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));
188 end
189 A(K,i)=A(i,K);
190end
191end
192
193function y=allbut(y,xset)
194% Y=ALLBUT(Y,XSET)
195
196y=y(setdiff(1:length(y),xset));
197end
198
199function mln=multinomialln(n)
200% MLN=MULTINOMIALLN(N)
201
202mln = factln(sum(n))- sum(factln(n));
203end
204
205function lf=factln(n)
206% LF=FACTLN(N)
207
208lf = gammaln(1+n);
209end