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 L = evalLST(self, s)
50 % L = EVALST(S)
51 % Evaluate the Laplace-Stieltjes transform of the distribution function at s
52 % For DiscreteUniform(a, b), LST(s) = (e^(-as) - e^(-(b+1)s)) / ((b-a+1)(1 - e^(-s)))
53
54 a = self.getParam(1).paramValue;
55 b = self.getParam(2).paramValue;
56
57 if abs(s) < 1e-10
58 % Handle s ≈ 0 case to avoid division by zero
59 L = 1.0;
60 else
61 e_neg_s = exp(-s);
62 numerator = exp(-a * s) - exp(-(b + 1) * s);
63 denominator = (b - a + 1) * (1 - e_neg_s);
64 L = numerator / denominator;
65 end
66 end
67
68
69 function X = sample(self, n)
70 % X = SAMPLE(N)
71
72 % Get n samples from the distribution
73 if nargin<2 %~exist('n','var'),
74 n = 1;
75 end
76 minVal = self.getParam(1).paramValue;
77 maxVal = self.getParam(2).paramValue;
78 X = round(minVal + (maxVal-minVal)*rand(n,1));
79 end
80
81 function proc = getProcess(self)
82 % PROC = GETPROCESS()
83
84 % Get process representation for non-Markovian distribution
85 % Returns [mean, SCV] pair for use in network analysis
86 proc = [self.getMean(), self.getSCV()];
87 end
88 end
89
90end
91