1.1.17Linear Algebra Essentials

Positive definite and semidefinite matrices

1,727 words8 min readdifficulty · medium6 backlinks

WHY do we care? (the 80/20)

In ML almost every "energy", "loss curvature", "covariance", or "kernel" is a symmetric matrix, and we constantly need to know: does this thing behave like a valid bowl-shaped cost?

  • Optimization: a function's Hessian being PD ⇒ a strict local minimum, so gradient descent converges nicely.
  • Covariance matrices are always PSD (variance can't be negative).
  • Kernels (SVMs, Gaussian processes) must be PSD (Mercer's condition) to correspond to a valid inner product.
  • Cholesky / solving Ax=bAx=b is fast and stable exactly when AA is PD.

So this single concept quietly powers loss landscapes, statistics, and kernel methods.


WHAT are the definitions?

We write A0A \succ 0 (PD) and A0A \succeq 0 (PSD). Negative (semi)definite flips the sign; indefinite means xAxx^\top A x takes both signs (a saddle).


HOW: deriving the eigenvalue test from scratch

We claim: for symmetric AA, "xAx>0x^\top A x>0 for all x0x\neq0" ⟺ "all eigenvalues >0>0".

Step 1 — Spectral theorem. A real symmetric matrix can be written A=QΛQ,QQ=I, Λ=diag(λ1,,λn).A = Q\Lambda Q^\top,\qquad Q^\top Q = I,\ \Lambda=\mathrm{diag}(\lambda_1,\dots,\lambda_n). Why this step? Symmetric matrices have real eigenvalues and an orthonormal eigenbasis — this is the key structural fact that lets us change coordinates without distortion.

Step 2 — Change of variables. Let y=Qxy = Q^\top x. Since QQ is orthogonal, x0    y0x\neq0 \iff y\neq0. Then xAx=xQΛQx=(Qx)Λ(Qx)=yΛy.x^\top A x = x^\top Q\Lambda Q^\top x = (Q^\top x)^\top \Lambda (Q^\top x) = y^\top \Lambda y. Why this step? Rotating into the eigenbasis makes the matrix diagonal — the "cross terms" disappear.

Step 3 — Diagonal form. yΛy=i=1nλiyi2.y^\top \Lambda y = \sum_{i=1}^n \lambda_i\, y_i^2. Why this step? A diagonal quadratic form is just a weighted sum of squares — trivially readable.

Step 4 — Conclude. Each yi20y_i^2 \ge 0.

  • If all λi>0\lambda_i>0, the sum is >0>0 whenever some yi0y_i\neq0 ⇒ PD.
  • If some λj0\lambda_j\le 0, pick y=ejy=e_j (i.e. x=Qejx=Q e_j, the jj-th eigenvector): the sum equals λj0\lambda_j\le0 ⇒ not PD.

\blacksquare Same argument with \ge gives the PSD ⟺ λi0\lambda_i\ge0 result.

Figure — Positive definite and semidefinite matrices

Worked examples


Common mistakes (steel-manned)


Recall Feynman: explain to a 12-year-old

Imagine a skateboard bowl. Drop a marble anywhere: if the ground curves up in every direction, the marble always rolls back to the bottom — that's a positive definite bowl. If part of the bowl is a flat gutter, the marble can sit still along that gutter (not roll down but not fall either) — that's semidefinite. If it's a mountain-pass saddle, it rolls down one way and up the other — that's indefinite. The "xAxx^\top A x" number is just the height of the ground when you walk in direction xx; positive definite means that height is always positive except right at the center.


Recall flashcards

What defines a positive definite symmetric matrix?
xAx>0x^\top A x>0 for all x0x\neq0; equivalently all eigenvalues >0>0.
PD vs PSD difference in one word?
Strict (>0>0, no zero eigenvalues) vs allows-flat (0\ge0, zero eigenvalues permitted).
Why must we assume AA symmetric before testing definiteness?
Only the symmetric part affects xAxx^\top Ax, since the antisymmetric part contributes zero.
Sylvester's criterion for PD?
All leading principal minors are positive.
Why does A=BBA=B^\top B guarantee PSD?
xBBx=Bx20x^\top B^\top B x=\|Bx\|^2\ge0 always.
When is a Hessian being PD useful?
At a critical point it certifies a strict local minimum.
Is a covariance matrix always PD?
No — always PSD; PD only if data isn't confined to a lower-dim subspace.
Counterexample: positive entries but not PD?
[1221]\begin{bmatrix}1&2\\2&1\end{bmatrix}, eigenvalues 3,13,-1 (indefinite).
Does detA>0\det A>0 imply PD?
No; I-I has det=1>0\det=1>0 but is negative definite.

Connections

  • Eigenvalues and Eigenvectors — the definitive test lives here.
  • Spectral Theorem — supplies the orthonormal diagonalization used in the derivation.
  • Cholesky Decomposition — exists iff PD; the fast solver.
  • Covariance Matrix — canonical PSD object in statistics.
  • Kernels and Mercer's Theorem — valid kernels ⟺ PSD Gram matrices.
  • Hessian and Convexity — PD Hessian ⇒ strictly convex ⇒ unique minimum.
  • Quadratic FormsxAxx^\top A x as a scalar function of direction.

Concept Map

only symmetric part matters

greater than 0 for all x nonzero

greater than or equal 0

change of variables y equals Q transpose x

all eigenvalues greater than 0

all eigenvalues greater than or equal 0

Hessian PD

enables

guarantees

Mercer condition

both signs

Symmetric matrix A

Quadratic form x transpose A x

Positive Definite

Positive Semidefinite

Spectral theorem A equals Q Lambda Q transpose

Sum of lambda_i times y_i squared

Strict local minimum

Cholesky and stable Ax equals b

Covariance matrices

Valid kernels

Indefinite saddle

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, ek symmetric matrix AA ko samajhne ka asaan tareeka hai uska "bowl shape". Har direction xx ke liye ek number nikalta hai xAxx^\top A x — ye us direction mein ground ki height jaisa hai. Agar ye number har non-zero direction mein positive hai, to matrix positive definite hai — matlab ek perfect bowl jahan marble kahin se bhi choro to neeche center pe hi aayega. Agar kuch directions mein number zero ho sakta hai (flat gutter), tab wo positive semidefinite hai. Aur agar kabhi positive kabhi negative, to wo saddle yaani indefinite.

Test kaise karein? Sabse pakka tareeka: eigenvalues nikalo. Saare positive ⇒ PD, saare non-negative ⇒ PSD, mixed ⇒ indefinite. Chhote matrices ke liye Sylvester shortcut hai: saare leading principal minors positive ⇒ PD. Ek badi galti se bachna — entries ka positive hona kaafi nahi hai, jaise [1221]\begin{bmatrix}1&2\\2&1\end{bmatrix} ke entries positive hain par eigenvalue 1-1 aata hai, to wo indefinite hai.

Ye cheez ML mein har jagah chhupi hai. Covariance matrix hamesha PSD hoti hai kyunki variance negative nahi ho sakta — aur wo XXX^\top X form mein hoti hai jo automatically Xv20\|Xv\|^2\ge0 deta hai. Kernels (SVM, Gaussian process) valid tabhi hote hain jab unki Gram matrix PSD ho. Aur optimization mein, agar Hessian kisi point pe PD hai, to wahan strict minimum hai — gradient descent aaraam se converge karega. Isliye ye ek chhota concept poore loss landscape aur statistics ko chalata hai.

Test yourself — Linear Algebra Essentials

Connections