Tutorials › Multivariate Statistics (Graduate) › Gaussian Discriminant Scores From Log Densities

Discriminant Analysis Theory · Tutorial 581 of 975

Gaussian Discriminant Scores From Log Densities

Learn to expand Gaussian log-posterior scores, identify their class-specific terms, and use them to compare candidate classes.

Intermediate 9 min read

What You'll Learn

  • Write the Gaussian log density for a class with a positive-definite covariance matrix
  • Derive a discriminant score by removing terms common to every class
  • Identify the quadratic, linear, determinant, and prior-probability contributions
  • Compare class scores with complete calculations in one- and two-dimensional examples
  • Explain why maximizing a score gives the same decision as maximizing the posterior
  • Recognize errors caused by dropping class-dependent terms

From Gaussian Densities to Class Scores

A Gaussian classification rule compares how well each candidate class accounts for an observed vector. The density supplies a measure of fit, while the class prior probability accounts for how common the class is before seeing the observation. Taking logarithms turns the product of these quantities into a sum whose separate contributions are easier to inspect.

Suppose \(C\) takes values \(1,\ldots,K\), and the observed feature vector is \(x\in\mathbb{R}^p\). Assume the prior probabilities are \(\pi_k=P(C=k)>0\), with \(\sum_{k=1}^K\pi_k=1\), and that \(X\mid C=k\sim N_p(\mu_k,\Sigma_k)\). Each \(\mu_k\) is a \(p\)-vector and each \(\Sigma_k\) is a symmetric positive-definite \(p\times p\) matrix. Positive definiteness ensures that the Gaussian density exists, its determinant is positive, and its inverse is defined.

Definition: The Gaussian log-posterior score for class \(k\), up to a term common to all classes, is \(\delta_k(x)=\log\pi_k-\frac12\log|\Sigma_k|-\frac12(x-\mu_k)^\mathsf{T}\Sigma_k^{-1}(x-\mu_k)\). The three displayed contributions are the log prior, the covariance determinant term, and the negative one-half squared Mahalanobis distance from \(x\) to \(\mu_k\).

The full log of the joint class-and-observation density is \(\log\{\pi_k f_k(x)\}\), where \(f_k\) is the \(N_p(\mu_k,\Sigma_k)\) density. It includes the additional term \(-\frac p2\log(2\pi)\). Since the dimension \(p\) is the same for every class, that term does not affect which score is largest. The distinction between a full log joint density and the reduced score matters when interpreting values: reduced scores are useful for comparison, but are not themselves log posterior probabilities.

Deriving and Reading the Score

The multivariate normal density is \(f_k(x)=(2\pi)^{-p/2}|\Sigma_k|^{-1/2}\exp\{-\frac12(x-\mu_k)^\mathsf{T}\Sigma_k^{-1}(x-\mu_k)\}\). Taking its logarithm and adding the log prior gives

$$ \log\{\pi_k f_k(x)\} = -\frac p2\log(2\pi) +\log\pi_k -\frac12\log|\Sigma_k| -\frac12(x-\mu_k)^\mathsf{T}\Sigma_k^{-1}(x-\mu_k). $$

The quadratic form is nonnegative. It measures discrepancy from the class mean after adjusting for the covariance scale and correlation. A large value lowers the score. The determinant term comes from the density’s normalizing factor: a larger covariance determinant contributes a larger penalty, all else equal. The prior contributes \(\log\pi_k\), so a more probable class receives a higher score before the feature vector is considered.

The score can also be expanded as a polynomial in \(x\). Because \(\Sigma_k^{-1}\) is symmetric, \((x-\mu_k)^\mathsf{T}\Sigma_k^{-1}(x-\mu_k) =x^\mathsf{T}\Sigma_k^{-1}x-2x^\mathsf{T}\Sigma_k^{-1}\mu_k+\mu_k^\mathsf{T}\Sigma_k^{-1}\mu_k\). Substitution yields

