1classdef Gamma < ContinuousDistribution
2 % Gamma General-purpose continuous distribution with shape and scale
4 % Gamma represents the gamma distribution with shape (alpha) and scale (beta)
5 % parameters. This versatile distribution can model various phenomena and
6 % includes the exponential and Erlang distributions as special cases. It
is
7 % commonly used
for modeling service times and inter-arrival times.
9 % @brief Gamma distribution with flexible shape and scale parameters
11 % Key characteristics:
12 % - Two parameters: shape (alpha) and scale (beta)
13 % - Mean = alpha * beta, Variance = alpha * beta²
14 % - SCV = 1/alpha (decreases with shape parameter)
16 % - Includes exponential (alpha=1) and Erlang as special cases
18 % The gamma distribution
is used
for:
19 % - Service time modeling with flexible variability
20 % - Waiting time distributions
21 % - Inter-arrival time modeling
22 % - Reliability and survival analysis
23 % - Approximating other continuous distributions
27 % service_dist = Gamma(2.0, 1.5); % Shape=2, Scale=1.5, Mean=3.0, SCV=0.5
28 % samples = service_dist.sample(1000);
31 % Copyright (c) 2012-2026, Imperial College London
32 % All rights reserved.
35 function self = Gamma(shape, scale)
36 % GAMMA Create a Gamma distribution instance
38 % @brief Creates a Gamma distribution with specified shape and scale
39 % @param shape Shape parameter alpha (must be positive)
40 % @param scale Scale parameter beta (must be positive)
41 % @return self Gamma distribution instance
42 self@ContinuousDistribution('Gamma',2,[0,Inf]);
43 setParam(self, 1,
'alpha', shape);
44 setParam(self, 2,
'beta', scale);
49 function ex = getMean(self)
52 % Get distribution mean
53 shape = self.getParam(1).paramValue;
54 scale = self.getParam(2).paramValue;
58 function SCV = getSCV(self)
61 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
63 shape = self.getParam(1).paramValue;
67 function X = sample(self, n)
70 % Get n samples from the distribution
71 if nargin<2 %~exist(
'n',
'var'),
74 shape = self.getParam(1).paramValue;
75 scale = self.getParam(2).paramValue;
76 X = gamrnd(shape, scale, n, 1);
79 function Ft = evalCDF(self,t)
80 % FT = EVALCDF(SELF,T)
82 % Evaluate the cumulative distribution function at t
85 shape = self.getParam(1).paramValue;
86 scale = self.getParam(2).paramValue;
87 Ft = gamcdf(t,shape,scale);
90 function L = evalLST(self, s)
91 % L = EVALLAPLACETRANSFORM(S)
93 % Evaluate the Laplace transform of the distribution function at t
95 shape = self.getParam(1).paramValue; %alpha
96 scale = self.getParam(2).paramValue; %beta
97 L = ((1/scale) / (s+1/scale))^shape;
100 function proc = getProcess(self)
101 % PROC = GETPROCESS()
103 % Get process representation with actual distribution parameters
104 % Returns {shape, scale}
for gamma distribution
105 proc = {self.getParam(1).paramValue, self.getParam(2).paramValue};
110 function gm = fitMeanAndSCV(MEAN, SCV)
111 % GM = FITMEANANDSCV(MEAN, SCV)
113 % Fit distribution from mean and squared coefficient of
116 scale = MEAN / shape;
117 gm = Gamma(shape, scale);