LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Gamma.m
1classdef Gamma < ContinuousDistribution
2 % Gamma General-purpose continuous distribution with shape and scale
3 %
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.
8 %
9 % @brief Gamma distribution with flexible shape and scale parameters
10 %
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)
15 % - Support: (0, ∞)
16 % - Includes exponential (alpha=1) and Erlang as special cases
17 %
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
24 %
25 % Example:
26 % @code
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);
29 % @endcode
30 %
31 % Copyright (c) 2012-2026, Imperial College London
32 % All rights reserved.
33
34 methods
35 function self = Gamma(shape, scale)
36 % GAMMA Create a Gamma distribution instance
37 %
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);
45 end
46 end
47
48 methods
49 function ex = getMean(self)
50 % EX = GETMEAN()
51
52 % Get distribution mean
53 shape = self.getParam(1).paramValue;
54 scale = self.getParam(2).paramValue;
55 ex = shape*scale;
56 end
57
58 function SCV = getSCV(self)
59 % SCV = GETSCV()
60
61 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
62
63 shape = self.getParam(1).paramValue;
64 SCV = 1 / shape;
65 end
66
67 function X = sample(self, n)
68 % X = SAMPLE(N)
69
70 % Get n samples from the distribution
71 if nargin<2 %~exist('n','var'),
72 n = 1;
73 end
74 shape = self.getParam(1).paramValue;
75 scale = self.getParam(2).paramValue;
76 X = gamrnd(shape, scale, n, 1);
77 end
78
79 function Ft = evalCDF(self,t)
80 % FT = EVALCDF(SELF,T)
81
82 % Evaluate the cumulative distribution function at t
83 % AT T
84
85 shape = self.getParam(1).paramValue;
86 scale = self.getParam(2).paramValue;
87 Ft = gamcdf(t,shape,scale);
88 end
89
90 function L = evalLST(self, s)
91 % L = EVALLAPLACETRANSFORM(S)
92
93 % Evaluate the Laplace transform of the distribution function at t
94
95 shape = self.getParam(1).paramValue; %alpha
96 scale = self.getParam(2).paramValue; %beta
97 L = ((1/scale) / (s+1/scale))^shape;
98 end
99
100 function proc = getProcess(self)
101 % PROC = GETPROCESS()
102
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};
106 end
107 end
108
109 methods(Static)
110 function gm = fitMeanAndSCV(MEAN, SCV)
111 % GM = FITMEANANDSCV(MEAN, SCV)
112
113 % Fit distribution from mean and squared coefficient of
114 % variation
115 shape = 1 / SCV;
116 scale = MEAN / shape;
117 gm = Gamma(shape, scale);
118 end
119 end
120
121end
122