LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_cub.m
1%{
2%{
3 % @file pfqn_cub.m
4 % @brief Cubature method for normalizing constant using Grundmann-Moeller rules.
5%}
6%}
7
8%{
9%{
10 % @brief Cubature method for normalizing constant using Grundmann-Moeller rules.
11 % @fn pfqn_cub(L, N, Z, order, atol)
12 % @param L Service demand matrix (MxR).
13 % @param N Population vector (1xR).
14 % @param Z Think time vector (1xR).
15 % @param order Degree of cubature rule (default: ceil((sum(N)-1)/2)).
16 % @param atol Absolute tolerance (default: 1e-8).
17 % @return Gn Estimated normalizing constant.
18 % @return lGn Logarithm of normalizing constant.
19%}
20%}
21function [Gn,lGn]=pfqn_cub(L,N,Z,order,atol)
22% [GN,LGN]=PFQN_CUB(L,N,Z,ORDER,TOL)
23
24% PFQN_GM Exact and approximate solution of closed product-form queueing
25% networks by Grundmann-Moeller cubature rules
26%
27% [Gn,lGn]=pfqn_gm(L,N,Z,S)
28% Input:
29% L : MxR demand matrix. L(i,r) is the demand of class-r at queue i
30% N : 1xR population vector. N(r) is the number of jobs in class r
31% Z : 1xR think time vector. Z(r) is the total think time of class r
32% S : degree of the cubature rule. Exact if S=ceil((sum(N)-1)/2).
33% atol: max absolute distance from zero to declare that a variable is zero
34%
35% Output:
36% Gn : estimated normalizing constat
37% lGn: logarithm of Gn. If Gn exceeds the floating-point range, only lGn
38% will be correctly estimated.
39%
40% Reference:
41% G. Casale. Accelerating performance inference over closed systems by
42% asymptotic methods. ACM SIGMETRICS 2017.
43% Available at: http://dl.acm.org/citation.cfm?id=3084445
44
45[M,~]=size(L);
46
47if isempty(L) || isempty(N) || sum(N)==0
48 Gn=1;
49 return;
50end
51if nargin<4
52 order=ceil((sum(N)-1)/2);
53end
54if nargin<5
55 atol = 1e-8;
56end
57
58if nargin<3 || sum(Z)<atol %~exist('Z','var')
59 Nt=sum(N);
60 beta=N/Nt;
61 f=@(x) ([x(:);1-sum(x)]'*L);
62 h=@(x) beta.*log(f(x));
63 [~,Q,~]=simplexquad(@(x) prod(exp(Nt*h(x))),M-1,order,atol);
64 Gn=Q*exp(gammaln(1+sum(N)+M-1)-sum(gammaln(1+N)));
65 Gn=Gn(end);
66else
67 steps = 1e4;
68 Nt = sum(N);
69 beta = N/Nt;
70 Gn=0;
71 vmax=Nt*10;
72 dv=vmax/steps;
73 for v=0:dv:vmax
74 Lv=L*v+repmat(Z,M,1);
75 h = @(x) beta.*log(([x(:);1-sum(x)]'*Lv));
76 [~,Q] = simplexquad(@(x) exp(sum(Nt*h(x))),M-1,order,atol);
77 dG = exp(-v)*v^(M-1)*Q(end)*dv;
78 Gn = Gn + dG;
79 if v>0 && dG/Gn<atol
80 break
81 end
82 end
83 Gn = Gn * exp(-sum(factln(N)));
84end
85lGn = log(Gn);
86end
87
88function [I,Q,nv]=simplexquad(f,n,order,tol)
89% [I,Q,NV]=SIMPLEXQUAD(F,N,ORDER,TOL)
90
91[Q,nv]=grnmol(@(x)f(x),eye(n,n+1),order,tol);
92I=Q(end);
93end
94
95function [Q,nv] = grnmol( f, V, s, tol)
96% [Q,NV] = GRNMOL( F, V, S , TOL)
97
98%
99% Q = grnmol( f, V )
100% computes approximation to the integral of f over an s-simplex
101% with vertices as columns of V, an n x (n+1) matrix, using
102% order 1, 2, ..., s (degree 2s+1) Grundmann-Moler rules.
103% Output Q is a vector approximations of degree 1, 3, ... 2s+1.
104% Example: % final two results should be 2/(11x10x9x8x7x6)
105% n = 4; grnmol(@(x)x(1)^2*x(n)^5,eye(n,n+1),4)
106% Reference:
107% "Invariant Integration Formulas for the N-Simplex by
108% Combinatorial Methods", A. Grundmann and H. M. Moller,
109% SIAM J Numer. Anal. 15(1978), pp. 282-290
110%
111[n,~] = size(V); % n is the dimension
112d = 0; % order of the polynomial
113Q = (zeros(1,s+1));
114Qv = Q;
115Vol = 1/factorial((n));%abs(det(V(:,1:n)-V(:,np)*ones(1,n)))/prod(mp([1:n]));
116nv = 0;
117while 1
118 m = n + 2*d + 1;
119 al = (ones(n,1));
120 alz = 2*d + 1;
121 Qs = 0;
122 while 1
123 Qs = Qs + f(V*[alz; al]/m);
124 nv = nv + 1;
125 for j = 1 : n
126 alz = alz - 2;
127 if alz > 0
128 al(j) = al(j) + 2;
129 break
130 end
131 alz = alz + al(j) + 1;
132 al(j) = 1;
133 end
134 if alz == 2*d+1
135 break
136 end
137 end
138 d = d + 1;
139 Qv(d) = Vol*Qs;
140 Q(d) = (0);
141 p = 2/(prod(2*[n+1:m])); %#ok<NBRAK1>
142 for i = 1 : d
143 Q(d) = Q(d) + ((m+2-2*i))^(2*d-1)*p*Qv(d+1-i);
144 p = -p*(m+1-i)/i;
145 end
146 if d > s || (d>1 && abs(Q(d)-Q(d-1))<tol*Q(d-1))
147 Q((d+1):end)=[];
148 break,
149 end
150end
151end