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 L = evalLST(self, s)
91 % L = EVALST(S)
92 % Evaluate the Laplace-Stieltjes transform at s
93
94 % For RAP marginal: LST(s) = pie * (sI - H0)^(-1) * (-H0) * e
95 % where pie is the stationary distribution of H0 + H1
96 pie = map_pie(self.process);
97 n = self.nPhases;
98 e = ones(n, 1);
99 sI = s * eye(n);
100 L = pie * ((sI - self.H0) \ (-self.H0 * e));
101 end
102
103 function mean_val = getMean(self)
104 % MEAN_VAL = GETMEAN()
105 % Get mean of the RAP distribution
106
107 mean_val = map_mean(self.process);
108 end
109
110 function var_val = getVar(self)
111 % VAR_VAL = GETVAR()
112 % Get variance of the RAP distribution
113
114 var_val = map_var(self.process);
115 end
116
117 function scv = getSCV(self)
118 % SCV = GETSCV()
119 % Get squared coefficient of variation
120
121 scv = map_scv(self.process);
122 end
123
124 function lam = getRate(self)
125 % LAM = GETRATE()
126 % Get arrival rate (lambda) of the RAP
127
128 lam = map_lambda(self.process);
129 end
130
131 function acf = getACF(self, lags)
132 % ACF = GETACF(SELF, LAGS)
133 % Get autocorrelation function at specified lags
134
135 acf = map_acf(self.process, lags);
136 end
137
138 function idc = getIDC(self, t)
139 % IDC = GETIDC(SELF, T)
140 % Get index of dispersion for counts
141 % If t is not provided, returns asymptotic IDC
142
143 if nargin < 2
144 idc = map_idc(self.process);
145 else
146 idc = map_count_var(self.process, t) / map_count_mean(self.process, t);
147 end
148 end
149
150 function proc = getProcess(self)
151 % PROC = GETPROCESS()
152 % Get process representation {H0, H1}
153
154 proc = self.process;
155 end
156
157 function H0_out = getH0(self)
158 % H0_OUT = GETH0()
159 % Get H0 matrix (hidden transitions)
160
161 H0_out = self.H0;
162 end
163
164 function H1_out = getH1(self)
165 % H1_OUT = GETH1()
166 % Get H1 matrix (visible transitions)
167
168 H1_out = self.H1;
169 end
170 end
171
172 methods(Static)
173 function rap = fromPoisson(rate)
174 % RAP = FROMPOISSON(RATE)
175 % Create RAP from exponential renewal process (Poisson)
176 % Convenience method showing that Poisson is a special case of RAP
177 %
178 % @param rate Arrival rate (lambda)
179 % @return rap RAP distribution equivalent to Poisson(rate)
180
181 H0 = -rate;
182 H1 = rate;
183 rap = RAP(H0, H1);
184 end
185
186 function rap = fromErlang(k, rate)
187 % RAP = FROMERLANG(K, RATE)
188 % Create RAP from Erlang renewal process
189 % Convenience method showing that Erlang is a special case of RAP
190 %
191 % @param k Number of phases
192 % @param rate Rate parameter for each phase
193 % @return rap RAP distribution equivalent to Erlang(k, rate)
194
195 H0 = zeros(k, k);
196 H1 = zeros(k, k);
197
198 for i = 1:k
199 H0(i, i) = -rate; % diagonal
200 if i < k
201 H0(i, i+1) = rate; % transitions to next phase (no arrival)
202 end
203 end
204 % Last phase transition with arrival back to first phase
205 H1(k, 1) = rate;
206
207 rap = RAP(H0, H1);
208 end
209
210 function rap = fromMAP(map)
211 % RAP = FROMMAP(MAP)
212 % Create RAP from Markovian Arrival Process
213 % Convenience method showing that MAP is a special case of RAP
214 %
215 % @param map MAP distribution instance
216 % @return rap RAP distribution equivalent to the given MAP
217
218 if isa(map, 'MAP')
219 proc = map.getProcess();
220 D0 = proc{1};
221 D1 = proc{2};
222 elseif iscell(map)
223 D0 = map{1};
224 D1 = map{2};
225 else
226 error('Input must be a MAP object or a cell array {D0, D1}');
227 end
228
229 rap = RAP(D0, D1);
230 end
231
232 function rap = fitMoments(moms)
233 % RAP = FITMOMENTS(MOMS)
234 % Create RAP by fitting the given moments
235 % Uses BuTools RAPFromMoments algorithm
236 %
237 % @param moms Array of moments
238 % @return rap RAP distribution matching the given moments
239
240 error('RAP.fitMoments() requires RAPFromMoments from BuTools. Use the RAP(H0, H1) constructor directly for now.');
241 end
242
243 function rap = fitMomentsAndCorrelations(moms, corrs)
244 % RAP = FITMOMENTSANDCORRELATIONS(MOMS, CORRS)
245 % Create RAP by fitting the given moments and correlations
246 % Uses BuTools RAPFromMomentsAndCorrelations algorithm
247 %
248 % @param moms Array of moments
249 % @param corrs Array of lag-k correlations
250 % @return rap RAP distribution matching the given moments and correlations
251
252 error('RAP.fitMomentsAndCorrelations() requires RAPFromMomentsAndCorrelations from BuTools. Use the RAP(H0, H1) constructor directly for now.');
253 end
254 end
255end