1classdef Binomial < DiscreteDistribution
2 % A Binomial distribution
4 % Copyright (c) 2018-2022, Imperial College London
8 function self = Binomial(n, p)
9 % SELF = BINOMIAL(N,
P)
11 self@DiscreteDistribution(
'Binomial',2,[0,Inf]);
12 setParam(self, 1,
'n', n);
13 setParam(self, 2,
'p', p);
16 function ex = getMean(self)
19 % Get distribution mean
20 n = self.getParam(1).paramValue;
21 p = self.getParam(2).paramValue;
25 function V = getVar(self)
27 n = self.getParam(1).paramValue;
28 p = self.getParam(2).paramValue;
32 function SCV = getSCV(self)
35 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
36 p = self.getParam(2).paramValue;
37 n = self.getParam(1).paramValue;
41 function X = sample(self, nsamples)
44 X = zeros(1, nsamples);
45 p = self.getParam(2).paramValue;
46 n = self.getParam(1).paramValue;
59 function Ft = evalCDF(self,t)
60 % FT = EVALCDF(SELF,T)
62 % Evaluate the cumulative distribution function at T
64 p = self.getParam(2).paramValue;
65 n = self.getParam(1).paramValue;
70 Ft = 1.0 - betainc(p, t + 1.0, n - t);
74 function L = evalLST(self, s)
76 % Evaluate the Laplace-Stieltjes transform of the distribution function at s
77 % For Binomial(n, p), LST(s) = (1 - p + p*e^(-s))^n
79 p = self.getParam(2).paramValue;
80 n = self.getParam(1).paramValue;
81 L = (1 - p + p * exp(-s))^n;
84 function
P = evalPMF(self, k)
87 % Evaluate the probability mass function at k
89 p = self.getParam(2).paramValue;
90 n = self.getParam(1).paramValue;
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()];