1classdef RAP < Markovian
2 % Rational Arrival Process (RAP) distribution
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.
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
15 % The marginal distribution of inter-arrival times
is a Matrix Exponential (ME).
17 % Copyright (c) 2012-2026, Imperial College London
18 % All rights reserved.
21 H0; % Hidden transition matrix
22 H1; % Visible transition matrix
26 function self = RAP(H0, H1)
27 % RAP Create a Rational Arrival Process instance
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
34 % Call superclass constructor
35 self@Markovian(
'RAP', 2);
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.');
45 self.nPhases = size(H0, 1);
48 setParam(self, 1,
'H0', H0);
49 setParam(self, 2,
'H1', H1);
52 H0Matrix = jline.util.matrix.Matrix(H0);
53 H1Matrix = jline.util.matrix.Matrix(H1);
54 self.obj = jline.lang.processes.RAP(H0Matrix, H1Matrix);
56 % Build process representation: {D0=H0, D1=H1}
57 % RAP uses same format as MAP
58 self.process = {H0, H1};
60 self.immediate =
false;
63 function X = sample(self, n)
65 % Get n samples from the distribution
using rap_sample
71 % Use rap_sample
for accurate sampling
72 X = rap_sample(self.process, n);
75 function phases = getNumberOfPhases(self)
76 % PHASES = GETNUMBEROFPHASES()
77 % Get number of phases in the RAP representation
78 phases = self.nPhases;
81 function Ft = evalCDF(self, t)
82 % FT = EVALCDF(SELF, T)
83 % Evaluate the cumulative distribution function at t
85 % For RAP, the marginal CDF
is same as MAP
87 Ft = map_cdf(self.process, t);
90 function L = evalLST(self, s)
92 % Evaluate the Laplace-Stieltjes transform at s
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);
100 L = pie * ((sI - self.H0) \ (-self.H0 * e));
103 function mean_val = getMean(self)
104 % MEAN_VAL = GETMEAN()
105 % Get mean of the RAP distribution
107 mean_val = map_mean(self.process);
110 function var_val = getVar(self)
112 % Get variance of the RAP distribution
114 var_val = map_var(self.process);
117 function scv = getSCV(self)
119 % Get squared coefficient of variation
121 scv = map_scv(self.process);
124 function lam = getRate(self)
126 % Get arrival rate (lambda) of the RAP
128 lam = map_lambda(self.process);
131 function acf = getACF(self, lags)
132 % ACF = GETACF(SELF, LAGS)
133 % Get autocorrelation function at specified lags
135 acf = map_acf(self.process, lags);
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
144 idc = map_idc(self.process);
146 idc = map_count_var(self.process, t) / map_count_mean(self.process, t);
150 function proc = getProcess(self)
151 % PROC = GETPROCESS()
152 % Get process representation {H0, H1}
157 function H0_out = getH0(self)
159 % Get H0 matrix (hidden transitions)
164 function H1_out = getH1(self)
166 % Get H1 matrix (visible transitions)
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
178 % @param rate Arrival rate (lambda)
179 % @
return rap RAP distribution equivalent to Poisson(rate)
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
191 % @param k Number of phases
192 % @param rate Rate parameter
for each phase
193 % @
return rap RAP distribution equivalent to Erlang(k, rate)
199 H0(i, i) = -rate; % diagonal
201 H0(i, i+1) = rate; % transitions to next phase (no arrival)
204 % Last phase transition with arrival back to first phase
210 function rap = fromMAP(
map)
212 % Create RAP from Markovian Arrival Process
213 % Convenience method showing that MAP
is a special
case of RAP
215 % @param
map MAP distribution instance
216 % @
return rap RAP distribution equivalent to the given MAP
219 proc =
map.getProcess();
226 error(
'Input must be a MAP object or a cell array {D0, D1}');
232 function rap = fitMoments(moms)
233 % RAP = FITMOMENTS(MOMS)
234 % Create RAP by fitting the given moments
235 % Uses BuTools RAPFromMoments algorithm
237 % @param moms Array of moments
238 % @
return rap RAP distribution matching the given moments
240 error(
'RAP.fitMoments() requires RAPFromMoments from BuTools. Use the RAP(H0, H1) constructor directly for now.');
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
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
252 error(
'RAP.fitMomentsAndCorrelations() requires RAPFromMomentsAndCorrelations from BuTools. Use the RAP(H0, H1) constructor directly for now.');