Bayesian decision theory
Bayesian decision theory gives a principled way to choose class labels by combining prior probabilities and class-conditional evidence (likelihood) to minimize expected loss (Bayes risk).
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Bayesian decision theory is used when an engineer must make decisions under uncertainty: e.g., classifying sensor readings, making biometric accept/reject decisions, or combining model outputs. It tells you how to use prior knowledge and measured evidence to make optimal decisions that minimize expected loss.
Key ideas
Class-conditional density / Likelihood p(x | ω_i): the probability density of observing feature vector x given that the true class is ω_i. For continuous x, this has units 1/(units of x) so that p(x|ω_i) dx is dimensionless.
Posterior probability P(ω_i | x): the probability that the true class is ω_i after observing x. Found by Bayes' rule. It is dimensionless.
Bayes' rule: how to update a prior with evidence (likelihood) to get a posterior. Assumes probabilities are known or estimated.
Loss function λ(α_j | ω_i): the penalty (cost) for taking action α_j when the true class is ω_i. Common simple case is 0–1 loss: 0 for correct decision and 1 for error.
Bayes risk: the expected loss using a decision rule. The optimal decision rule minimizes Bayes risk.
Bayes decision rule (general): choose the action α_j that minimizes conditional risk R(α_j | x) = Σ_i λ(α_j | ω_i) P(ω_i | x). This is a local (for each x) minimization.
Derivation (common exam-style):
- Total expected risk (Bayes risk) = ∫ R(δ(x) | x) p(x) dx where δ(x) is the decision rule. To minimize the integral for all x, minimize the integrand R(α_j | x) for each x.
- Therefore, for each x, pick the action α_j that minimizes R(α_j | x) = Σ_i λ(α_j | ω_i) P(ω_i | x).
MAP rule / Minimum error rule (0–1 loss): under 0–1 loss (λ(α_j|ω_i)=0 if j=i, =1 otherwise), conditional risk R(α_j|x)=1-P(ω_j|x). Minimizing this means pick the class with largest posterior. So the MAP (maximum a posteriori) decision: choose class with maximum P(ω_i | x).
Likelihood ratio test (two-class case): For two classes ω_1, ω_2 with actions decide ω_1 or ω_2, and 0–1 loss, decide ω_1 if p(x|ω_1) / p(x|ω_2) > P(ω_2) / P(ω_1). This compares likelihood ratio to prior odds. More generally, with losses λ(α_j | ω_i), decide ω_1 if p(x|ω_1)/p(x|ω_2) > ((λ(α_1 | ω_2) − λ(α_2 | ω_2)) / (λ(α_2 | ω_1) − λ(α_1 | ω_1))) · P(ω_2)/P(ω_1); when λ(α_i | ω_i)=0 and misclassification losses are λ(α_1|ω_2), λ(α_2|ω_1), the threshold becomes (λ(α_1|ω_2)/λ(α_2|ω_1)) · P(ω_2)/P(ω_1).
Draw a diagram (exam): draw one horizontal axis labelled x (feature value). Sketch two Gaussian curves p(x|ω_1) and p(x|ω_2) with peaks at μ1 and μ2. Mark the decision threshold x0 where p(x|ω_1)P(ω_1)=p(x|ω_2)P(ω_2). Label regions assigned to ω_1 and ω_2.
Discriminant functions: Instead of computing posteriors directly, define g_i(x) such that choose class i with largest g_i(x). For MAP with continuous densities, a convenient choice is g_i(x) = ln p(x | ω_i) + ln P(ω_i). Log helps numeric stability and turns products into sums.
Gaussian class-conditional model: If p(x|ω_i) is multivariate normal N(μ_i, Σ_i), then the discriminant becomes quadratic in x. If all classes share the same covariance Σ, decision boundaries are linear (Linear Discriminant Analysis, LDA). If covariances differ, boundaries are quadratic (Quadratic Discriminant Analysis, QDA).
Derivation sketch (common exam): write p(x|ω_i) then take logarithm and drop constant terms common to all classes; obtain g_i(x) = -0.5 ln|Σ_i| - 0.5 (x-μ_i)^T Σ_i^{-1} (x-μ_i) + ln P(ω_i). For equal Σ, terms quadratic in x cancel between classes and you get a linear function in x.
Assumptions to state in answers: known priors and class-conditionals (or good estimates), loss function specified, independence of training/test conditions if using estimated parameters, Gaussian assumptions only when you model p(x|ω_i) as Gaussian.
Formulas
P(ω_i | x) = p(x | ω_i) P(ω_i) / p(x) — Bayes' rule. p(x) = Σ_k p(x | ω_k) P(ω_k). P(ω_i | x) dimensionless. Applies when p(x|ω_i) and P(ω_i) known or estimated.
R(α_j | x) = Σ_i λ(α_j | ω_i) P(ω_i | x) — conditional risk given x. Units: same as loss (dimensionless or currency). Use to choose best action at x.
Choose α_j* = argmin_j R(α_j | x) — Bayes decision rule.
For 0–1 loss: choose ω_i with largest P(ω_i | x) (MAP). — practical rule.
Minimum probability of error (0–1 loss): P_e = 1 − ∫ max_i p(x|ω_i) P(ω_i) dx = ∑_i ∫_{R_j, j≠i} p(x|ω_i) P(ω_i) dx. — Bayes error.
Two-class 1D (threshold t; decide ω_1 for x < t): P_e = P(ω_1)[1 − Φ((t − μ_1)/σ_1)] + P(ω_2) Φ((t − μ_2)/σ_2). — Φ is the standard normal CDF.
Likelihood ratio for two classes (0–1 loss): Λ(x) = p(x|ω_1) / p(x|ω_2). Decide ω_1 if Λ(x) > P(ω_2)/P(ω_1). — applied when two classes. General threshold with losses: decide ω_1 if Λ(x) > ((λ(α_1 | ω_2) − λ(α_2 | ω_2)) / (λ(α_2 | ω_1) − λ(α_1 | ω_1))) · P(ω_2)/P(ω_1), which reduces to (λ(α_1|ω_2)/λ(α_2|ω_1)) · P(ω_2)/P(ω_1) when λ(α_i | ω_i)=0.
Gaussian likelihood: p(x|ω_i) = (1 / ((2π)^{d/2} |Σ_i|^{1/2})) · exp(-0.5 (x-μ_i)^T Σ_i^{-1} (x-μ_i)) — units: 1/(units of x)^d. Applies when modeling with multivariate normal.
Discriminant (Gaussian): g_i(x) = -0.5 ln|Σ_i| - 0.5 (x-μ_i)^T Σ_i^{-1} (x-μ_i) + ln P(ω_i) — choose i with largest g_i(x).
If Σ_i = Σ for all i: g_i(x) = x^T Σ^{-1} μ_i - 0.5 μ_i^T Σ^{-1} μ_i + ln P(ω_i) — linear discriminant. Here Σ^{-1} μ_i is a weight vector.
Worked examples
Example 1 — numerical 1D, equal variances Problem: Two classes ω1, ω2. p(x|ω1) = N(0, 1), p(x|ω2) = N(2, 1). Priors: P(ω1)=0.6, P(ω2)=0.4. Decide threshold t so that for x < t choose ω1, else ω2. Steps:
- For equal σ^2, decision boundary t solves p(x|ω1) P1 = p(x|ω2) P2.
- For normal densities with same σ^2: boundary t = (μ1 + μ2)/2 + (σ^2/(μ2 - μ1)) ln(P1/P2).
- Substitute μ1=0, μ2=2, σ^2=1, P1=0.6, P2=0.4. Compute ln(P1/P2)=ln(1.5)=0.405465.
- t = (0+2)/2 + (1/2)*0.405465 = 1 + 0.2027325 = 1.2027325.
- Therefore classify: if x < 1.2027325 → ω1; if x ≥ 1.2027325 → ω2. Answer: Threshold t = 1.2027 (units of x).
Example 2 — model derivation (theory question) Question: Show that for multivariate Gaussian class-conditionals with common covariance Σ, the decision boundary is linear and give the weight vector and bias. Model answer (stepwise):
- Write discriminant for class i: g_i(x) = ln p(x|ω_i) + ln P(ω_i).
- Substitute Gaussian p(x|ω_i) and drop constant -d/2 ln(2π) common to all classes.
- g_i(x) = -0.5 ln|Σ| -0.5 (x-μ_i)^T Σ^{-1} (x-μ_i) + ln P(ω_i).
- For common Σ, -0.5 ln|Σ| is same for all i and can be dropped for comparing classes.
- Expand quadratic term: -0.5 x^T Σ^{-1} x + x^T Σ^{-1} μ_i - 0.5 μ_i^T Σ^{-1} μ_i.
- The -0.5 x^T Σ^{-1} x term is common to all i and cancels, leaving linear function in x: g_i(x) = x^T Σ^{-1} μ_i - 0.5 μ_i^T Σ^{-1} μ_i + ln P(ω_i).
- For two classes ω1, ω2, define w = Σ^{-1} (μ1 - μ2), w0 = -0.5(μ1^T Σ^{-1} μ1 - μ2^T Σ^{-1} μ2) + ln(P1/P2). Decision g1(x)-g2(x) = w^T x + w0; boundary is w^T x + w0 = 0 which is a hyperplane (linear).
- Hence LDA linear boundary and weight vector w as above.
Diagrams to draw: draw two ellipses (Gaussian contours) in 2D centered at μ1 and μ2 with same orientation/shape when Σ common, draw straight line (perpendicular to vector Σ^{-1}(μ1-μ2)) dividing classes, label μ1, μ2, indicate decision region signs.
Common mistakes
- Not taking log when multiplying small probabilities — may cause underflow; also missing that log turns product to sum which simplifies algebra.
- Dropping terms incorrectly: when comparing g_i(x) you may drop only terms common to all classes. Dropping class-dependent terms by mistake changes result.
- Assuming linear boundary when covariances differ — check Σ_i equality before claiming linear boundary.
- Sign errors in exponent when using Gaussian formula or in expansion of quadratic forms.
For your exam
Typical question types:
- Definitions: priors, likelihood, posterior, loss, Bayes risk. State definitions and units.
- Short derivations: derive MAP rule from minimizing conditional risk; show discriminant for Gaussian and linearization under equal covariances.
- Numericals: compute decision threshold for two Gaussian classes with given priors and variances; compute Bayes error for simple 1D cases.
- Diagrams: draw class-conditional densities and mark decision boundary; draw 2D Gaussian contours and linear/quadratic boundaries.
- Long theory: derive LDA weights, explain assumptions and limitations.
What a full-marks answer includes:
- Clear statement of assumptions (known priors, loss function, model for p(x|ω_i)).
- Correct formula derivations step-by-step with any terms dropped justified as common to all classes.
- If numerical, show substitution with units and final rounded numeric answer.
- For diagrams, label axes, means, covariance shape/contours, and decision boundary.
Quick check
- What is the MAP decision under 0–1 loss?
- Give the likelihood ratio test condition for two classes in terms of priors.
- When do Gaussian class-conditional models give linear decision boundaries? Answers: Choose class with largest posterior (MAP). Decide ω1 if p(x|ω1)/p(x|ω2) > P(ω2)/P(ω1). When all classes share the same covariance matrix Σ (common covariance).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?