LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
RAP.m
1classdef RAP < Markovian
2 % Rational Arrival Process (RAP) distribution
3 %
4 % RAP is a generalization of the Markovian Arrival Process (MAP) where
5 % the matrices H0 and H1 represent hidden and visible transitions respectively,
6 % but with relaxed constraints compared to MAP.
7 %
8 % Representation:
9 % - H0: matrix of hidden transition rates (transitions without arrivals)
10 % - H1: matrix of visible transition rates (transitions with arrivals)
11 % - H0 + H1 must form a valid infinitesimal generator (row sums = 0)
12 % - All eigenvalues of H0 must have negative real parts
13 % - Dominant eigenvalue of H0 must be negative and real
14 %
15 % The marginal distribution of inter-arrival times is a Matrix Exponential (ME).
16 %
17 % Copyright (c) 2012-2026, Imperial College London
18 % All rights reserved.
19
20 properties
21 H0; % Hidden transition matrix
22 H1; % Visible transition matrix
23 end
24
25 methods
26 function self = RAP(H0, H1)
27 % RAP Create a Rational Arrival Process instance
28 %
29 % @brief Creates a RAP with the given H0 and H1 matrices
30 % @param H0 Hidden transition matrix (square matrix)
31 % @param H1 Visible transition matrix (square matrix, same size as H0)
32 % @return self RAP distribution instance
33
34 % Call superclass constructor
35 self@Markovian('RAP', 2);
36
37 % Validate using BuTools
38 if ~CheckRAPRepresentation(H0, H1)
39 error('Invalid RAP representation: Check that H0 and H1 are square matrices of the same size, H0 + H1 forms a valid infinitesimal generator (row sums = 0), all eigenvalues of H0 have negative real parts, and the dominant eigenvalue of H0 is real.');
40 end
41
42 % Store parameters
43 self.H0 = H0;
44 self.H1 = H1;
45 self.nPhases = size(H0, 1);
46
47 % Set parameters
48 setParam(self, 1, 'H0', H0);
49 setParam(self, 2, 'H1', H1);
50
51 % Create Java object
52 H0Matrix = jline.util.matrix.Matrix(H0);
53 H1Matrix = jline.util.matrix.Matrix(H1);
54 self.obj = jline.lang.processes.RAP(H0Matrix, H1Matrix);
55
56 % Build process representation: {D0=H0, D1=H1}
57 % RAP uses same format as MAP
58 self.process = {H0, H1};
59
60 self.immediate = false;
61 end
62
63 function X = sample(self, n)
64 % X = SAMPLE(N)
65 % Get n samples from the distribution using rap_sample
66
67 if nargin < 2
68 n = 1;
69 end
70
71 % Use rap_sample for accurate sampling
72 X = rap_sample(self.process, n);
73 end
74
75 function phases = getNumberOfPhases(self)
76 % PHASES = GETNUMBEROFPHASES()
77 % Get number of phases in the RAP representation
78 phases = self.nPhases;
79 end
80
81 function Ft = evalCDF(self, t)
82 % FT = EVALCDF(SELF, T)
83 % Evaluate the cumulative distribution function at t
84 %
85 % For RAP, the marginal CDF is same as MAP
86
87 Ft = map_cdf(self.process, t);
88 end
89
90 function ft = evalPDF(self, t)
91 % FT = EVALPDF(SELF, T)
92 % Evaluate the probability density function at t
93 %
94 % For RAP, the marginal PDF is same as MAP
95
96 ft = map_pdf(self.process, t);
97 end
98
99 function L = evalLST(self, s)
100 % L = EVALST(S)
101 % Evaluate the Laplace-Stieltjes transform at s
102
103 % For RAP marginal: LST(s) = pie * (sI - H0)^(-1) * (-H0) * e
104 % where pie is the stationary distribution of H0 + H1
105 pie = map_pie(self.process);
106 n = self.nPhases;
107 e = ones(n, 1);
108 sI = s * eye(n);
109 L = pie * ((sI - self.H0) \ (-self.H0 * e));
110 end
111
112 function mean_val = getMean(self)
113 % MEAN_VAL = GETMEAN()
114 % Get mean of the RAP distribution
115
116 mean_val = map_mean(self.process);
117 end
118
119 function var_val = getVar(self)
120 % VAR_VAL = GETVAR()
121 % Get variance of the RAP distribution
122
123 var_val = map_var(self.process);
124 end
125
126 function scv = getSCV(self)
127 % SCV = GETSCV()
128 % Get squared coefficient of variation
129
130 scv = map_scv(self.process);
131 end
132
133 function lam = getRate(self)
134 % LAM = GETRATE()
135 % Get arrival rate (lambda) of the RAP
136
137 lam = map_lambda(self.process);
138 end
139
140 function acf = getACF(self, lags)
141 % ACF = GETACF(SELF, LAGS)
142 % Get autocorrelation function at specified lags
143
144 acf = map_acf(self.process, lags);
145 end
146
147 function idc = getIDC(self, t)
148 % IDC = GETIDC(SELF, T)
149 % Get index of dispersion for counts
150 % If t is not provided, returns asymptotic IDC
151
152 if nargin < 2
153 idc = map_idc(self.process);
154 else
155 idc = map_count_var(self.process, t) / map_count_mean(self.process, t);
156 end
157 end
158
159 function proc = getProcess(self)
160 % PROC = GETPROCESS()
161 % Get process representation {H0, H1}
162
163 proc = self.process;
164 end
165
166 function H0_out = getH0(self)
167 % H0_OUT = GETH0()
168 % Get H0 matrix (hidden transitions)
169
170 H0_out = self.H0;
171 end
172
173 function H1_out = getH1(self)
174 % H1_OUT = GETH1()
175 % Get H1 matrix (visible transitions)
176
177 H1_out = self.H1;
178 end
179 end
180
181 methods(Static)
182 function rap = fromPoisson(rate)
183 % RAP = FROMPOISSON(RATE)
184 % Create RAP from exponential renewal process (Poisson)
185 % Convenience method showing that Poisson is a special case of RAP
186 %
187 % @param rate Arrival rate (lambda)
188 % @return rap RAP distribution equivalent to Poisson(rate)
189
190 H0 = -rate;
191 H1 = rate;
192 rap = RAP(H0, H1);
193 end
194
195 function rap = fromErlang(k, rate)
196 % RAP = FROMERLANG(K, RATE)
197 % Create RAP from Erlang renewal process
198 % Convenience method showing that Erlang is a special case of RAP
199 %
200 % @param k Number of phases
201 % @param rate Rate parameter for each phase
202 % @return rap RAP distribution equivalent to Erlang(k, rate)
203
204 H0 = zeros(k, k);
205 H1 = zeros(k, k);
206
207 for i = 1:k
208 H0(i, i) = -rate; % diagonal
209 if i < k
210 H0(i, i+1) = rate; % transitions to next phase (no arrival)
211 end
212 end
213 % Last phase transition with arrival back to first phase
214 H1(k, 1) = rate;
215
216 rap = RAP(H0, H1);
217 end
218
219 function rap = fromMAP(map)
220 % RAP = FROMMAP(MAP)
221 % Create RAP from Markovian Arrival Process
222 % Convenience method showing that MAP is a special case of RAP
223 %
224 % @param map MAP distribution instance
225 % @return rap RAP distribution equivalent to the given MAP
226
227 if isa(map, 'MAP')
228 proc = map.getProcess();
229 D0 = proc{1};
230 D1 = proc{2};
231 elseif iscell(map)
232 D0 = map{1};
233 D1 = map{2};
234 else
235 error('Input must be a MAP object or a cell array {D0, D1}');
236 end
237
238 rap = RAP(D0, D1);
239 end
240
241 function rap = fitMoments(moms)
242 % RAP = FITMOMENTS(MOMS)
243 % Create RAP by fitting the given moments
244 % Uses BuTools RAPFromMoments algorithm
245 %
246 % @param moms Array of moments
247 % @return rap RAP distribution matching the given moments
248
249 error('RAP.fitMoments() requires RAPFromMoments from BuTools. Use the RAP(H0, H1) constructor directly for now.');
250 end
251
252 function rap = fitMomentsAndCorrelations(moms, corrs)
253 % RAP = FITMOMENTSANDCORRELATIONS(MOMS, CORRS)
254 % Create RAP by fitting the given moments and correlations
255 % Uses BuTools RAPFromMomentsAndCorrelations algorithm
256 %
257 % @param moms Array of moments
258 % @param corrs Array of lag-k correlations
259 % @return rap RAP distribution matching the given moments and correlations
260
261 error('RAP.fitMomentsAndCorrelations() requires RAPFromMomentsAndCorrelations from BuTools. Use the RAP(H0, H1) constructor directly for now.');
262 end
263 end
264end
Definition Station.m:287
Definition Station.m:245