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 if p >= 1
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.
51 X = ones(n,1);
52 return
53 end
54 X = ceil(log(1-r) ./ log(1-p));
55 end
56
57 function Ft = evalCDF(self,k)
58 % FT = EVALCDF(SELF,K)
59
60 % Evaluate the cumulative distribution function at t
61 % AT T
62
63 p = self.getParam(1).paramValue;
64 Ft = 1 - (1-p)^k;
65 end
66
67 function L = evalLST(self, s)
68 % L = EVALST(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))
71
72 p = self.getParam(1).paramValue;
73 e_neg_s = exp(-s);
74 L = (p * e_neg_s) / (1 - (1 - p) * e_neg_s);
75 end
76
77 function pr = evalPMF(self, k)
78 % PR = EVALPMF(K)
79
80 % Evaluate the probability mass function at k
81 % AT K
82
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.
87 if k < 1
88 pr = 0;
89 return
90 end
91 pr = (1-p)^(k-1)*p;
92 end
93
94 function proc = getProcess(self)
95 % PROC = GETPROCESS()
96
97 % Get process representation for non-Markovian distribution
98 % Returns [mean, SCV] pair for use in network analysis
99 proc = [self.getMean(), self.getSCV()];
100 end
101 end
102
103end
104
Definition Station.m:245