BRAGA

02 Writing02-02 Notes02-02-159

Determinant Identity (eigenvalues)

Published 16 Apr 20269 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
det⁡(A)=∏iλi\det(A) = \prod_{i} \lambda_i
(1)

Deep Breakdown

What it tells me (Situation Awareness): The determinant of a square matrix equals the product of all its eigenvalues: det⁡(A)=∏iλi\det(A) = \prod_i \lambda_i. This is one of the two fundamental eigenvalue identities (the other is the trace = sum of eigenvalues). Since the determinant encodes invertibility, this formula says: AA is singular if and only if at least one eigenvalue is zero. In DA/DS this appears when checking whether a covariance matrix is positive definite (det⁡(Σ)=∏iλi>0\det(\Sigma) = \prod_i \lambda_i > 0 iff all eigenvalues are positive), computing the log-likelihood of a Gaussian (log⁡∣Σ∣=∑ilog⁡λi\log|\Sigma| = \sum_i \log\lambda_i is much more stable than computing det⁡(Σ)\det(\Sigma) directly for high-dimensional data), and understanding why adding a small diagonal perturbation (εI\varepsilon I) makes a singular matrix invertible (shifts all eigenvalues up by ε\varepsilon, pushing the product away from zero).

Flowchart

YesNoYesMixed signsInput: squarematrix A (n x n)Computeeigenvalues:lambda_1,lambda_2, ...,lambda_nComputeproduct: det(A) =lambda_1 *lambda_2 * ... *lambda_nIs any lambda_i== 0?det(A) = 0:matrix issingular (notinvertible)det(A) != 0:matrix isinvertibleAll lambda_i 0?Positive definite:det 0, safe forCholeskyIndefinite: detsign = product ofsigns ofeigenvaluesConnection: anyzero eigenvaluecollapses adimension to 0volumelog_det =sum(log(lambda_i)): numericallystablelog-determinant

Real-world use

Where it is used

Used in the multivariate Gaussian log-likelihood (requires log⁡∣Σ∣\log|\Sigma|), in testing positive definiteness of covariance matrices, in computing the volume scaling factor of a linear transformation, in PCA to measure how much "information" is compressed (small eigenvalues contribute near-zero to the product), and in checking whether a linear system has a unique solution.

Problem it solves

Computing det⁡(A)\det(A) via cofactor expansion is O(n!)O(n!) for naive implementations and numerically unstable for large matrices. Using eigenvalues, you can compute det⁡(A)=∏iλi\det(A) = \prod_i \lambda_i from an O(n3)O(n^3) eigendecomposition. More importantly, the log-determinant log⁡det⁡(A)=∑ilog⁡λi\log\det(A) = \sum_i \log\lambda_i avoids overflow/underflow for large covariance matrices (common in high-dimensional DA/DS), where det⁡(Σ)\det(\Sigma) would underflow to zero in float64.

How it solves the problem

If A=VΛV−1A = V\Lambda V^{-1} is the eigendecomposition, then det⁡(A)=det⁡(V)det⁡(Λ)det⁡(V−1)=det⁡(Λ)\det(A) = \det(V)\det(\Lambda)\det(V^{-1}) = \det(\Lambda) because det⁡(V)det⁡(V−1)=det⁡(VV−1)=det⁡(I)=1\det(V)\det(V^{-1}) = \det(VV^{-1}) = \det(I) = 1. The determinant of the diagonal matrix Λ\Lambda is just the product of its diagonal entries λi\lambda_i.

Example in a business

A data scientist computes the log-likelihood of a multivariate Gaussian model for customer lifetime value predictions across 20 features. The covariance matrix Σ\Sigma is 20×2020 \times 20. Direct det⁡(Σ)\det(\Sigma) is numerically unstable (product of 20 small numbers). Instead: compute eigenvalues λ1,…,λ20\lambda_1, \dots, \lambda_{20}, compute log⁡∣Σ∣=∑i=120log⁡λi\log|\Sigma| = \sum_{i=1}^{20} \log\lambda_i. This is numerically stable and connects directly to the Gaussian log-likelihood −12(x−μ)TΣ−1(x−μ)−12log⁡∣Σ∣−n2log⁡(2π)-\frac{1}{2}(x - \mu)^T \Sigma^{-1}(x - \mu) - \frac{1}{2}\log|\Sigma| - \frac{n}{2}\log(2\pi).

The formula, piece by piece

  • det⁡(A)\det(A): the determinant of the n×nn \times n matrix AA; a scalar
  • ∏i\prod_i: product over all eigenvalue indices i=1,2,…,ni = 1, 2, \ldots, n
  • λi\lambda_i: the ii-th eigenvalue of AA (possibly complex for non-symmetric matrices; for symmetric real matrices all eigenvalues are real)
  • If any λi=0\lambda_i = 0: the whole product is zero, so AA is singular
  • The product includes repeated eigenvalues with their algebraic multiplicity Full formula: det⁡(A)=∏i=1nλi=λ1⋅λ2⋯λn\det(A) = \prod_{i=1}^n \lambda_i = \lambda_1 \cdot \lambda_2 \cdots \lambda_n

