1%{ @file fj_order_stat.m
2 % @brief CDF and expected value of k-th order statistic
4 % @author LINE Development Team
8 % @brief CDF and expected value of k-th order statistic
11 % Computes the CDF and expected value of the k-th order statistic
12 % (k-th smallest) of K i.i.d. random variables.
15 % F_{Y_K}(y) = [F_X(y)]^K
17 % For k-th order statistic (k-th smallest):
18 % F_{Y_k}(y) = sum_{j=k}^{K} C(K,j) * F_X(y)^j * (1-F_X(y))^{K-j}
20 % Expected value of maximum:
21 % E[Y_K] = integral_0^inf [1 - F_X(y)^K] dy
25 % F_Yk = fj_order_stat(y, k, K, F_X)
26 % [F_Yk, E_Yk] = fj_order_stat(y, k, K, F_X)
31 % <tr><th>Name<th>Description
32 % <tr><td>y<td>Value(s) at which to evaluate CDF
33 % <tr><td>k<td>Order of the statistic (1 = minimum, K = maximum)
34 % <tr><td>K<td>Total number of random variables
35 % <tr><td>F_X<td>CDF function handle: F_X(y) returns CDF value
40 % <tr><th>Name<th>Description
41 % <tr><td>F_Yk<td>CDF of k-th order statistic at y
42 % <tr><td>E_Yk<td>Expected value of k-th order statistic (if requested)
46 % A. Thomasian, "Analysis of Fork/Join and Related Queueing Systems",
47 % ACM Computing Surveys, Vol. 47, No. 2, Article 17, July 2014.
48 % Eq. (18) and (19) on page 17:15.
50function [F_Yk, E_Yk] = fj_order_stat(y, k, K, F_X)
53 line_error(mfilename, 'k must satisfy 1 <= k <= K. Got k=%d, K=%d.', k, K);
56% Evaluate the base CDF at y
60 % Maximum (K-th order statistic): F_{Y_K}(y) = [F_X(y)]^K
63 % General k-th order statistic:
64 % F_{Y_k}(y) = sum_{j=k}^{K} C(K,j) * F_X(y)^j * (1-F_X(y))^{K-j}
65 F_Yk = zeros(size(y));
67 F_Yk = F_Yk + nchoosek(K, j) .* (F_y.^j) .* ((1 - F_y).^(K - j));
71% Compute expected value
if requested
74 % Expected value of maximum: E[Y_K] = integral_0^inf [1 - F_X(y)^K] dy
75 integrand = @(t) 1 - F_X(t).^K;
77 % Expected value of minimum: E[Y_1] = integral_0^inf [1 - F_X(y)]^K dy
78 integrand = @(t) (1 - F_X(t)).^K;
80 % General
case: use the formula involving order statistic pdf
81 % E[Y_k] = integral_0^inf y * f_{Y_k}(y) dy
82 % where f_{Y_k}(y) = K * C(K-1,k-1) * f_X(y) * F_X(y)^{k-1} * (1-F_X(y))^{K-k}
84 % Use numerical differentiation for pdf (approximate)
86 f_X = @(t) (F_X(t + eps_val) - F_X(t - eps_val)) / (2 * eps_val);
88 coeff = K * nchoosek(K - 1, k - 1);
89 integrand = @(t) t .* coeff .* f_X(t) .* (F_X(t).^(k - 1)) .* ((1 - F_X(t)).^(K - k));
92 % Numerical integration
93 % Find reasonable upper limit (where CDF
is very close to 1)
94 upper_limit = find_upper_limit(F_X, 0.999999);
95 E_Yk = integral(integrand, 0, upper_limit,
'RelTol', 1e-8,
'AbsTol', 1e-10);
100function u = find_upper_limit(F_X, target)
101% Find value u such that F_X(u) >= target