1classdef Erlang < Markovian
2 % Erlang Multi-phase exponential distribution with reduced variability
4 % Erlang represents the distribution of the sum of r independent exponential
5 % random variables with the same rate. It models processes with reduced
6 % variability compared to exponential distributions and
is commonly used
7 %
for service times with more predictable durations.
9 % @brief Erlang distribution with phase rate and number of phases
11 % Key characteristics:
12 % - Sum of r independent exponential phases
13 % - Two parameters: phase rate (alpha) and number of phases (r)
14 % - Mean = r/alpha, Variance = r/alpha²
15 % - SCV = 1/r (always ≤ 1, decreasing with r)
16 % - Multi-phase Markovian representation
18 % The Erlang distribution
is used
for:
19 % - Service times with reduced variability
20 % - Multi-stage service processes
21 % - Modeling deterministic processes approximately
22 % - Building blocks
for phase-type distributions
23 % - Systems where variability decreases with stages
27 % service_dist = Erlang(3.0, 4); % 4 phases, rate 3.0 each
28 % % Mean = 4/3.0 = 1.33, SCV = 1/4 = 0.25
29 % samples = service_dist.sample(1000);
32 % Copyright (c) 2012-2026, Imperial College London
33 % All rights reserved.
36 function self = Erlang(phaseRate, nphases)
37 % ERLANG Create an Erlang distribution instance
39 % @brief Creates an Erlang distribution with specified phase rate and phases
40 % @param phaseRate Rate parameter for each exponential phase
41 % @param nphases Number of sequential exponential phases (positive integer)
42 % @return self Erlang distribution instance
43 self@Markovian('Erlang',2);
44 setParam(self, 1,
'alpha', phaseRate); % rate in each state
45 setParam(self, 2,
'r', round(nphases)); % number of phases
46 self.obj = jline.lang.processes.Erlang(phaseRate, nphases);
47 r = self.getParam(2).paramValue;
48 self.process = map_erlang(getMean(self),r);
49 self.nPhases = length(self.process{1});
52 function phases = getNumberOfPhases(self)
53 % PHASES = GETNUMBEROFPHASES()
55 % Get number of phases in the underpinnning phase-type
57 phases = self.getParam(2).paramValue; %r
60 function ex = getMean(self)
63 % Get distribution mean
64 alpha = self.getParam(1).paramValue;
65 r = self.getParam(2).paramValue;
69 function SCV = getSCV(self)
71 % Get the squared coefficient of variation of the distribution (SCV = variance / mean^2)
72 r = self.getParam(2).paramValue;
76 function setMean(self,MEAN)
77 % UPDATEMEAN(SELF,MEAN)
78 % Update parameters to match the given mean
79 setMean@Markovian(self,MEAN);
80 r = self.getParam(2).paramValue;
81 self.setParam(1,
'alpha', r/MEAN);
82 self.process = map_erlang(getMean(self),r);
86 function Ft = evalCDF(self,t)
87 % FT = EVALCDF(SELF,T)
89 % Evaluate the cumulative distribution function at t
92 alpha = self.getParam(1).paramValue; % rate
93 r = self.getParam(2).paramValue; % stages
96 Ft = Ft - exp(-alpha*t).*(alpha*t).^j/factorial(j);
100 function L = evalLST(self, s)
101 % L = EVALLAPLACETRANSFORM(S)
103 % Evaluate the Laplace transform of the distribution function at t
106 alpha = self.getParam(1).paramValue; % rate
107 r = self.getParam(2).paramValue; % stages
108 L = (alpha / (alpha + s))^r;
113 function er = fit(MEAN, SCV, SKEW)
114 % ER = FITCENTRAL(MEAN, SCV, SKEW)
116 % Fit distribution from first three central moments (mean,
118 er = Erlang.fitMeanAndSCV(MEAN,SCV);
119 er.immediate = MEAN < GlobalConstants.FineTol;
122 % function er = fitRate(RATE)
123 % % ER = FITRATE(RATE)
125 % % Fit distribution with given rate
126 % line_warning(mfilename,
'The Erlang distribution is underspecified by the rate, setting the number of phases to 2.\n');
127 % er = Erlang.fitMeanAndOrder(1/RATE, 2);
128 % er.immediate = 1/RATE < GlobalConstants.FineTol;
131 % function er = fitMean(MEAN)
132 % % ER = FITMEAN(MEAN)
134 % % Fit distribution with given mean
135 % line_warning(mfilename,
'The Erlang distribution is underspecified by the mean, setting the number of phases to 2.\n');
136 % er = Erlang.fitMeanAndOrder(MEAN, 2);
137 % er.immediate = MEAN < GlobalConstants.FineTol;
140 function er = fitMeanAndSCV(MEAN, SCV)
141 % ER = FITMEANANDSCV(MEAN, SCV)
143 line_error(mfilename,
'The Erlang distribution requires squared coefficient of vairation <= 1.');
145 % Fit distribution with given mean and squared coefficient of variation (SCV=variance/mean^2)
148 er = Erlang(alpha, r);
149 er.immediate = MEAN < GlobalConstants.FineTol;
152 function er = fitMeanAndOrder(MEAN, n)
153 % ER = FITMEANANDORDER(MEAN, N)
155 % Fit distribution with given mean and number of phases
159 er = Erlang(alpha, r);
160 er.immediate = MEAN < GlobalConstants.FineTol;