The formula in words

"The determinant is the product of all eigenvalues. If even one eigenvalue is zero, the determinant is zero and the matrix is singular (non-invertible). The determinant encodes the total volume scaling of the transformation." Tiny numeric example: A=[3004]A = \begin{bmatrix}3 & 0 \\ 0 & 4\end{bmatrix} (diagonal). Eigenvalues: λ1=3\lambda_1 = 3, λ2=4\lambda_2 = 4. det⁡(A)=3⋅4=12\det(A) = 3 \cdot 4 = 12. Direct formula: 3⋅4−0⋅0=123 \cdot 4 - 0 \cdot 0 = 12. Non-diagonal: A=[2112]A = \begin{bmatrix}2 & 1 \\ 1 & 2\end{bmatrix}. Eigenvalues: λ1=3\lambda_1 = 3, λ2=1\lambda_2 = 1. det⁡(A)=3⋅1=3\det(A) = 3 \cdot 1 = 3. Direct: 4−1=34 - 1 = 3.

Critical Concepts

  • Singular iff any eigenvalue is zero: det⁡(A)=0  ⟺  ∃i:λi=0\det(A) = 0 \iff \exists i: \lambda_i = 0. A zero eigenvalue means there is a non-zero vector vv such that Av=0Av = 0, i.e., a direction that gets collapsed to the origin.
  • Log-determinant: log⁡det⁡(A)=∑ilog⁡λi\log\det(A) = \sum_i \log\lambda_i. For positive definite matrices (all λi>0\lambda_i > 0), this is always defined and numerically stable. Use np.linalg.slogdet(A) which returns sign and log-abs-det.
  • Covariance matrix: det⁡(Σ)>0\det(\Sigma) > 0 iff Σ\Sigma is positive definite (all eigenvalues positive). det⁡(Σ)=0\det(\Sigma) = 0 means the features are linearly dependent; the joint distribution is degenerate.
  • Companion identity: tr(A)=∑iλi\text{tr}(A) = \sum_i \lambda_i (sum) and det⁡(A)=∏iλi\det(A) = \prod_i \lambda_i (product). These are the first two of the nn elementary symmetric polynomials of the eigenvalues.
  • Product rule: det⁡(AB)=det⁡(A)det⁡(B)=∏iλi(A)⋅∏iλi(B)\det(AB) = \det(A)\det(B) = \prod_i\lambda_i(A) \cdot \prod_i\lambda_i(B).
  • Regularization effect: det⁡(A+εI)=∏i(λi+ε)\det(A + \varepsilon I) = \prod_i (\lambda_i + \varepsilon); adding εI\varepsilon I shifts every eigenvalue by ε\varepsilon, preventing the product from being zero when ε>0\varepsilon > 0 and λi≥0\lambda_i \geq 0.

Step-by-step calculation (tiny example)

Step 1: Compute eigenvalues of a symmetric 3x3 matrix A=[410131012]A = \begin{bmatrix}4 & 1 & 0 \\ 1 & 3 & 1 \\ 0 & 1 & 2\end{bmatrix}. Characteristic polynomial: det⁡(A−λI)=0\det(A - \lambda I) = 0. Eigenvalues (computed numerically): λ1≈5.214\lambda_1 \approx 5.214, λ2≈2.0\lambda_2 \approx 2.0, λ3≈1.786\lambda_3 \approx 1.786.

Step 2: Compute the determinant via product of eigenvalues det⁡(A)=5.214×2.0×1.786≈18.63\det(A) = 5.214 \times 2.0 \times 1.786 \approx 18.63.

Step 3: Verify directly Direct cofactor expansion: det⁡(A)=4(3⋅2−1⋅1)−1(1⋅2−1⋅0)+0=4(5)−1(2)=20−2=18\det(A) = 4(3 \cdot 2 - 1 \cdot 1) - 1(1 \cdot 2 - 1 \cdot 0) + 0 = 4(5) - 1(2) = 20 - 2 = 18. Close to 18.6318.63 (difference due to rounding of eigenvalues). Exact eigenvalues give exact product = 18.

Code examples

Beginner example (Python)

python
import numpy as np   # -- det(A) = product of eigenvalues: verify and apply ----------------
A = np.array([[4.0, 1.0, 0.0], [1.0, 3.0, 1.0], [0.0, 1.0, 2.0]])
eigenvalues = np.linalg.eigvalsh(A)   # use eigvalsh for symmetric matrices
det_via_eigs = float(np.prod(eigenvalues))
det_via_numpy = float(np.linalg.det(A))
print(f"Eigenvalues: {eigenvalues.round(6)}")
print(f"\ndet via product of eigenvalues: {det_via_eigs:.6f}")
print(f"det via np.linalg.det: {det_via_numpy:.6f}")
print(f"Match: {np.isclose(det_via_eigs, det_via_numpy)}")   # Log-determinant (numerically stable)
sign, log_abs_det = np.linalg.slogdet(A)
log_det_via_eigs = float(np.sum(np.log(eigenvalues)))
print(f"\nlog|det(A)| via slogdet: {log_abs_det:.6f}")
print(f"log|det(A)| via sum(log(eig)): {log_det_via_eigs:.6f}")   # Singular matrix: one eigenvalue is 0
A_sing = np.array([[1.0, 2.0], [2.0, 4.0]])   # row 2 = 2 * row 1
print(f"\nSingular matrix eigenvalues: {np.linalg.eigvalsh(A_sing).round(6)}")
print(f"det (should be 0): {np.linalg.det(A_sing):.2e}")

