BRAGA

02 Writing02-02 Notes02-02-375

Chain Rule Product Rule

Published 16 Apr 20263 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
P(A∩B)=P(A∣B)P(B)=P(B∣A)P(A)P(A \cap B) = P(A \mid B)P(B) = P(B \mid A)P(A)
(1)

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 nn events: P(A1∩…∩An)=P(A1)⋅P(A2∣A1)⋯P(An∣A1,…,An−1)P(A_1 \cap \ldots \cap A_n) = P(A_1) \cdot P(A_2 \mid A_1) \cdots P(A_n \mid A_1, \ldots, A_{n-1}). Fundamental to Bayesian networks, language models, and Hidden Markov Models.

Flowchart

Joint P(A∩B)Factor 1: P(B) =marginalFactor 2: P(A|B)= conditionalP(A∩B) = P(A|B)* P(B)Generalize:P(A1∩...∩An) =product ofconditionals

Real-world use

Where it is used

Bayesian inference: computing likelihoods. Language models: P(w1,w2,…,wn)=∏P(wi∣w1,…,wi−1)P(w_1, w_2, \ldots, w_n) = \prod P(w_i \mid w_1, \ldots, w_{i-1}). Naive Bayes: factoring P(features∣class)P(\text{features} \mid \text{class}).

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: P(purchase∩cart)=P(purchase∣cart)×P(cart)P(\text{purchase} \cap \text{cart}) = P(\text{purchase} \mid \text{cart}) \times P(\text{cart}). Used to decompose funnel conversion rates into conditional step probabilities.

The formula, piece by piece

P(A∩B)=P(A∣B)⋅P(B)P(A \cap B) = P(A \mid B) \cdot P(B)

  • P(A∩B)P(A \cap B): joint probability of both events.
  • P(A∣B)P(A \mid B): conditional probability (how likely AA is given BB).
  • P(B)P(B): marginal probability of BB.
  • Equivalent form: =P(B∣A)⋅P(A)= P(B \mid A) \cdot P(A) (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: P(A,B,C)=P(C∣A,B)P(B∣A)P(A)P(A,B,C) = P(C \mid A,B) P(B \mid A) P(A).
  • Basis of Bayes' theorem: P(A∣B)=P(B∣A)P(A)/P(B)P(A \mid B) = P(B \mid A) P(A) / P(B).
  • Rearranging: P(A∣B)=P(A∩B)/P(B)P(A \mid B) = P(A \cap B) / P(B) — 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 P(cart∩purchase)=P(purchase∣cart)×P(cart)P(\text{cart} \cap \text{purchase}) = P(\text{purchase} \mid \text{cart}) \times P(\text{cart}) =0.40×0.30=0.12= 0.40 \times 0.30 = 0.12

Step 3: Interpret 12% of all visitors both add to cart AND purchase.

Code examples

Beginner example (Python)

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.12

Beginner example (R)

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.12

Professional example (Python)

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

#probability-statistics#probability-theory#conditional-probability-and-independence

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close