1classdef Geometric < DiscreteDistribution
2 % A Geometric probability distribution
4 % The distribution of
the number of Bernoulli trials needed to get
7 % Copyright (c) 2018-2022, Imperial College London
11 function self = Geometric(p)
13 self@DiscreteDistribution(
'Geometric',1,[1,Inf]);
14 % Construct a geometric distribution with probability p
16 setParam(self, 1,
'p', p);
19 function ex = getMean(self)
22 % Get distribution mean
23 p = self.getParam(1).paramValue;
28 function SCV = getSCV(self)
31 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
32 p = self.getParam(1).paramValue;
37 function X = sample(self, n)
42 % Get n samples from
the distribution
43 p = self.getParam(1).paramValue;
46 % Degenerate
case:
the first trial always succeeds. The
47 % inversion below cannot express it, because log(1-p)
is -Inf
48 % and
the quotient rounds to 0, outside
the declared support
49 % {1,2,...}. The draws above are still consumed so a parameter
50 % sweep stays stream-
synchronized.
54 X = ceil(log(1-r) ./ log(1-p));
57 function Ft = evalCDF(self,k)
58 % FT = EVALCDF(SELF,K)
60 % Evaluate
the cumulative distribution function at t
63 p = self.getParam(1).paramValue;
67 function L = evalLST(self, s)
69 % Evaluate
the Laplace-Stieltjes transform of
the distribution function at s
70 % For Geometric(p), LST(s) = p*e^(-s) / (1 - (1-p)*e^(-s))
72 p = self.getParam(1).paramValue;
74 L = (p * e_neg_s) / (1 - (1 - p) * e_neg_s);
77 function pr = evalPMF(self, k)
80 % Evaluate
the probability mass function at k
83 p = self.getParam(1).paramValue;
84 % The support
is {1,2,...} (
the trial index of
the first success), so
85 %
the mass vanishes below it. Without
this the formula continues
86 % analytically to k=0 and returns p/(1-p), which
is not a probability.
94 function proc = getProcess(self)
97 % Get process representation
for non-Markovian distribution
98 % Returns [mean, SCV] pair
for use in network analysis
99 proc = [self.getMean(), self.getSCV()];