LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Geometric.m
1classdef Geometric < DiscreteDistribution
2 % A Geometric probability distribution
3 %
4 % The distribution of the number of Bernoulli trials needed to get
5 % one success.
6 %
7 % Copyright (c) 2018-2022, Imperial College London
8 % All rights reserved.
9
10 methods
11 function self = Geometric(p)
12 % SELF = GEOMETRIC(P)
13 self@DiscreteDistribution('Geometric',1,[1,Inf]);
14 % Construct a geometric distribution with probability p
15
16 setParam(self, 1, 'p', p);
17 end
18
19 function ex = getMean(self)
20 % EX = GETMEAN()
21
22 % Get distribution mean
23 p = self.getParam(1).paramValue;
24
25 ex = 1 / p;
26 end
27
28 function SCV = getSCV(self)
29 % SCV = GETSCV()
30
31 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
32 p = self.getParam(1).paramValue;
33
34 SCV = 1 - p;
35 end
36
37 function X = sample(self, n)
38 % X = SAMPLE(N)
39 if nargin < 2
40 n = 1;
41 end
42 % Get n samples from the distribution
43 p = self.getParam(1).paramValue;
44 r = rand(n,1);
45 X = ceil(log(1-r) ./ log(1-p));
46 end
47
48 function Ft = evalCDF(self,k)
49 % FT = EVALCDF(SELF,K)
50
51 % Evaluate the cumulative distribution function at t
52 % AT T
53
54 p = self.getParam(1).paramValue;
55 Ft = 1 - (1-p)^k;
56 end
57
58 function L = evalLST(self, s)
59 % L = EVALST(S)
60 % Evaluate the Laplace-Stieltjes transform of the distribution function at s
61 % For Geometric(p), LST(s) = p*e^(-s) / (1 - (1-p)*e^(-s))
62
63 p = self.getParam(1).paramValue;
64 e_neg_s = exp(-s);
65 L = (p * e_neg_s) / (1 - (1 - p) * e_neg_s);
66 end
67
68 function pr = evalPMF(self, k)
69 % PR = EVALPMF(K)
70
71 % Evaluate the probability mass function at k
72 % AT K
73
74 p = self.getParam(1).paramValue;
75 pr = (1-p)^(k-1)*p;
76 end
77
78 function proc = getProcess(self)
79 % PROC = GETPROCESS()
80
81 % Get process representation for non-Markovian distribution
82 % Returns [mean, SCV] pair for use in network analysis
83 proc = [self.getMean(), self.getSCV()];
84 end
85 end
86
87end
88