Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 19: (Optional) Further Explorations

Welcome to the final chapter! This chapter provides a brief glimpse into several fascinating areas that build upon the foundations of probability we’ve established. These topics often form the basis for more advanced courses in statistics, machine learning, information theory, and quantitative finance.

We won’t delve into rigorous proofs or exhaustive detail, but rather aim to provide an intuitive understanding and demonstrate simple applications using Python. Consider this a launching point for your further learning.

We will touch upon:

Introduction to Information Theory

Information theory, pioneered by Claude Shannon, deals with quantifying information, data compression, and communication limits. Two fundamental concepts are entropy and Kullback-Leibler (KL) divergence.

Entropy

Entropy measures the average level of “information”, “surprise”, or “uncertainty” inherent in a random variable’s possible outcomes. For a discrete random variable XX with PMF p(x)p(x), the entropy H(X)H(X) is defined as:

H(X)=−∑xp(x)log⁡bp(x)H(X) = - \sum_{x} p(x) \log_b p(x)

The base bb of the logarithm determines the units (usually base 2 for bits, base ee for nats).

Example: Consider a fair six-sided die vs. a heavily weighted die where P(roll=1)=0.9 and P(roll=i)=0.02 for i=2..6. The fair die has higher entropy because the outcome is less predictable.

Let’s compare the entropy of English text (where ‘e’ is common, ‘z’ is rare) to random characters (where all letters are equally likely). English text will have lower entropy because the letter frequencies are uneven, making it more predictable than random characters.

Entropy of fair die: 2.5850 bits
Entropy of biased die: 2.1610 bits

Kullback-Leibler (KL) Divergence

KL divergence measures how one probability distribution PP diverges from a second, expected probability distribution QQ. It’s often interpreted as the information gain achieved when switching from a prior distribution QQ to a posterior distribution PP.

For discrete distributions PP and QQ defined on the same sample space, the KL divergence from QQ to PP is:

DKL(P∣∣Q)=∑xP(x)log⁡bP(x)Q(x)D_{KL}(P || Q) = \sum_{x} P(x) \log_b \frac{P(x)}{Q(x)}

Key properties:

Example: How much information is lost if we model the biased die using the distribution of a fair die?

KL Divergence D_KL(Biased || Fair): 0.4240 bits
KL Divergence D_KL(Fair || Biased): 0.3500 bits

Introduction to Stochastic Processes

A stochastic process is a collection of random variables, typically indexed by time, {X(t)∣t∈T}\{X(t) | t \in T\}. It describes systems that evolve randomly.

Poisson Process

A Poisson process counts the number of events occurring in a given time interval. It’s characterized by a constant average rate λ\lambda (events per unit time).

Key properties:

  1. The number of events in any interval of length tt follows a Poisson distribution with mean λt\lambda t.

  2. The numbers of events in disjoint time intervals are independent.

  3. The time between consecutive events follows an Exponential distribution with rate λ\lambda (mean 1/λ1/\lambda).

Example: Modeling the arrival of customers at a store, radioactive decay events, or receiving emails, assuming the average rate is constant and events are independent.

Let’s simulate the arrival times of events in a Poisson process.

<Figure size 1000x200 with 1 Axes>
Number of events simulated in 10 time units: 22

Brownian Motion

Brownian motion (or Wiener process) W(t)W(t) models the random movement of particles suspended in a fluid, or more generally, phenomena exhibiting continuous random fluctuations.

Key properties (Standard Brownian Motion):

  1. W(0)=0W(0) = 0.

  2. Independent Increments: For any 0≤s<t<u<v0 \le s < t < u < v, the increments W(t)−W(s)W(t) - W(s) and W(v)−W(u)W(v) - W(u) are independent random variables.

  3. Normal Increments: For any 0≤s<t0 \le s < t, the increment W(t)−W(s)W(t) - W(s) is normally distributed with mean 0 and variance t−st - s. W(t)∼N(0,t)W(t) \sim \mathcal{N}(0, t).

  4. Continuous Paths: The function W(t)W(t) is continuous in tt.

Geometric Brownian Motion (GBM): Often used in finance to model stock prices. A process S(t)S(t) follows GBM if it satisfies the stochastic differential equation:

dS(t)=μS(t)dt+σS(t)dW(t)dS(t) = \mu S(t) dt + \sigma S(t) dW(t)

where μ\mu is the drift (average rate of return), σ\sigma is the volatility (standard deviation of returns), and dW(t)dW(t) is the increment of a Wiener process.

The solution can be written as:

S(t)=S(0)exp⁡((μ−σ22)t+σW(t))S(t) = S(0) \exp\left( (\mu - \frac{\sigma^2}{2})t + \sigma W(t) \right)

Example: Simulating a simple stock price path using GBM.

<Figure size 1000x600 with 1 Axes>

Generating Functions

Generating functions are powerful tools in probability and combinatorics. They encode the sequence of probabilities of a distribution into a single function. Derivatives and manipulations of this function can reveal properties like moments (mean, variance) and the distribution of sums of independent random variables.

Probability Generating Functions (PGFs)

Used for non-negative integer-valued discrete random variables XX (like Poisson, Binomial, Geometric). The PGF is defined as:

GX(z)=E[zX]=∑k=0∞P(X=k)zkG_X(z) = E[z^X] = \sum_{k=0}^{\infty} P(X=k) z^k

Properties:

Moment Generating Functions (MGFs)

Applicable to both discrete and continuous random variables. The MGF is defined as:

MX(t)=E[etX]M_X(t) = E[e^{tX}]

For discrete XX: MX(t)=∑xetxP(X=x)M_X(t) = \sum_x e^{tx} P(X=x) For continuous XX: MX(t)=∫−∞∞etxfX(x)dxM_X(t) = \int_{-\infty}^{\infty} e^{tx} f_X(x) dx

Properties:

Example: The MGF of a Normal distribution X∼N(μ,σ2)X \sim \mathcal{N}(\mu, \sigma^2) is MX(t)=exp⁡(μt+12σ2t2)M_X(t) = \exp(\mu t + \frac{1}{2} \sigma^2 t^2). Let’s verify the mean and variance using derivatives:

While calculating MGFs often involves calculus, some libraries like scipy.stats internally use properties derived from them to provide moments.

Using scipy.stats for N(mu=5, sigma=2):
  Mean (E[X]): 5.0000 (Theoretical: 5)
  Variance (Var(X)): 4.0000 (Theoretical: 4)
  E[X^2]: 29.0000 (Theoretical: 29)

Chapter Summary

This chapter offered a brief introduction to several advanced probability topics:

These areas represent vast fields of study. Hopefully, this glimpse has piqued your interest and demonstrated how the fundamental concepts learned throughout this book serve as stepping stones to more complex and powerful probabilistic modeling techniques.