Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Discriminant functions

Discriminant functions give a numerical score to inputs so we can decide class membership; common types are linear and quadratic discriminants, Fisher's LDA and the perceptron, all derived from likelihoods or geometrical criteria.

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

Discriminant functions are what an engineer implements when a machine must decide which class an input belongs to. You will use them in classification blocks (for example in biometric recognition, speech recognition, or image classifiers) where you need a decision rule that is efficient and can be analysed for error rates.

Key ideas

Start with the problem: we have an input (feature) vector x ∈ R^d and a finite set of classes {ω1, ω2, ... , ωc}. A classifier computes a real-valued discriminant function g_i(x) for each class ω_i and chooses the class with the largest value.

  • Discriminant function: A scalar function g_i(x) whose relative values across classes determine the chosen class. (Defined here.)
  • Decision surface / decision boundary: The set of x where g_i(x) = g_j(x) for some i ≠ j. This is the geometric boundary between class regions.
  • Bayes classifier: The classifier that chooses the class with maximum posterior probability P(ω_i | x). Posterior probability is defined by Bayes' rule: P(ω_i | x) = P(x | ω_i) P(ω_i) / P(x). Here P(x | ω_i) is the likelihood and P(ω_i) is the prior. With unequal misclassification costs λ_ij, the Bayes decision minimizes expected risk ∑_j λ_ij P(ω_j | x); for two classes this leads to the threshold ln P(x | ω_1) - ln P(x | ω_2) > ln(λ_12 P(ω_2)) - ln(λ_21 P(ω_1)).

From Bayes rule we can define the canonical discriminant: g_i(x) = ln P(x | ω_i) + ln P(ω_i). This choice prefers the class with largest posterior. Use logarithms to convert products into sums and for numerical stability.

Common models for the likelihood P(x | ω_i):

  • Multivariate normal (Gaussian) model: P(x | ω_i) = N(x; μ_i, Σ_i), where mean vector μ_i is the expected value E[x | ω_i] and covariance matrix Σ_i = E[(x - μ_i)(x - μ_i)^T | ω_i]. Both are defined here.

Important special cases and derivations universities expect:

  1. Linear discriminant from Gaussian likelihoods with equal covariances: assume P(x | ω_i) = N(x; μ_i, Σ) for all i with the same Σ. The log-likelihood term ln N becomes a quadratic form in x, but the quadratic parts cancel when you take differences g_i(x) - g_j(x), leaving a linear function in x. The decision boundary between i and j is a hyperplane.

    • Derivation (typical exam derivation): write ln N(x; μ_i, Σ) = -1/2 (x - μ_i)^T Σ^{-1} (x - μ_i) - (d/2) ln(2π) - 1/2 ln |Σ|. For equal Σ, the common constants drop and g_i(x) - g_j(x) reduces to w^T x + w0 where w = Σ^{-1}(μ_i - μ_j) and w0 = -1/2(μ_i^T Σ^{-1} μ_i - μ_j^T Σ^{-1} μ_j) + ln(P(ω_i)/P(ω_j)).
    • This is called a linear discriminant because the resulting classifier uses a linear function of x.
  2. Quadratic discriminant: if covariances Σ_i differ across classes, the log-likelihoods retain quadratic terms, so g_i(x) is a quadratic function of x and boundaries are quadratic surfaces (ellipses, hyperbolas, or parabolas in 2D). This is called Quadratic Discriminant Analysis (QDA).

  3. Fisher's linear discriminant (Fisher LDA): this is a projection method (not directly from likelihoods) that finds a projection direction w (a d-vector) that maximises class separability for two classes. Define the between-class scatter S_B = (m2 - m1)(m2 - m1)^T and the within-class scatter S_W = S_{W1} + S_{W2}, where S_{Wi} = Σ_{x in ω_i} (x - m_i)(x - m_i)^T. Fisher's criterion J(w) = (w^T S_B w) / (w^T S_W w). Maximising J(w) leads to the generalized eigenvector problem S_B w = λ S_W w. For two classes this reduces (up to scale) to w ∝ S_W^{-1} (m2 - m1). The projection is one-dimensional; after projecting training data you pick a threshold (typically mid-point of projected class means or chosen by minimising error).

  4. Perceptron: a simple iterative algorithm to learn a linear discriminant directly from data. The model uses a weight vector w and bias w0 and predicts sign(w^T x + w0). The perceptron update rule for a misclassified example (x, y) with y ∈ {+1, -1} is w ← w + η y x and w0 ← w0 + η y, where η > 0 is the learning rate. If data are linearly separable, the perceptron converges in finite steps (perceptron convergence theorem). Convergence proof requires separability and finite margin; details often asked in exams.

  5. Multiple classes: extend discriminants by one-vs-all linear functions, use argmax_i g_i(x) or use pairwise comparisons. For Gaussian models with equal Σ you get linear discriminant functions g_i(x) = w_i^T x + w_{i0} with w_i = Σ^{-1} μ_i and w_{i0} = -1/2 μ_i^T Σ^{-1} μ_i + ln P(ω_i) (constant common term can be dropped when taking argmax).

