2 % @brief Characteristic maximum M_K
for order statistics
4 % @author LINE Development Team
8 % @brief Characteristic maximum M_K
for order statistics
11 % Computes the characteristic maximum M_K, which provides a bound
for
12 % the expected value of the maximum of K i.i.d. random variables.
14 % Let m_K be the greatest lower bound such that
P(X > m_K) <= 1/K.
15 % For continuous distributions with a density:
P(X > m_K) = 1/K.
17 % The characteristic maximum
is:
18 % M_K = m_K + K * integral_{m_K}^{inf}
P(X > x) dx
20 % For specific distributions:
21 % - Exponential: m_K = ln(K)/μ, M_K = H_K/μ
22 % - Erlang-k: m_K solves exp(-μ*m_K) * sum_{i=0}^{k-1} (μ*m_K)^i/i! = 1/K
23 % M_K = (k/μ) * [1 + K*exp(-μ*m_K)*(μ*m_K)^k/k!]
27 % [MK, mK] = fj_char_max(K, mu) % Exponential
28 % [MK, mK] = fj_char_max(K, mu,
'exp') % Exponential (explicit)
29 % [MK, mK] = fj_char_max(K, [k, mu],
'erlang') % Erlang-k
30 % [MK, mK] = fj_char_max(K, S_X,
'general') % General (S_X
is survival function)
35 % <tr><th>Name<th>Description
36 % <tr><td>K<td>Number of random variables (positive integer)
37 % <tr><td>param<td>Distribution parameters (rate mu, or [k, mu] for Erlang)
38 % <tr><td>dist_type<td>Optional:
'exp' (default),
'erlang', or
'general'
43 % <tr><th>Name<th>Description
44 % <tr><td>MK<td>Characteristic maximum M_K
45 % <tr><td>mK<td>Threshold m_K where
P(X > m_K) = 1/K
49 % A. Thomasian,
"Analysis of Fork/Join and Related Queueing Systems",
50 % ACM Computing Surveys, Vol. 47, No. 2, Article 17, July 2014.
51 % Eq. (47) on page 17:24.
53 % A. Gravey,
"A Simple Construction of an Upper Bound for the Mean of
54 % the Maximum of n Identically Distributed Random Variables", 1985.
56function [MK, mK] = fj_char_max(K, param, dist_type)
63 line_error(mfilename,
'K must be a positive integer. Got K=%d.', K);
66switch lower(dist_type)
68 % Exponential distribution with rate mu
71 line_error(mfilename,
'Rate mu must be positive.');
75 % M_K = H_K / mu (exact
for exponential)
76 MK = fj_harmonic(K) / mu;
79 % Erlang-k distribution
81 line_error(mfilename,
'For Erlang, param must be [k, mu].');
87 line_error(mfilename,
'Erlang stages k must be positive.');
90 line_error(mfilename,
'Rate mu must be positive.');
93 % Find m_K by solving: exp(-mu*m_K) * sum_{i=0}^{k-1} (mu*m_K)^i/i! = 1/K
94 mK = find_mK_erlang(K, k, mu);
96 % M_K = (k/mu) * [1 + K * exp(-mu*m_K) * (mu*m_K)^k / k!]
97 MK = (k / mu) * (1 + K * exp(-mu * mK) * (mu * mK)^k / factorial(k));
100 % General distribution: param
is survival function S_X(x) =
P(X > x)
102 if ~isa(S_X,
'function_handle')
103 line_error(mfilename, 'For general distribution, param must be a survival function handle.');
106 % Find m_K such that S_X(m_K) = 1/K
107 mK = find_mK_general(K, S_X);
109 % M_K = m_K + K * integral_{m_K}^{inf} S_X(x) dx
110 integrand = @(x) S_X(x);
111 upper_limit = find_upper_limit(S_X, 1e-10);
112 tail_integral = integral(integrand, mK, upper_limit,
'RelTol', 1e-8,
'AbsTol', 1e-10);
113 MK = mK + K * tail_integral;
116 line_error(mfilename,
'Unknown distribution type: %s. Valid: exp, erlang, general.', dist_type);
121function mK = find_mK_erlang(K, k, mu)
122% Find m_K
for Erlang-k by solving:
123% exp(-mu*m_K) * sum_{i=0}^{k-1} (mu*m_K)^i/i! = 1/K
125% Erlang survival function
126S_erlang = @(x) erlang_survival(x, k, mu);
128% Use fzero to find the root
129objective = @(x) S_erlang(x) - 1/K;
131% Initial guess:
for large K, m_K
is approximately the mean plus adjustment
132initial_guess = k / mu + log(K) / mu;
134options = optimset(
'TolX', 1e-10,
'Display',
'off');
135mK = fzero(objective, initial_guess, options);
138function S = erlang_survival(x, k, mu)
139% Erlang-k survival function:
P(X > x) = exp(-mu*x) * sum_{i=0}^{k-1} (mu*x)^i/i!
145 S = S + (mu * x)^i / factorial(i);
147 S = exp(-mu * x) * S;
151function mK = find_mK_general(K, S_X)
152% Find m_K such that S_X(m_K) = 1/K
153objective = @(x) S_X(x) - 1/K;
158while S_X(upper) > 1/K
162options = optimset(
'TolX', 1e-10,
'Display',
'off');
163mK = fzero(objective, [lower, upper], options);
166function u = find_upper_limit(S_X, target)
167% Find u such that S_X(u) <= target