$$ \delta_k(x) = -\frac12x^\mathsf{T}\Sigma_k^{-1}x +x^\mathsf{T}\Sigma_k^{-1}\mu_k -\frac12\mu_k^\mathsf{T}\Sigma_k^{-1}\mu_k -\frac12\log|\Sigma_k| +\log\pi_k. $$

This form makes the roles of the terms explicit. The first is quadratic in the observation, the second is linear in it, and the remaining terms are constant with respect to \(x\) for a fixed class. Across classes, however, those constants need not agree. In particular, neither the determinant nor the prior may be dropped merely because it does not vary with \(x\).

Theorem: Under the stated Gaussian model and positive class priors, assigning \(x\) to a class with the largest posterior probability is equivalent to assigning it to a class with the largest \(\delta_k(x)\). Ties give the same set of maximizing classes under either comparison.

Proof. By Bayes’ rule, for each class \(k\), \(P(C=k\mid X=x)=\pi_k f_k(x)\big/\sum_{j=1}^K\pi_j f_j(x)\). The denominator is positive and does not depend on \(k\), so it cannot change the maximizing class. The logarithm is strictly increasing, hence maximizing the posterior is equivalent to maximizing \(\log\{\pi_k f_k(x)\}\). From the density expansion, this log joint density equals \(\delta_k(x)-\frac p2\log(2\pi)\). The subtracted term is also independent of \(k\), proving the claim. \(\square\)

Worked Example: Comparing Two Classes in Two Dimensions

Let the priors be \(\pi_1=0.6\) and \(\pi_2=0.4\). Suppose \(\mu_1=(0,0)^\mathsf{T}\), \(\Sigma_1=\begin{pmatrix}1&0\\0&4\end{pmatrix}\), \(\mu_2=(2,0)^\mathsf{T}\), and \(\Sigma_2=\begin{pmatrix}4&0\\0&1\end{pmatrix}\). For \(x=(0,1)^\mathsf{T}\), calculate the reduced scores.

Both determinants equal \(4\), so both determinant contributions are \(-\frac12\log 4=-\log 2\). For class 1, \(x-\mu_1=(0,1)^\mathsf{T}\) and \(\Sigma_1^{-1}=\begin{pmatrix}1&0\\0&1/4\end{pmatrix}\), giving \((x-\mu_1)^\mathsf{T}\Sigma_1^{-1}(x-\mu_1)=1/4\). Therefore \(\delta_1(x)=\log(0.6)-\log 2-\frac18\approx-0.5108-0.6931-0.125=-1.329\).

For class 2, \(x-\mu_2=(-2,1)^\mathsf{T}\) and \(\Sigma_2^{-1}=\begin{pmatrix}1/4&0\\0&1\end{pmatrix}\). Its quadratic form is \((-2)^2/4+1^2=2\). Thus \(\delta_2(x)=\log(0.4)-\log 2-1\approx-0.9163-0.6931-1=-2.609\). Since \(-1.329>-2.609\), the score rule assigns \(x\) to class 1. The calculation uses the prior, determinant, and distance terms; the common \(-\frac p2\log(2\pi)\) would lower both full scores equally.

Why the Determinant and Prior Matter

The quadratic distance alone does not represent the Gaussian density. A class with a more dispersed distribution can place an observation relatively close in its own covariance-scaled geometry, but its density also has a normalizing factor involving \(|\Sigma_k|\). Likewise, the likelihood alone ignores the prior probability of encountering the class. A complete comparison retains every term that varies across classes.

Worked Example: The Determinant Can Change the Winner

Consider two equally likely classes in two dimensions, both with mean \((0,0)^\mathsf{T}\). Let \(\Sigma_1=I_2\), \(\Sigma_2=4I_2\), and observe \(x=(2,0)^\mathsf{T}\). Since the priors are equal, their log-prior terms cancel in the comparison.

For class 1, \(|\Sigma_1|=1\) and the quadratic form is \(x^\mathsf{T}x=4\), so its reduced score is \(\delta_1(x)=-\frac12(0)-\frac12(4)=-2\).

