LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
DiscreteUniform.m
1classdef DiscreteUniform < DiscreteDistribution
2 % The uniform statistical distribution
3 %
4 % Copyright (c) 2012-2026, Imperial College London
5 % All rights reserved.
6
7 methods
8 function self = DiscreteUniform(minVal, maxVal)
9 % SELF = UNIFORM(MINVAL, MAXVAL)
10
11 % Constructs an uniform distribution with specified minimum and
12 % maximum values
13 self@DiscreteDistribution('DiscreteUniform',2,[minVal,maxVal]);
14 setParam(self, 1, 'min', minVal);
15 setParam(self, 2, 'max', maxVal);
16 end
17
18 function ex = getMean(self)
19 % EX = GETMEAN()
20
21 % Get distribution mean
22 ex = (self.getParam(2).paramValue+self.getParam(1).paramValue) / 2;
23 end
24
25 function SCV = getSCV(self)
26 % SCV = GETSCV()
27
28 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
29 var = ((self.getParam(2).paramValue-self.getParam(1).paramValue+1)^2-1) / 12;
30 SCV = var/getMean(self)^2;
31 end
32
33 function Ft = evalCDF(self,t)
34 % FT = EVALCDF(SELF,T)
35
36 % Evaluate the cumulative distribution function at T
37
38 minVal = self.getParam(1).paramValue;
39 maxVal = self.getParam(2).paramValue;
40 if t < minVal
41 Ft = 0;
42 elseif t > maxVal
43 Ft = 0;
44 else
45 Ft = (floor(t)-minVal+1)/(maxVal-minVal+1);
46 end
47 end
48
49 function P = evalPMF(self,k)
50 % P = EVALPMF(SELF,K)
51
52 % Evaluate the probability mass function at K
53
54 minVal = self.getParam(1).paramValue;
55 maxVal = self.getParam(2).paramValue;
56 if k < minVal || k > maxVal
57 P = 0;
58 else
59 P = 1/(maxVal-minVal+1);
60 end
61 end
62
63 function L = evalLST(self, s)
64 % L = EVALST(S)
65 % Evaluate the Laplace-Stieltjes transform of the distribution function at s
66 % For DiscreteUniform(a, b), LST(s) = (e^(-as) - e^(-(b+1)s)) / ((b-a+1)(1 - e^(-s)))
67
68 a = self.getParam(1).paramValue;
69 b = self.getParam(2).paramValue;
70
71 if abs(s) < 1e-10
72 % Handle s ≈ 0 case to avoid division by zero
73 L = 1.0;
74 else
75 e_neg_s = exp(-s);
76 numerator = exp(-a * s) - exp(-(b + 1) * s);
77 denominator = (b - a + 1) * (1 - e_neg_s);
78 L = numerator / denominator;
79 end
80 end
81
82
83 function X = sample(self, n)
84 % X = SAMPLE(N)
85
86 % Get n samples from the distribution
87 if nargin<2 %~exist('n','var'),
88 n = 1;
89 end
90 minVal = self.getParam(1).paramValue;
91 maxVal = self.getParam(2).paramValue;
92 X = round(minVal + (maxVal-minVal)*rand(n,1));
93 end
94
95 function proc = getProcess(self)
96 % PROC = GETPROCESS()
97
98 % Get process representation for non-Markovian distribution
99 % Returns [mean, SCV] pair for use in network analysis
100 proc = [self.getMean(), self.getSCV()];
101 end
102 end
103
104end
105
Definition Station.m:245