Diagrams to draw in answers:

  • For the equal-covariance Gaussian case draw two Gaussian contour ellipses with same shape but different centers; draw the linear decision boundary (straight line) with normal vector w ∝ Σ^{-1}(μ2 - μ1) (it is perpendicular to μ1 - μ2 only if Σ ∝ I), and place sample points.
  • For Fisher LDA draw two 2D clusters, the projection line w, projected points on a 1D axis and the threshold between class projections.

Assumptions to state in proofs/derivations: clearly state when you assume equal covariances, Gaussian class-conditional densities, linear separability for perceptron convergence, or i.i.d. samples for scatter estimates.

Formulas

g_i(x) = ln P(x | ω_i) + ln P(ω_i) — g_i(x) is the discriminant; P(x | ω_i) is the likelihood; P(ω_i) is the prior. (unitless; applies generally)

P(x | ω_i) = (1 / ((2π)^{d/2} |Σ_i|^{1/2})) · exp(-1/2 (x - μ_i)^T Σ_i^{-1} (x - μ_i)) — multivariate normal density; μ_i is mean vector (units of x), Σ_i is covariance matrix (units of x^2), |Σ_i| is determinant.

g_i(x) - g_j(x) = (μ_i - μ_j)^T Σ^{-1} x + [ -1/2 (μ_i^T Σ^{-1} μ_i - μ_j^T Σ^{-1} μ_j) + ln(P(ω_i)/P(ω_j)) ] — when Σ_i = Σ_j = Σ; w = Σ^{-1}(μ_i - μ_j), w0 as bracketed term. (unitless)

w = Σ^{-1} (μ_i - μ_j) — weight vector for linear discriminant (units: 1/unit of x)

w0 = -1/2 (μ_i^T Σ^{-1} μ_i - μ_j^T Σ^{-1} μ_j) + ln(P(ω_i)/P(ω_j)) — bias term (unitless)

Decision: choose ω_i if g_i(x) > g_j(x) for all j ≠ i — definition of argmax decision rule.

J(w) = (w^T S_B w) / (w^T S_W w) — Fisher criterion; S_B and S_W are scatter matrices (units: x^2).

w ∝ S_W^{-1} (m_2 - m_1) — Fisher LDA solution for two classes (direction only; scale does not matter).

Perceptron update: w ← w + η y x, w0 ← w0 + η y — for misclassified example (x,y), η > 0 learning rate (unitless).

Worked examples

Example 1 — Linear discriminant from equal-covariance Gaussians (numerical). Given d = 2. Class ω1: μ1 = [1, 2]^T. Class ω2: μ2 = [3, 4]^T. Covariance Σ = [[1, 0.2], [0.2, 1]]. Priors P(ω1) = P(ω2) = 0.5. Steps:

  1. Compute Σ^{-1}. For Σ = [[1, 0.2], [0.2, 1]] the determinant det Σ = 1 - 0.04 = 0.96. Then Σ^{-1} = (1/det) · [[1, -0.2], [-0.2, 1]] = [[1.0416667, -0.2083333], [-0.2083333, 1.0416667]].
  2. Compute w = Σ^{-1} (μ1 - μ2). μ1 - μ2 = [-2, -2]^T. w ≈ [[1.0416667, -0.2083333], [-0.2083333, 1.0416667]] · [-2, -2]^T = [-1.6666668, -1.6666668]^T.
  3. Compute w0 = -1/2 (μ1^T Σ^{-1} μ1 - μ2^T Σ^{-1} μ2) + ln(0.5/0.5). Compute Σ^{-1} μ1 ≈ [0.62501, 1.87501]^T so μ1^T Σ^{-1} μ1 ≈ 4.37503. Compute Σ^{-1} μ2 ≈ [2.29169, 3.54169]^T so μ2^T Σ^{-1} μ2 ≈ 21.04183. Thus w0 ≈ -0.5 (4.37503 - 21.04183) = 8.3334.
  4. The discriminant g(x) = w^T x + w0. Decision: choose ω1 if g(x) > 0.
  5. Test point x = [2, 3]^T (midpoint between means): g(x) ≈ (-1.66672) + (-1.66673) + 8.3334 ≈ 0 (so borderline). Test x = [2, 0]^T: g ≈ -3.3334 + 0 + 8.3334 = 5.0 so classify as ω1 (bold final answer).