For class 2, \(|\Sigma_2|=4^2=16\) and \(\Sigma_2^{-1}=\frac14 I_2\). Its quadratic form is \(x^\mathsf{T}(\frac14 I_2)x=1\), so \(\delta_2(x)=-\frac12\log 16-\frac12(1)=-\log 4-\frac12\approx-1.3863-0.5=-1.8863\).

Thus class 2 has the larger score, despite its determinant penalty, because its smaller distance penalty more than offsets that cost at this observation. If the determinant term were incorrectly omitted, the scores would be \(-2\) and \(-0.5\), exaggerating the advantage of the more dispersed class. The correct comparison is \(-1.8863>-2\).

Worked Example: A Prior Breaks a Distance Tie

In one dimension, suppose three classes have means \(\mu_1=-2\), \(\mu_2=0\), and \(\mu_3=2\), all with variance \(1\). Let their priors be \(0.2\), \(0.5\), and \(0.3\), respectively. For the observation \(x=1\), compare reduced scores.

Here each determinant is \(1\), so the determinant terms vanish. The squared distances are \(9\), \(1\), and \(1\). Therefore \(\delta_1(1)=\log(0.2)-\frac92\approx-1.6094-4.5=-6.1094\), \(\delta_2(1)=\log(0.5)-\frac12\approx-0.6931-0.5=-1.1931\), and \(\delta_3(1)=\log(0.3)-\frac12\approx-1.2040-0.5=-1.7040\).

Classes 2 and 3 are equally far from the observation, but class 2 has the larger prior and therefore the larger score. Class 2 also exceeds class 1, whose distance penalty is much larger. The assignment is class 2. Ignoring the prior would incorrectly treat classes 2 and 3 as tied.

Common Mistakes and a Reliable Comparison

A useful way to organize a calculation is to evaluate the five terms in the expanded score for each class, or to calculate the three terms in the centered form. Keep one form consistently; the expanded and centered forms are algebraically identical.

1
Record the class parameters.
For each class, identify its prior, mean, and covariance matrix, checking that the covariance is positive definite.
2
Calculate the covariance contributions.
Find \(\log|\Sigma_k|\) and the inverse needed for the quadratic form.
3
Evaluate the observation-dependent distance.
Compute \((x-\mu_k)^\mathsf{T}\Sigma_k^{-1}(x-\mu_k)\), then multiply by \(-1/2\).
4
Add the log prior and compare.
Choose a class with the largest total score; add the common normal-density constant only if a full log joint density is needed.

A frequent mistake is to discard every term that is constant in \(x\). That reasoning confuses “constant as \(x\) varies” with “the same for all classes.” The determinant, prior, and mean-dependent terms are constant in \(x\), but generally differ by class, so removing them can change the assignment. Only terms that are common to every class at the observation being evaluated can be dropped without changing the maximizing class.

Another mistake is to compare raw quadratic distances when covariance matrices differ. The relevant distance is scaled by the class-specific inverse covariance, and even that is only one part of the score. The determinant and prior complete the comparison. When all class parameters are specified, retaining these contributions makes the classification calculation transparent and checkable.

Key takeaway: A Gaussian class score is the log prior minus one-half the log covariance determinant minus one-half the covariance-adjusted squared distance. The largest score gives the same class assignment as the largest posterior probability because all omitted terms are common to the classes.

Check Your Understanding

Use the definitions and calculations above to answer the following questions.

  1. Which assumptions ensure that the Gaussian log score is defined for every class?
  2. Why can the term \(-\frac p2\log(2\pi)\) be omitted when comparing classes?
  3. In the expanded score, which terms depend on the observation \(x\), and which are constant in \(x\) for a fixed class?
  4. Why is it generally incorrect to omit \(-\frac12\log|\Sigma_k|\) from a class comparison?
  5. If two classes have the same covariance and equal distance contributions at an observation, what part of the score can still decide between them?
Clinical Biostats