2 % @brief Monte Carlo importance-sampling summation
for loss networks
4 % @author LINE Development Team
8 % @brief Estimates
the product-form normalization constant and
class
9 % blocking probabilities of a loss network by Monte Carlo summation.
12 % Implements
the importance-sampling Monte Carlo summation method of
13 % Ross and Wang,
"Monte Carlo Summation Applied to Product-Form Loss
14 % Networks", Probability in
the Engineering and Informational Sciences,
17 % A loss network has links j=1..J with capacity C(j) and classes (routes)
18 % r=1..R with offered load nu(r) and per-link circuit requirement A(j,r).
19 % The state n=(n_1,..,n_R)
is feasible iff A*n <= C (set Omega). The
20 % equilibrium distribution
is product form with normalization constant
21 % g(C) = sum_{n in Omega} prod_r nu(r)^n_r / n_r! .
22 % The
class-r acceptance probability
is 1-beta_r = g(C-A(:,r))/g(C).
24 % States are sampled from
the importance distribution (Eq. 6)
25 % p(n) = (1/c) prod_r gamma_r^n_r / n_r!, n in {0..N_1}x..x{0..N_R},
26 % with N_r = min_j floor(C_j/A_jr) over A_jr>0. Ratio estimators (Eq. 8)
27 % give unbiased/consistent g and consistent blocking with delta-method
28 % confidence intervals.
32 % [QLen, Loss, lG, ci, nsamples] = lossn_mci(nu, A, C)
33 % [QLen, Loss, lG, ci, nsamples] = lossn_mci(nu, A, C, options)
38 % <tr><th>Name<th>Description
39 % <tr><td>nu<td>Offered load of route (class) r (1xR vector)
40 % <tr><td>A<td>Circuit requirement of link j for route r (JxR matrix)
41 % <tr><td>C<td>Available capacity of link j (Jx1 vector)
42 % <tr><td>options<td>struct with optional fields: samples (default 1e5),
43 % gamma (1xR importance params, default Sec. 3.4
44 % heuristic), seed (rng seed), alpha (CI level,
50 % <tr><th>Name<th>Description
51 % <tr><td>QLen<td>Mean carried load (E[n_r]) for route r (1xR)
52 % <tr><td>Loss<td>Blocking probability beta_r for route r (1xR)
53 % <tr><td>lG<td>Log of
the estimated normalization constant g(C)
54 % <tr><td>ci<td>struct with confidence intervals and point estimates:
55 % .accept (Rx2), .loss (Rx2), .acceptPoint (1xR),
56 % .lossPoint (1xR), .level (1-alpha)
57 % <tr><td>nsamples<td>Number of Monte Carlo samples used
60function [QLen, Loss, lG, ci, nsamples] = lossn_mci(nu, A, C, options)
61if nargin < 4 || isempty(options)
68if size(A,1) ~= J || size(A,2) ~= R
69 line_error(mfilename, sprintf('A must be %dx%d (J x R).
', J, R));
72nsamples = getfielddef(options, 'samples
', 1e5);
73alpha = getfielddef(options, 'alpha
', 0.05);
74seed = getfielddef(options, 'seed
', []);
75gamma = getfielddef(options, 'gamma
', []);
81% Per-class maximum feasible occupancy N_r = min_j floor(C_j/A_jr)
86 N(k) = floor(min(C(pos) ./ A(pos, k)));
88 N(k) = 0; % class uses no link: cannot admit connections
92% Importance-sampling parameters gamma (Section 3.4 heuristic)
96 load_j(j) = sum(A(j,:) .* nu) / C(j);
99 b = max(A, [], 1); % 1xR, b_k = max_j A_jk
100 base = 1 - 0.15 * (1 - delta);
101 base = max(base, 1e-6);
102 gamma = nu .* (base .^ b);
105gamma = max(gamma, 1e-300);
107% Normalization constant c of
the importance distribution (log space)
111 logterms = l * log(gamma(k)) - gammaln(l + 1);
112 log_c = log_c + logsumexp(logterms);
115% Draw S i.i.d. samples V (S x R), each
column truncated Poisson(gamma_k)
119 logpmf = l * log(gamma(k)) - gammaln(l + 1);
120 pmf = exp(logpmf - logsumexp(logpmf));
122 cdf(end) = 1; % guard rounding
124 idx = sum(u > cdf(:)
', 2); % # of thresholds exceeded = value
128% Feasibility indicators
129AV = V * A'; % S x J, row s = A*n_s
130inOmega = all(AV <= C(:)
', 2); % S x 1
131inOmegaK = false(S, R);
133 Ck = (C - A(:,k))'; % 1 x J capacity
for Omega(C-A_.k)
134 inOmegaK(:, k) = all(AV <= Ck, 2);
137% Likelihood ratio alpha^i = prod_k (nu_k/gamma_k)^V_k (log space)
138logratio = log(nu) - log(gamma); % 1xR
139log_alpha = V * logratio'; % S x 1
141% Normalization constant estimate g(C) = (c/S) sum alpha 1(Omega)
142laO = log_alpha(inOmega);
147 lG = log_c + m + log(sum(exp(laO - m))) - log(S);
150% Ratio estimators for acceptance (Eq. 8) with shifted weights for stability
152 M = max(log_alpha(inOmega));
156w = exp(log_alpha - M); % S x 1 scaled likelihood ratios
157Z = w .* inOmega; % denominator summand
160crit = sqrt(2) * erfinv(1 - alpha); % standard-normal 1-alpha/2 quantile
162acceptCI = zeros(R, 2);
164 Y = w .* inOmegaK(:, k);
167 phi = NaN; half = NaN;
172 covYZ = sum((Y - meanY) .* (Z - meanZ)) / (S - 1);
173 sig2 = (varY - 2*phi*covYZ + phi^2*varZ) / (S * meanZ^2);
175 half = crit * sqrt(sig2);
178 acceptCI(k, :) = [phi - half, phi + half];
186ci.loss = [1 - acceptCI(:,2), 1 - acceptCI(:,1)];
187ci.acceptPoint = accept;
192function s = logsumexp(x)
198 s = m + log(sum(exp(x - m)));
202function v = getfielddef(s, f, d)
203if isfield(s, f) && ~isempty(s.(f))