Beginner example (R)

r
# -- det(A) = product of eigenvalues: verify -------------------------
A <- matrix(c(4, 1, 0, 1, 3, 1, 0, 1, 2), nrow = 3, byrow = TRUE)
ev <- eigen(A, symmetric = TRUE)$values
det_ev <- prod(ev)
det_r <- det(A)
cat(sprintf("Eigenvalues: %s\n", paste(round(ev, 6), collapse = ", ")))
cat(sprintf("det via product of eigenvalues: %.6f\n", det_ev))
cat(sprintf("det via det(): %.6f\n", det_r))
cat(sprintf("Match: %s\n", isTRUE(all.equal(det_ev, det_r, tolerance = 1e-8))))  # Log-determinant (stable)
log_det <- sum(log(ev[ev > 0]))
cat(sprintf("log|det(A)| via sum(log(eig)): %.6f\n", log_det))

Professional example (Python)

python
import numpy as np
import pandas as pd
np.random.seed(42)   # -- Business scenario: Gaussian log-likelihood for anomaly detection
# Fit a multivariate Gaussian to N_TRAIN normal campaign weeks.
# Score test campaigns via log-likelihood (uses log-determinant).
N_TRAIN = 150
N_TEST = 20
N_FEATURES = 8
KPI_NAMES = [f"kpi_{i}" for i in range(N_FEATURES)]
JITTER = 1e-6   # numerical stability for Cholesky # Simulate training data (normal campaign KPIs)
true_mean = np.zeros(N_FEATURES)
true_cov = np.random.uniform(0.1, 0.5, size=(N_FEATURES, N_FEATURES))
true_cov = true_cov @ true_cov.T + np.eye(N_FEATURES)   # ensure PD
X_train = np.random.multivariate_normal(true_mean, true_cov, N_TRAIN)
X_test = np.random.multivariate_normal(true_mean * 2, true_cov * 1.5, N_TEST)   # Estimate mean and covariance from training data
mu_hat = X_train.mean(axis=0)
cov_hat = np.cov(X_train.T) + JITTER * np.eye(N_FEATURES)   # Log-determinant via eigenvalues (numerically stable)
eigenvalues = np.linalg.eigvalsh(cov_hat)
log_det = float(np.sum(np.log(eigenvalues)))   # = log|cov_hat|
sign, log_det_np = np.linalg.slogdet(cov_hat)
print(f"Estimated cov eigenvalue range: [{eigenvalues.min():.4f}, {eigenvalues.max():.4f}]")
print(f"det(cov_hat) = prod(eigenvalues) = {float(np.prod(eigenvalues)):.4e} (tiny -- direct det would lose precision)")
print(f"log|det(cov_hat)| via eigenvalues: {log_det:.4f}")
print(f"log|det(cov_hat)| via slogdet: {log_abs_det_check:.4f}" if False else f"slogdet sign={sign}, log_abs_det={log_det_np:.4f}")   # Mahalanobis-based anomaly score (uses log-det in full Gaussian log-likelihood)
cov_inv = np.linalg.inv(cov_hat)

def gaussian_log_likelihood(x, mu, cov_inv, log_det, n_features):
    diff = x - mu
    maha = float(diff @ cov_inv @ diff)
    return -0.5 * (maha + log_det + n_features * np.log(2 * np.pi))
train_scores = [gaussian_log_likelihood(x, mu_hat, cov_inv, log_det, N_FEATURES) for x in X_train]
test_scores = [gaussian_log_likelihood(x, mu_hat, cov_inv, log_det, N_FEATURES) for x in X_test]
threshold = float(np.percentile(train_scores, 5))   # 5th percentile of training log-likelihoods
print(f"\nTraining log-likelihood: mean={np.mean(train_scores):.2f}, std={np.std(train_scores):.2f}")
print(f"Test log-likelihood: mean={np.mean(test_scores):.2f}, std={np.std(test_scores):.2f}")
print(f"Anomaly threshold (5th pct of training): {threshold:.2f}")
print(f"Test campaigns flagged as anomalous: {sum(s < threshold for s in test_scores)} / {N_TEST}")
print("\nInterpretation: log_det = sum(log(eigenvalues)) replaces det(Sigma) in the Gaussian formula, preventing numerical underflow in high-dimensional data.")

Source: MYLA p. 5

#linear-algebra#matrices-and-determinants#determinants-and-inverses

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