PMF and PDF

Probability Mass Function (PMF) and Probability Density Function (PDF) are tools to model the probabilities of random variables. The PMF is used for discrete random variables and the PDF is used for continuous random variables.

Bernoulli Distribution

Bernoulli distribution is used to model random variables which can have 2 outcomes. The most famous random variable with this distribution is the tossing of a coin which can only have two outcomes, head or tail. Mathematically, this distribution is \( \rm{Bernoulli}(X = x) = p^{x} (1 - p)^{1-x} \) where \(p\) is the probability of success.

For example, for a fair coin the probability of heads and tails is equal therefore, \(p=1/2\) and the PMF is: \( \rm{Bernoulli}(\text{tossing a fair coin} = x) = (\frac{1}{2})^{x} (\frac{1}{2})^{1-x} = \frac{1}{2} \) In python, we can use scipy.stats to get PMF or simulate data for various probability distributions.


import numpy as np

from scipy.stats import bernoulli



# simulate 10 trails of tossing a fair coin

np.random.seed(123)

fair_coin_simulation = bernoulli.rvs(p=0.5, size=10)

fair_coin_simulation

# array([1, 0, 0, 1, 1, 0, 1, 1, 0, 0])



# find pmf value of tossing a fair coin

bernoulli.pmf(1, p=0.5)

# 0.5