LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
fj_order_stat.m
1%{ @file fj_order_stat.m
2 % @brief CDF and expected value of k-th order statistic
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief CDF and expected value of k-th order statistic
9 %
10 % @details
11 % Computes the CDF and expected value of the k-th order statistic
12 % (k-th smallest) of K i.i.d. random variables.
13 %
14 % For maximum (k=K):
15 % F_{Y_K}(y) = [F_X(y)]^K
16 %
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}
19 %
20 % Expected value of maximum:
21 % E[Y_K] = integral_0^inf [1 - F_X(y)^K] dy
22 %
23 % @par Syntax:
24 % @code
25 % F_Yk = fj_order_stat(y, k, K, F_X)
26 % [F_Yk, E_Yk] = fj_order_stat(y, k, K, F_X)
27 % @endcode
28 %
29 % @par Parameters:
30 % <table>
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
36 % </table>
37 %
38 % @par Returns:
39 % <table>
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)
43 % </table>
44 %
45 % @par Reference:
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.
49%}
50function [F_Yk, E_Yk] = fj_order_stat(y, k, K, F_X)
51
52if k < 1 || k > K
53 line_error(mfilename, 'k must satisfy 1 <= k <= K. Got k=%d, K=%d.', k, K);
54end
55
56% Evaluate the base CDF at y
57F_y = F_X(y);
58
59if k == K
60 % Maximum (K-th order statistic): F_{Y_K}(y) = [F_X(y)]^K
61 F_Yk = F_y.^K;
62else
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));
66 for j = k:K
67 F_Yk = F_Yk + nchoosek(K, j) .* (F_y.^j) .* ((1 - F_y).^(K - j));
68 end
69end
70
71% Compute expected value if requested
72if nargout > 1
73 if k == K
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;
76 elseif k == 1
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;
79 else
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}
83
84 % Use numerical differentiation for pdf (approximate)
85 eps_val = 1e-8;
86 f_X = @(t) (F_X(t + eps_val) - F_X(t - eps_val)) / (2 * eps_val);
87
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));
90 end
91
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);
96end
97
98end
99
100function u = find_upper_limit(F_X, target)
101% Find value u such that F_X(u) >= target
102u = 1;
103max_iter = 100;
104for iter = 1:max_iter
105 if F_X(u) >= target
106 break;
107 end
108 u = u * 2;
109end
110end