Final decision rule (explicit linear equation): -1.6667 x1 -1.6667 x2 + 8.3334 > 0 ⇒ ω1. (Values rounded.)

Example 2 — Fisher LDA with small 2D dataset (numerical, model-answer style). Data: ω1 points: (1,2), (2,1), (2,2). ω2 points: (4,5), (5,4), (5,5). Steps:

  1. Compute class means: m1 = (1.6667, 1.6667), m2 = (4.6667, 4.6667).
  2. Compute within-class scatter S_W = Σ_{i∈ω1} (x - m1)(x - m1)^T + Σ_{i∈ω2} (x - m2)(x - m2)^T. After computing each outer product and summing we obtain S_W ≈ [[1.3332, -0.6666], [-0.6666, 1.3332]].
  3. Compute direction w ∝ S_W^{-1} (m2 - m1). Here m2 - m1 = (3, 3). Compute S_W^{-1} (approx) and multiply: w ≈ [4.503, 4.503], which is parallel to vector (1,1). So a convenient scaled choice is w = (1, 1)^T.
  4. Project points: for w = (1,1), projected values are sums of coordinates. Projected mean m1_proj ≈ 3.333, m2_proj ≈ 9.333. Choose threshold mid-point ≈ 6.333 or choose threshold to minimise classification errors on training data.
  5. Classification: a new x is classified by comparing w^T x to threshold 6.333. For example x = (3,3) → w^T x = 6 < 6.333 ⇒ classify as ω1.

Bold result: projection direction w ~ (1,1) and threshold ~ 6.333 classifies given points correctly.

Common mistakes

  • Confusing Fisher LDA (a projection-based method) with the Bayes linear discriminant (derived from Gaussian likelihoods with equal covariances). Both give linear boundaries but arise from different objectives.
  • Using sample covariance without subtracting the mean (i.e., forgetting x - m in scatter computations).
  • Not normalising projection directions when interpreting magnitudes; Fisher's w is only defined up to scale.
  • For perceptron: not converting class labels to +1 and -1 and applying update formula accordingly.

For your exam

Types of questions you will see:

  • Definitions: define discriminant function, decision surface, Bayes classifier, Fisher criterion.
  • Derivations: derive the linear discriminant from Gaussian likelihoods with equal covariances; derive Fisher's w ∝ S_W^{-1}(m2 - m1).
  • Numericals: compute w and w0 for a given 2D Gaussian example (like Example 1). Show matrix inverses and compute boundary line.
  • Short notes: explain differences between LDA and QDA; when to prefer each.
  • Diagrams: draw two Gaussian clusters and show linear or quadratic boundary.

What full-marks answers include:

  • Clear statement of assumptions.
  • Step-by-step algebra with intermediate results (matrix inverse, vector products).
  • Correctly labelled diagram if asked (axes, means, decision boundary, sample points).
  • Final numeric answers with correct rounding and units (usually unitless for discriminant scores).

Quick check

  1. What is the discriminant function you use to implement the Bayes classifier?
  2. Under what condition on class covariances does the Gaussian Bayes classifier give linear boundaries?
  3. Give the Fisher LDA direction for two classes in terms of scatter matrices. Answers: 1) g_i(x) = ln P(x | ω_i) + ln P(ω_i). 2) When all classes share the same covariance matrix Σ (Σ_i = Σ). 3) w ∝ S_W^{-1} (m2 - m1).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?