Contents
Deep Breakdown
What it tells me (Situation Awareness): The chain rule decomposes the joint probability of two events into a product of a marginal and a conditional. It generalizes to events: . Fundamental to Bayesian networks, language models, and Hidden Markov Models.
Flowchart
Real-world use
Where it is used
Bayesian inference: computing likelihoods. Language models: . Naive Bayes: factoring .
Problem it solves
How do I compute or factorize the joint probability of multiple events without knowing the full joint distribution?
How it solves the problem
Rewrites the joint as a product of simpler, estimable terms — a marginal and a conditional — which are often easier to compute or estimate from data.
Example in a business
Customer journey: . Used to decompose funnel conversion rates into conditional step probabilities.
The formula, piece by piece
- : joint probability of both events.
- : conditional probability (how likely is given ).
- : marginal probability of .
- Equivalent form: (symmetric).
The formula in words
"The joint probability of A and B equals the probability of B times the probability of A given B."
Critical Concepts
- This is exact, not an approximation (unlike Naive Bayes which assumes independence).
- Generalizes: .
- Basis of Bayes' theorem: .
- Rearranging: — back to conditional probability definition.
Step-by-step calculation (tiny example)
Step 1: Known rates P(add to cart) = 0.30. P(purchase | cart) = 0.40.
Step 2: Chain rule
Step 3: Interpret 12% of all visitors both add to cart AND purchase.
Code examples
Beginner example (Python)
# Funnel decomposition via chain rule
p_cart = 0.30 # P(add to cart)
p_purchase_given_cart = 0.40 # P(purchase | cart)
p_purchase_and_cart = p_purchase_given_cart * p_cart
print(f"P(cart ∩ purchase) = {p_purchase_and_cart:.2f}") # 0.12Beginner example (R)
p_cart <- 0.30
p_purchase_given_cart <- 0.40
p_purchase_and_cart <- p_purchase_given_cart * p_cart
cat("P(cart ∩ purchase) =", p_purchase_and_cart, "\n") # 0.12Professional example (Python)
import numpy as np
from typing import Sequence
def chain_rule_decomposition( conditional_probs: Sequence[float], marginal_first: float ) -> float:
"""Compute joint probability via chain rule for sequential events. P(A1 ∩ ... ∩ An) = P(A1) * P(A2|A1) * P(A3|A1,A2) * ... Args: conditional_probs: P(Ak | A1,...,A_{k-1}) for k=2,...,n. marginal_first: P(A1), probability of first event. Returns: Joint probability of all events in sequence. """
joint = marginal_first
for cond_prob in conditional_probs:
joint *= cond_prob
return joint # E-commerce funnel analysis
funnel_steps = [ ("Session start", 1.00), ("P(browse | start)", 0.75), ("P(add_to_cart | browse)", 0.30), ("P(checkout | cart)", 0.55), ("P(purchase | checkout)", 0.80),
]
cumulative = 1.0
print("Funnel cumulative probabilities:")
for step_name, step_rate in funnel_steps:
cumulative *= step_rate
print(f" {step_name:<35} {cumulative:.4f} ({cumulative*100:.2f}%)")Source: AIO p. 84