1classdef Bernoulli < DiscreteDistribution
2 % Bernoulli Binary outcome distribution
for success/failure modeling
4 % Bernoulli represents a Bernoulli distribution with probability parameter p.
5 % This
is the simplest discrete distribution, modeling a single trial with
6 % two possible outcomes: success (1) with probability p, and failure (0)
7 % with probability 1-p. It forms the foundation for binomial distributions.
9 % @brief Bernoulli distribution for binary success/failure outcomes
11 % Key characteristics:
12 % - Single parameter: success probability p ∈ [0,1]
13 % - Mean = p, Variance = p(1-p)
16 % - Building block
for binomial and geometric distributions
18 % The Bernoulli distribution
is used
for:
19 % - Modeling binary outcomes (success/failure, yes/no)
20 % - Cache hit/miss modeling
21 % - Component reliability analysis
22 % - Binary decision processes
23 % - Foundation
for more complex discrete distributions
27 % coin_flip = Bernoulli(0.5); % Fair coin (50% success)
28 % biased_coin = Bernoulli(0.7); % Biased coin (70% success)
29 % samples = coin_flip.sample(1000);
32 % Copyright (c) 2018-2022, Imperial College London
33 % All rights reserved.
36 function self = Bernoulli(p)
37 % BERNOULLI Create a Bernoulli distribution instance
39 % @brief Creates a Bernoulli distribution with success probability p
40 % @param p Success probability (must be in [0,1])
41 % @return self Bernoulli distribution instance
43 self@DiscreteDistribution('Bernoulli',1,[0,Inf]);
44 setParam(self, 1,
'p', p);
47 function ex = getMean(self)
50 % Get distribution mean
52 p = self.getParam(1).paramValue;
56 function V = getVar(self)
59 p = self.getParam(1).paramValue;
63 function SCV = getSCV(self)
66 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
67 p = self.getParam(1).paramValue;
72 function X = sample(self, nsamples)
75 X = zeros(1, nsamples);
76 p = self.getParam(1).paramValue;
90 function Ft = evalCDF(self,t)
91 % FT = EVALCDF(SELF,T)
93 % Evaluate the cumulative distribution function at T
95 p = self.getParam(1).paramValue;
101 Ft = 1.0 - betainc(p, t + 1.0, n - t);
105 function L = evalLST(self, s)
107 % Evaluate the Laplace-Stieltjes transform of the distribution function at s
108 % For Bernoulli(p), LST(s) = (1 - p + p*e^(-s))
110 p = self.getParam(1).paramValue;
111 L = 1 - p + p * exp(-s);
114 function
P = evalPMF(self, k)
117 % Evaluate the probability mass function at k
119 p = self.getParam(1).paramValue;
121 P = binopdf(k, n, p);
124 function proc = getProcess(self)
125 % PROC = GETPROCESS()
127 % Get process representation for non-Markovian distribution
128 % Returns [mean, SCV] pair for use in network analysis
129 proc = [self.getMean(), self.getSCV()];