LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Distribution.m
1classdef Distribution < Copyable
2 % Distribution Abstract base class for statistical distributions
3 %
4 % Distribution provides the common interface and functionality for all
5 % statistical distributions used in queueing models. It defines abstract
6 % methods for sampling, computing moments, and obtaining distribution
7 % properties that must be implemented by concrete distribution classes.
8 %
9 % @brief Abstract base class for all statistical distribution types
10 %
11 % Key characteristics:
12 % - Abstract interface for all distributions
13 % - Support for both discrete and continuous distributions
14 % - Moment computation (mean, variance, SCV)
15 % - Random sampling capabilities
16 % - Parameter management and validation
17 % - Copyable interface for cloning distributions
18 %
19 % Distribution hierarchy includes:
20 % - Continuous distributions (Exp, Erlang, HyperExp, etc.)
21 % - Discrete distributions (Poisson, Bernoulli, Zipf, etc.)
22 % - Phase-type distributions (PH, APH, Coxian, etc.)
23 % - Markov-modulated processes (MAP, MMPP, etc.)
24 %
25 % Common usage patterns:
26 % @code
27 % dist = Exp(1.5); % Exponential with rate 1.5
28 % mean_val = dist.getMean(); % Get mean value
29 % samples = dist.sample(100); % Generate 100 samples
30 % @endcode
31 %
32 % Copyright (c) 2012-2026, Imperial College London
33 % All rights reserved.
34
35 properties (Hidden)
36 mean; % cached mean
37 immediate; % true if immediate
38 end
39
40 properties
41 obj
42 name
43 params
44 support; % support interval
45 end
46
47 methods %(Abstract)
48
49 function X = sample(self,n)
50 % SAMPLE Generate random samples from the distribution
51 %
52 % @brief Generates n random samples from this distribution
53 % @param n Number of samples to generate
54 % @return X Vector of n random samples
55 line_error(mfilename,'An abstract method was called. The function needs to be overridden by a subclass.');
56 end
57
58 function RATE = getRate(self)
59 % GETRATE Get the rate parameter (inverse of mean)
60 %
61 % @brief Returns the rate parameter defined as 1/mean
62 % @return RATE Rate parameter (1/mean)
63 RATE = 1 / getMean(self);
64 end
65
66 function MEAN = getMean(self)
67 % MEAN = GETMEAN()
68 % Get distribution mean
69 line_error(mfilename,'An abstract method was called. The function needs to be overridden by a subclass.');
70 end
71
72 function SCV = getSCV(self)
73 % SCV = GETSCV()
74 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
75 line_error(mfilename,'An abstract method was called. The function needs to be overridden by a subclass.');
76 end
77
78 function VAR = getVar(self)
79 % VAR = GETVAR()
80 % Get distribution variance
81 VAR = getSCV(self)*getMean(self)^2;
82 end
83
84 function SKEW = getSkewness(self)
85 % SKEW = GETSKEWNESS()
86 % Get distribution skewness
87 line_error(mfilename,'An abstract method was called. The function needs to be overridden by a subclass.');
88 end
89
90 function Ft = evalCDF(self,t)
91 % FT = EVALCDF(SELF,T)
92 % Evaluate the cumulative distribution function at t
93 line_error(mfilename,'An abstract method was called. The function needs to be overridden by a subclass.');
94 end
95
96 function L = evalLST(self, s)
97 % L = EVALLAPLACETRANSFORM(S)
98 % Evaluate the Laplace transform of the distribution function at t
99 line_error(mfilename,'An abstract method was called. The function needs to be overridden by a subclass.');
100
101 end
102 end
103
104 methods (Hidden)
105 function self = Distribution(name, numParam, support)
106 % SELF = DISTRIB(NAME, NUMPARAM, SUPPORT)
107 % Construct a distribution from name, number of parameters, and
108 % range
109 self.name = name;
110 self.support = support;
111 self.setNumParams(numParam);
112 self.immediate = false;
113 end
114 end
115
116 methods
117 function nParam = setNumParams(self, numParam)
118 % NPARAM = SETNUMPARAMS(NUMPARAM)
119 % Initializes the parameters
120 self.params = cell(1,numParam);
121 for i=1:numParam
122 self.params{i}=struct('paramName','','paramValue',NaN);
123 end
124 end
125
126 function nParam = getNumParams(self)
127 % NPARAM = GETNUMPARAMS()
128 % Returns the number of parameters needed to specify the distribution
129 nParam = length(self.params);
130 end
131
132 function setParam(self, id, name, value)
133 % SETPARAM(ID, NAME, VALUE, TYPECLASS)
134 % Set a distribution parameter given id, name, value, Java
135 % class type (for JMT translation)
136 self.params{id}.paramName=name;
137 self.params{id}.paramValue=value;
138 end
139
140 function param = getParam(self,id)
141 % PARAM = GETPARAM(SELF,ID)
142 % Return the parameter associated to the given id
143 param = self.params{id};
144 end
145
146 function bool = isDisabled(self)
147 % BOOL = ISDISABLED()
148 % Check if the distribution is equivalent to a Disabled
149 % distribution
150 %bool = cellfun(@(c) isnan(c.paramValue), self.params)
151 bool = isnan(getMean(self));
152 end
153
154 function bool = isImmediate(self)
155 % BOOL = ISIMMEDIATE()
156 % Check if the distribution is equivalent to an Immediate
157 % distribution
158 bool = self.immediate;
159 end
160
161 function bool = isContinuous(self)
162 % BOOL = ISCONTINUOUS()
163 % Check if the distribution is discrete
164 bool = isa(self,'ContinuousDistribution');
165 end
166
167 function bool = isDiscrete(self)
168 % BOOL = ISDISCRETE()
169 % Check if the distribution is discrete
170 bool = isa(self,'DiscreteDistribution');
171 end
172
173 function delta = evalProbInterval(self,t0,t1)
174 % DELTA = EVALPROBINTERVAL(SELF,T0,T1)
175 % Evaluate the probability mass between t0 and t1 (t1>t0)
176 if t1>=t0
177 Ft1 = self.evalCDF(t1);
178 Ft0 = self.evalCDF(t0);
179 delta = Ft1 - Ft0;
180 else
181 line_error(mfilename,'CDF interval incorrectly specified (t1<t0)');
182 end
183 end
184 end
185end