4 % @brief Logistic sampling approximation
for normalizing constant.
10 % @brief Logistic sampling approximation
for normalizing constant.
11 % @fn pfqn_ls(L, N, Z, I)
12 % @param L Service demand matrix (MxR).
13 % @param N Population vector (1xR).
14 % @param Z Think time vector (1xR).
15 % @param I Number of samples (
default: 1e5).
16 % @return Gn Estimated normalizing constant.
17 % @return lGn Logarithm of normalizing constant.
20function [Gn,lGn]=pfqn_ls(L,N,Z,I)
21% [GN,LGN]=PFQN_LS(L,N,Z,I)
23% PFQN_MCI Approximate solution of closed product-form queueing networks
26% [Gn,lGn]=pfqn_ls(L,N,Z,I)
28% L : MxR demand matrix. L(i,r)
is the demand of class-r at queue i
29% N : 1xR population vector. N(r)
is the number of jobs in class r
30% Z : 1xR think time vector. Z(r)
is the total think time of class r
31% I : number of samples (default: 1e5)
34% Gn : estimated normalizing constat
37% G. Casale. Accelerating performance inference over closed systems by
38% asymptotic methods. ACM SIGMETRICS 2017.
46if isempty(L) || sum(L(:))<1e-4 || isempty(N) || sum(N)==0
47 lGn = - sum(factln(N)) + sum(N.*log(sum(Z,1)));
48elseif nargin<3 || isempty(Z) %~exist(
'Z',
'var') || isempty(Z)
49 umax=pfqn_le_fpi(L,N);
50 A = pfqn_le_hessian(L,N,umax
'); % slightly faster than pfqn_le_hessianZ
51 A = (A+A')/2; % let
's get rid of small numerical perturbations
53 x0 = log(umax(1:M-1)/umax(M))'; % move to R^{K-1}
55 samples = mvnrnd(x0,iA,I);
58 h = @(x) simplex_fun(x,L,N);
60 T(i) = h(samples(i,:));
64 dpdf(i)=mvnpdf(samples(i,:)
',x0,iA);
66 lGn = multinomialln([N,M-1]) + factln(M-1) + log(mean(T(:)./dpdf(:)));
69 [umax,vmax]=pfqn_le_fpiZ(L,N,Z);
70 A = pfqn_le_hessianZ(L,N,Z,umax',vmax);
71 A = (A+A
')/2; % let's get rid of small numerical perturbations
73 x0 = [log(umax(1:M-1)/umax(M))
',log(vmax)]; % move to R^{K}
75 samples = mvnrnd(x0,iA,I);
80 eta = sum(N)+M*(1+eN);
82 h = @(x)exp(-exp(x(K))+K*(1+eN)*x(M)+sum(N*log( (L(K,:)*exp(x(K))+Z) + exp(x(1:K-1))*(L(1:K-1,:)*exp(x(K))+repmat(Z,K-1,1)))') +sum(x(1:K-1)) -eta*log(1+sum(exp(x(1:K-1)))));
84 T(i) = h(samples(i,:));
86 dpdf = mvnpdf(samples,x0,iA)
';
87 Gn = exp(-sum(gammaln(1+N))) * mean(T./dpdf(:));
93function [u,d]=pfqn_le_fpi(L,N)
94% [U,D]=PFQN_LE_FPI(L,N)
96% find location of mode of gaussian
101while norm(u-u_1,1)>1e-10
106 u(i)=u(i)+N(r)/(sum(N)+M)*L(i,r)*u_1(i)/(u_1'*L(:,r));
109 d(end+1,:)=abs(u-u_1)
';
113function [u,v,d]=pfqn_le_fpiZ(L,N,Z)
114% [U,V,D]=PFQN_LE_FPIZ(L,N,Z)
116% find location of mode of gaussian
122v_1=Inf*v; %#ok<NASGU>
124while norm(u-u_1,1)>1e-10
130 u(ist)=u(ist)+(N(r)/eta)*(Z(r)+v*L(ist,r))*u_1(ist)/(Z(r)+v*u_1'*L(:,r));
134 xi(r)=N(r)/(Z(r)+v*u_1(:)
'*L(:,r));
140 d(end+1,:)=abs(u-u_1)'+abs(v-v_1);
145function hu=pfqn_le_hessian(L,N,u0)
146% HU=PFQN_LE_HESSIAN(L,N,U0)
148% find hessian of gaussian
155 hu(i,j)=-(Ntot+M)*u0(i)*u0(j);
157 hu(i,j)=hu(i,j)+N(r)*L(i,r)*L(j,r)*(u0(i)*u0(j))/(u0*L(:,r))^2;
160 hu(i,j)=(Ntot+M)*u0(i)*sum(allbut(u0,i));
162 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;
169function A=pfqn_le_hessianZ(L,N,Z,u,v)
170% A=PFQN_LE_HESSIANZ(L,N,Z,U,V)
172% find hessian of gaussian
178 csi(r)=N(r)/(Z(r)+v*u*L(:,r));
183 Lhat(k,r)=Z(r)+v*L(k,r);
190 A(i,j)=-eta*u(i)*u(j);
192 A(i,j)=A(i,j)+csi(r)^2*Lhat(i,r)*Lhat(j,r)*(u(i)*u(j))/N(r);
198 A(i,i)=-sum(allbut(A(i,:),i));
203 A(K,K)=A(K,K)-(csi(r)^2/N(r))*Z(r)*u*L(:,r);
209 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));
215function y=allbut(y,xset)
218y=y(setdiff(1:length(y),xset));
221function mln=multinomialln(n)
222% MLN=MULTINOMIALLN(N)
224mln = factln(sum(n))- sum(factln(n));
233function f=simplex_fun(x,L,N)
234% F=SIMPLEX_FUN(X,L,N)
244f=exp(sum(N*log(v(:)'*L)
')+sum(x)-(sum(N)+M)*log(sum(v)));