1function pfqn_sens_linearizer_validate()
4 % @file pfqn_sens_linearizer_validate.m
5 % @brief Validation harness
for pfqn_sens_linearizer,
the LINEARIZER-2 /
6 % LINEARIZER-3 moment approximation of Strelen (1990), Section 5.
8 % This routine
is an APPROXIMATION, so it must not be held to machine
9 % precision. The checks are therefore of three kinds:
11 % A. accuracy bands against
the exact pfqn_sens_mom, on models small
12 % enough
for the exact lattice. The reference reports relative
13 % errors below 2.1% on E[Q], 4.1% on E[Q^2] and 6.2% on E[Q^3]
14 % over its own 51 networks;
the bands asserted here are of that
15 % order. This
is the only meaningful statement of correctness
for
16 % an approximation: it must track
the exact answer, not equal it.
17 % B. exactness where
the approximation degenerates. At a population of
18 % one job
the CORE estimate of
the queue lengths one job down
is
19 % identically zero whatever
the delta terms are, so
the Linearizer
20 % equations coincide with
the exact MVA and every moment must match
21 % pfqn_sens_mom to roundoff. This pins
the derivative algebra
22 % independently of
the heuristic.
23 % C. structural invariants that hold
for any population:
the mean
24 % queue lengths conserve
the population, and
the mean queue lengths
25 % agree with LINE
's own pfqn_linearizer, which runs the same
26 % heuristic without derivatives.
28 % Reference: J. C. Strelen, "Moment Analysis for Closed Queuing Networks
29 % and its Linearizer", Performance Evaluation 11:127-142, 1990.
33tolExact = 1e-9; % B: the one-job case must be exact
34tolPop = 1e-8; % C: population conservation
35tolLin = 5e-2; % C: agreement with LINE's pfqn_linearizer on
the means
36% A:
the bands are
the accuracy
the reference itself claims in Section 5 over
37% its 51 networks, so
this asserts that our port reproduces
the paper
's own
38% accuracy statement rather than some slacker figure. rng is fixed, so the model
39% set is deterministic and these are hard regression guards.
40bandM = 0.021; % r(Q) < 2.1% in the reference
41bandM2 = 0.041; % r(Q^2) < 4.1% in the reference
42bandM3 = 0.062; % r(Q^3) < 6.2% in the reference
43% The reference does not report an error on the variance. It is naturally larger
44% than the one on E[Q^2] because Var = E[Q^2] - E[Q]^2 is a difference of larger
45% numbers, so relative error is amplified; banded here only to catch regressions.
48errExact = 0; errPop = 0; errLin = 0;
49worstM = 0; worstM2 = 0; worstM3 = 0; worstVar = 0;
52% =====================================================================
53% A / C. random closed models against the exact moment analysis
54% =====================================================================
66 app = pfqn_sens_linearizer(L,N,Z);
67 ex = pfqn_sens_mom(L,N,Z);
69 worstM = max(worstM, relerr(app.m, ex.m));
70 worstM2 = max(worstM2, relerr(app.M2, ex.M2));
71 worstM3 = max(worstM3, relerr(app.M3, ex.M3));
72 worstVar = max(worstVar, relerr(app.Var, ex.Var));
75 % ---- C. population conservation --------------------------------
77 inNet = sum(app.Q(:,r));
78 inDelay = app.X(r) * Z(r);
79 errPop = max(errPop, abs(inNet + inDelay - N(r)) / max(1,N(r)));
82 % ---- C. means against LINE's own Linearizer --------------------
83 QL = pfqn_linearizer(L,N,Z,ones(M,1),1e-10,500);
84 errLin = max(errLin, relerr(sum(app.Q,2), sum(QL,2)));
87% =====================================================================
88% B. one job:
the Linearizer equations degenerate to
the exact MVA
89% =====================================================================
93 Z = (mod(trial,2)==0) * (0.4 + rand);
94 app = pfqn_sens_linearizer(L,1,Z);
95 ex = pfqn_sens_mom(L,1,Z);
96 errExact = max([errExact, relerr(app.m,ex.m), relerr(app.Var,ex.Var), ...
97 relerr(app.M2,ex.M2), relerr(app.M3,ex.M3), ...
98 relerr(app.Cov,ex.Cov)]);
101fprintf(
'\n=== pfqn_sens_linearizer validation ===\n');
102fprintf(
' A. accuracy vs exact pfqn_sens_mom (%d models), max relative error:\n', nA);
103fprintf(
' E[Q] : %6.3f%% (band %.1f%%)\n', 100*worstM, 100*bandM);
104fprintf(
' Var[Q] : %6.3f%% (band %.1f%%, not reported by the paper)\n', 100*worstVar, 100*bandVar);
105fprintf(
' E[Q^2] : %6.3f%% (band %.1f%%)\n', 100*worstM2, 100*bandM2);
106fprintf(
' E[Q^3] : %6.3f%% (band %.1f%%)\n', 100*worstM3, 100*bandM3);
107fprintf(
' B. one job, exact vs pfqn_sens_mom : %.3e (tol %.1e)\n', errExact, tolExact);
108fprintf(
' C. population conservation : %.3e (tol %.1e)\n', errPop, tolPop);
109fprintf(
' C. means vs pfqn_linearizer : %.3e (tol %.1e)\n', errLin, tolLin);
111ok = worstM <= bandM && worstM2 <= bandM2 && worstM3 <= bandM3 && ...
112 worstVar <= bandVar && errExact <= tolExact && errPop <= tolPop && ...
115 error(
'pfqn_sens_linearizer_validate:mismatch',
'one or more checks exceeded tolerance');
117fprintf(
' ALL CHECKS PASSED\n');
120% =========================================================================
121function e = relerr(a,b)
124scale = max(1, max(abs(a),abs(b)));