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 lGn=0;
50 return;
51end
52if nargin<4
53 order=ceil((sum(N)-1)/2);
54end
55if nargin<5
56 atol = 1e-8;
57end
58
59if nargin<3 || sum(Z)<atol %~exist('Z','var')
60 Nt=sum(N);
61 beta=N/Nt;
62 f=@(x) ([x(:);1-sum(x)]'*L);
63 h=@(x) beta.*log(f(x));
64 [~,Q,~]=simplexquad(@(x) prod(exp(Nt*h(x))),M-1,order,atol);
65 Gn=Q*exp(gammaln(1+sum(N)+M-1)-sum(gammaln(1+N)));
66 Gn=Gn(end);
67else
68 steps = 1e4;
69 Nt = sum(N);
70 beta = N/Nt;
71 Gn=0;
72 vmax=Nt*10;
73 dv=vmax/steps;
74 for v=0:dv:vmax
75 Lv=L*v+repmat(Z,M,1);
76 h = @(x) beta.*log(([x(:);1-sum(x)]'*Lv));
77 [~,Q] = simplexquad(@(x) exp(sum(Nt*h(x))),M-1,order,atol);
78 dG = exp(-v)*v^(M-1)*Q(end)*dv;
79 Gn = Gn + dG;
80 if v>0 && dG/Gn<atol
81 break
82 end
83 end
84 Gn = Gn * exp(-sum(factln(N)));
85end
86lGn = log(Gn);
87end
88
89function [I,Q,nv]=simplexquad(f,n,order,tol)
90% [I,Q,NV]=SIMPLEXQUAD(F,N,ORDER,TOL)
91
92[Q,nv]=grnmol(@(x)f(x),eye(n,n+1),order,tol);
93I=Q(end);
94end
95
96function [Q,nv] = grnmol( f, V, s, tol)
97% [Q,NV] = GRNMOL( F, V, S , TOL)
98
99%
100% Q = grnmol( f, V )
101% computes approximation to the integral of f over an s-simplex
102% with vertices as columns of V, an n x (n+1) matrix, using
103% order 1, 2, ..., s (degree 2s+1) Grundmann-Moler rules.
104% Output Q is a vector approximations of degree 1, 3, ... 2s+1.
105% Example: % final two results should be 2/(11x10x9x8x7x6)
106% n = 4; grnmol(@(x)x(1)^2*x(n)^5,eye(n,n+1),4)
107% Reference:
108% "Invariant Integration Formulas for the N-Simplex by
109% Combinatorial Methods", A. Grundmann and H. M. Moller,
110% SIAM J Numer. Anal. 15(1978), pp. 282-290
111%
112[n,~] = size(V); % n is the dimension
113d = 0; % order of the polynomial
114Q = (zeros(1,s+1));
115Qv = Q;
116Vol = 1/factorial((n));%abs(det(V(:,1:n)-V(:,np)*ones(1,n)))/prod(mp([1:n]));
117nv = 0;
118while 1
119 m = n + 2*d + 1;
120 al = (ones(n,1));
121 alz = 2*d + 1;
122 Qs = 0;
123 while 1
124 Qs = Qs + f(V*[alz; al]/m);
125 nv = nv + 1;
126 for j = 1 : n
127 alz = alz - 2;
128 if alz > 0
129 al(j) = al(j) + 2;
130 break
131 end
132 alz = alz + al(j) + 1;
133 al(j) = 1;
134 end
135 if alz == 2*d+1
136 break
137 end
138 end
139 d = d + 1;
140 Qv(d) = Vol*Qs;
141 Q(d) = (0);
142 p = 2/(prod(2*[n+1:m])); %#ok<NBRAK1>
143 for i = 1 : d
144 Q(d) = Q(d) + ((m+2-2*i))^(2*d-1)*p*Qv(d+1-i);
145 p = -p*(m+1-i)/i;
146 end
147 if d > s || (d>1 && abs(Q(d)-Q(d-1))<tol*Q(d-1))
148 Q((d+1):end)=[];
149 break,
150 end
151end
152end