LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
getCdfAoI.m
1function [AoI_cdf, PAoI_cdf] = getCdfAoI(self, t_values)
2%GETCDFAOI Get CDF of Age of Information
3%
4% [AoI_cdf, PAoI_cdf] = GETCDFAOI(t_values)
5%
6% Returns the cumulative distribution function (CDF) of Age of Information
7% and Peak AoI computed using matrix exponential representations.
8%
9% The CDF is computed using the formula:
10% F(t) = 1 - g * expm(A*t) * h
11%
12% where g, A, h are the matrix exponential parameters from the aoi-fluid solver.
13%
14% Parameters:
15% self: SolverFLD instance
16% t_values (optional): Vector of time values at which to evaluate CDF
17% If not provided, uses automatic range based on mean
18%
19% Returns:
20% AoI_cdf: [n x 2] matrix with [CDF_values, t_values] for AoI
21% PAoI_cdf: [n x 2] matrix with [CDF_values, t_values] for Peak AoI
22%
23% Example:
24% model = Network('AoI_Example');
25% % ... model setup ...
26% solver = SolverFLD(model, 'method', 'mfq');
27% solver.getAvg();
28%
29% % Get CDF at automatic time points
30% [AoI_cdf, PAoI_cdf] = solver.getCdfAoI();
31%
32% % Plot CDFs
33% figure;
34% plot(AoI_cdf(:,2), AoI_cdf(:,1), 'b-', 'LineWidth', 2);
35% hold on;
36% plot(PAoI_cdf(:,2), PAoI_cdf(:,1), 'r--', 'LineWidth', 2);
37% xlabel('Age');
38% ylabel('CDF');
39% legend('AoI', 'Peak AoI');
40%
41% % Get CDF at specific time points
42% t = linspace(0, 10, 100);
43% [AoI_cdf, PAoI_cdf] = solver.getCdfAoI(t);
44%
45% See also: getAvgAoI, solver_mfq_aoi, aoi_is_aoi
46
47% Copyright (c) 2012-2026, Imperial College London
48% All rights reserved.
49
50% Ensure solver has been run
51if isempty(self.result)
52 self.getAvg();
53end
54
55% Initialize outputs
56AoI_cdf = [];
57PAoI_cdf = [];
58
59% Check if AoI results are available
60if ~isfield(self.result, 'solverSpecific') || ...
61 ~isfield(self.result.solverSpecific, 'aoiResults') || ...
62 isempty(self.result.solverSpecific.aoiResults)
63 line_warning(mfilename, 'No AoI results available. Ensure model has valid AoI topology and use method=''mfq''.');
64 return;
65end
66
67aoiResults = self.result.solverSpecific.aoiResults;
68
69% Check if matrix exponential parameters are available
70if isempty(aoiResults.AoI_A) || isempty(aoiResults.AoI_g) || isempty(aoiResults.AoI_h)
71 line_warning(mfilename, 'Matrix exponential parameters not available for AoI CDF computation.');
72 return;
73end
74
75% Generate time values if not provided
76if nargin < 2 || isempty(t_values)
77 % Use automatic range based on mean AoI
78 mean_aoi = aoiResults.AoI_mean;
79 if isnan(mean_aoi) || mean_aoi <= 0
80 mean_aoi = 1; % Default if mean is invalid
81 end
82 % Range from 0 to 5 times the mean (covers most of the distribution)
83 t_max = 5 * mean_aoi;
84 t_values = linspace(0, t_max, 200);
85end
86
87t_values = t_values(:); % Ensure column vector
88n = length(t_values);
89
90% Extract matrix exponential parameters for AoI
91AoI_g = aoiResults.AoI_g;
92AoI_A = aoiResults.AoI_A;
93AoI_h = aoiResults.AoI_h;
94
95% Compute AoI CDF: F(t) = 1 - g * expm(A*t) * h
96AoI_F = zeros(n, 1);
97for i = 1:n
98 t = t_values(i);
99 if t <= 0
100 AoI_F(i) = 0;
101 else
102 % Compute matrix exponential
103 expAt = expm(AoI_A * t);
104 ccdf = AoI_g * expAt * AoI_h;
105 AoI_F(i) = max(0, min(1, 1 - ccdf));
106 end
107end
108
109AoI_cdf = [AoI_F, t_values];
110
111% Extract matrix exponential parameters for Peak AoI
112PAoI_g = aoiResults.PAoI_g;
113PAoI_A = aoiResults.PAoI_A;
114PAoI_h = aoiResults.PAoI_h;
115
116% Compute Peak AoI CDF: F(t) = 1 - g * expm(A*t) * h
117PAoI_F = zeros(n, 1);
118for i = 1:n
119 t = t_values(i);
120 if t <= 0
121 PAoI_F(i) = 0;
122 else
123 % Compute matrix exponential
124 expAt = expm(PAoI_A * t);
125 ccdf = PAoI_g * expAt * PAoI_h;
126 PAoI_F(i) = max(0, min(1, 1 - ccdf));
127 end
128end
129
130PAoI_cdf = [PAoI_F, t_values];
131
132end