Skip to main content
© 2026 ePowerAI — free, open courseware. No login required.
CoursesContact
ePOWERAI
CoursesContact
Week 5: Semidefinite Programming
Adv. Optimization

Duality & KKT

  1. 01Week 1: Optimality Conditions Revisited
  2. 02Week 2: Lagrangian Duality in Depth
  3. 03Week 3: KKT and Sensitivity

Cones & IPMs

  1. 04Week 4: LP, QP, and Conic Form
  2. 05Week 5: Semidefinite Programming
  3. 06Week 6: Interior-Point Methods
  4. 07Week 7: Proximal Methods and ADMM

Second-order & scale

  1. 08Week 8: Newton and Quasi-Newton
  2. 09Week 9: Variance Reduction
  3. 10Week 10: Large-Batch and Distributed Training

Geometry & training science

  1. 11Week 11: Automatic Differentiation
  2. 12Week 12: Sharpness and SAM
  3. 13Week 13: Landscapes and Implicit Bias

Capstone

  1. 14Week 14: Capstone — Structure Meets Scale
Week 05· Adv. Optimization· Cones & IPMs9 min read

Week 5: Semidefinite Programming

Learning Outcomes
  • Write an SDPSemidefinite Program in standard form: min⁡⟨C,X⟩\min \langle C, X \ranglemin⟨C,X⟩ s.t. ⟨Ai,X⟩=bi\langle A_i, X \rangle = b_i⟨Ai​,X⟩=bi​, X⪰0X \succeq 0X⪰0
  • Explain why the PSD cone is convex
  • Describe the relaxation idea that lifts a vector variable xxx to a matrix X=xxTX = xx^TX=xxT, then drops the rank-1 constraint
Prerequisites

Background: Week 4 (LP/QP/SOCP forms, cone vocabulary). Linear Algebra (eigenvalues, PSD matrices, trace inner product). Intermediate Optim convex sets.

Later weeks: SDPSemidefinite Program relaxations are the most powerful structured convex tool. Week 6 (IPMs) solves SDPs; Week 14 capstone references SDPs as the prototypical "structure path" choice.

  • Also see: Linear Algebra Week 12: Symmetric and Positive Definite Matrices — the spectral facts behind the PSD cone.

The PSD cone#

PSD cone: X ⪰ 0 trace(X) = 1 slice spectrahedron constraint X ⪰ 0 means every eigenvalue λᵢ(X) ≥ 0 semidefinite programming: linear objective over the PSD cone

The constraint X⪰0X \succeq 0X⪰0 says every eigenvalue of XXX is non-negative — a convex cone, not a linear one. Intersecting it with an affine slice gives a spectrahedron, the SDP analogue of a polytope.

Let Sn\mathbb{S}^nSn denote the set of n×nn \times nn×n real symmetric matrices. A matrix X∈SnX \in \mathbb{S}^nX∈Sn is positive semidefinite (PSD), written X⪰0X \succeq 0X⪰0, if:

vTXv≥0∀v∈Rnv^T X v \geq 0 \quad \forall v \in \mathbb{R}^nvTXv≥0∀v∈Rn

Equivalent characterisations:

  • All eigenvalues of XXX are ≥0\geq 0≥0.
  • All principal minors are ≥0\geq 0≥0 (Sylvester's criterion for PD, extended for PSD).
  • X=LLTX = L L^TX=LLT for some LLL (Cholesky factorisation exists when X≻0X \succ 0X≻0).

The set S+n={X∈Sn∣X⪰0}\mathbb{S}^n_+ = \{X \in \mathbb{S}^n \mid X \succeq 0\}S+n​={X∈Sn∣X⪰0} is the PSD cone — a closed, convex, pointed, full-dimensional cone in Sn\mathbb{S}^nSn.

Proof of convexity. Let X,Y⪰0X, Y \succeq 0X,Y⪰0 and θ∈[0,1]\theta \in [0,1]θ∈[0,1]. For any vvv, vT(θX+(1−θ)Y)v=θvTXv+(1−θ)vTYv≥0v^T (\theta X + (1-\theta)Y) v = \theta v^T X v + (1-\theta) v^T Y v \geq 0vT(θX+(1−θ)Y)v=θvTXv+(1−θ)vTYv≥0 since both terms are ≥0\geq 0≥0. The set is closed under nonnegative scaling and addition, forming a proper cone.

The PSD cone generalises the nonnegative orthant. For diagonal matrices, X⪰0X \succeq 0X⪰0 reduces to xi≥0x_i \geq 0xi​≥0 — every diagonal entry must be nonnegative. The off-diagonal entries introduce coupling: X⪰0X \succeq 0X⪰0 requires xiixjj≥xij2x_{ii} x_{jj} \geq x_{ij}^2xii​xjj​≥xij2​ for each 2×22 \times 22×2 principal submatrix.

Worked PSD test — 2×22 \times 22×2:

X=(abbc)⪰0  ⟺  a≥0,  c≥0,  ac−b2≥0X = \begin{pmatrix} a & b \\ b & c \end{pmatrix} \succeq 0 \iff a \geq 0,\; c \geq 0,\; ac - b^2 \geq 0X=(ab​bc​)⪰0⟺a≥0,c≥0,ac−b2≥0

  • X=(2112)X = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}X=(21​12​): eigenvalues 3,1≥03, 1 \geq 03,1≥0, so PSD.
  • X=(1331)X = \begin{pmatrix} 1 & 3 \\ 3 & 1 \end{pmatrix}X=(13​31​): eigenvalues 4,−24, -24,−2 — not PSD.
  • X=(0000)X = \begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix}X=(00​00​): PSD (zero matrix is always PSD).

SDP standard form#

A semidefinite program (SDP) is:

min⁡X⟨C,X⟩=tr⁡(CTX)=∑i,jCijXijs.t.⟨Ai,X⟩=bi,i=1,…,mX⪰0\begin{aligned} \min_X &\quad \langle C, X \rangle = \operatorname{tr}(C^T X) = \sum_{i,j} C_{ij} X_{ij} \\ \text{s.t.} &\quad \langle A_i, X \rangle = b_i, \quad i = 1, \ldots, m \\ &\quad X \succeq 0 \end{aligned}Xmin​s.t.​⟨C,X⟩=tr(CTX)=i,j∑​Cij​Xij​⟨Ai​,X⟩=bi​,i=1,…,mX⪰0​

where C,Ai∈SnC, A_i \in \mathbb{S}^nC,Ai​∈Sn and b∈Rmb \in \mathbb{R}^mb∈Rm. The decision variable is the entire n×nn \times nn×n matrix XXX, and the objective is linear in XXX (the trace inner product). The single constraint X⪰0X \succeq 0X⪰0 is nonlinear and cone-shaped — it is the defining complexity of an SDP.

Why matrix variable? Many problems naturally involve matrix decisions — covariance estimation, experiment design, kernel matrix learning. The constraint X⪰0X \succeq 0X⪰0 enforces that covariance/kernel matrices are valid PSD.

LP as a special case. If we constrain XXX to be diagonal, ⟨C,X⟩=∑iCiiXii\langle C, X \rangle = \sum_i C_{ii} X_{ii}⟨C,X⟩=∑i​Cii​Xii​, and X⪰0X \succeq 0X⪰0 becomes Xii≥0X_{ii} \geq 0Xii​≥0. Setting ci=Ciic_i = C_{ii}ci​=Cii​, xi=Xiix_i = X_{ii}xi​=Xii​, the SDP reduces to min⁡cTx\min c^T xmincTx s.t. Ax=bAx = bAx=b, x≥0x \geq 0x≥0 — a standard-form LP. Every LP is an SDP; SDPs are strictly more expressive.

Dual SDP. The Lagrangian dual of an SDP is also an SDP:

max⁡y∈Rm  bTys.t.C−∑i=1myiAi⪰0\max_{y \in \mathbb{R}^m} \; b^T y \quad \text{s.t.} \quad C - \sum_{i=1}^m y_i A_i \succeq 0maxy∈Rm​bTys.t.C−∑i=1m​yi​Ai​⪰0

The dual variable yyy has dimension mmm (the number of equality constraints), and the dual constraint is a linear matrix inequality (LMI). This dual structure enables elegant theoretical guarantees.

Spectrahedra#

The feasible set of an SDP, {X⪰0∣⟨Ai,X⟩=bi}\{X \succeq 0 \mid \langle A_i, X \rangle = b_i\}{X⪰0∣⟨Ai​,X⟩=bi​}, is the intersection of an affine subspace with the PSD cone. In dual space, the feasible set {y∣C−∑yiAi⪰0}\{y \mid C - \sum y_i A_i \succeq 0\}{y∣C−∑yi​Ai​⪰0} is a spectrahedron — a set defined by a linear matrix inequality. Spectrahedra are convex sets that generalise polyhedra (which are defined by x≥0x \geq 0x≥0 rather than X⪰0X \succeq 0X⪰0).

Every polyhedron is a spectrahedron, but the converse is false. Spectrahedra can have curved boundaries described by polynomial inequalities (determinantal constraints), giving them richer geometry than polyhedra. This is why SDPs can model problems that LPs cannot.

Visualising spectrahedra in 3D. The set {(y1,y2,y3)∣(1y1y2y11y3y2y31)⪰0}\{(y_1, y_2, y_3) \mid \begin{pmatrix} 1 & y_1 & y_2 \\ y_1 & 1 & y_3 \\ y_2 & y_3 & 1 \end{pmatrix} \succeq 0\}{(y1​,y2​,y3​)∣​1y1​y2​​y1​1y3​​y2​y3​1​​⪰0} is a convex body known as the 3×33 \times 33×3 elliptope. Its boundary has smooth curved regions and sharp ridges where the matrix drops rank — a shape no polyhedron can produce.

Relaxations#

Many hard combinatorial problems become tractable convex programs via SDP relaxation. The core trick: replace a vector variable xxx with a matrix variable X=xxTX = xx^TX=xxT.

Rank-1 lifting. Consider a quadratic problem:

min⁡x∈Rn  xTCxs.t.xTAix=bi,  x∈{−1,1}n\min_{x \in \mathbb{R}^n} \; x^T C x \quad \text{s.t.} \quad x^T A_i x = b_i,\; x \in \{-1, 1\}^nminx∈Rn​xTCxs.t.xTAi​x=bi​,x∈{−1,1}n

The objective xTCx=⟨C,xxT⟩x^T C x = \langle C, xx^T \ranglexTCx=⟨C,xxT⟩, so define X=xxTX = xx^TX=xxT. Then X⪰0X \succeq 0X⪰0, XXX has rank 1, and Xii=1X_{ii} = 1Xii​=1 (since xi∈{−1,1}x_i \in \{-1, 1\}xi​∈{−1,1}). The nonconvex rank-1 constraint is the source of hardness. Dropping it yields an SDP:

min⁡X⪰0  ⟨C,X⟩s.t.⟨Ai,X⟩=bi,  Xii=1\min_{X \succeq 0} \; \langle C, X \rangle \quad \text{s.t.} \quad \langle A_i, X \rangle = b_i,\; X_{ii} = 1minX⪰0​⟨C,X⟩s.t.⟨Ai​,X⟩=bi​,Xii​=1

This SDP provides a lower bound on the original problem. If the SDP solution happens to have rank 1, it is exact. In practice, rounding heuristics (e.g., random hyperplane rounding for Max-Cut) recover feasible solutions from the fractional SDP optimum with provable approximation guarantees.

Matrix completion. Given partially observed entries of a low-rank matrix, one can recover the full matrix by solving an SDP that minimises ∥X∥∗\|X\|_*∥X∥∗​ (nuclear norm, the sum of singular values) subject to matching observations. The nuclear norm is the convex envelope of rank — minimising it is an SDP relaxation of rank minimisation. This underlies recommendation systems and collaborative filtering.

When SDPs appear in learning#

SDPs are not a first-line tool in deep learning training, but they appear wherever structure matters:

  • Kernel learning: learning a valid PSD kernel matrix KKK from data reduces to an SDP.
  • Covariance estimation: estimating a sparse inverse covariance (graphical Lasso) under PSD constraint.
  • Robust PCA: separating a low-rank matrix from sparse corruption via SDP.
  • Certification: SDPs can certify robustness of neural networks against adversarial perturbations, providing formal guarantees.

The pattern is the same: when your learning problem has a matrix decision variable that must be PSD, you are in SDP territory. The solver (IPM, Week 6) handles the constraint; your job is recognising when that constraint applies.

Knowledge Check#

Exercise · Multiple choice

Which of these 2 × 2 matrices is PSD?

[[1, 2], [2, 1]]
[[3, 1], [1, 1]]
[[−1, 0], [0, −1]]
[[0, 1], [1, 0]]
Question 1 of 3

In SDP standard form, the decision variable is a symmetric ____, constrained to be PSD.

Browser lab#

Check PSD status of several 3×33 \times 33×3 matrices via eigenvalues. Implement spectral projection onto the PSD cone: zero out negative eigenvalues and reconstruct.

python · runs in browser
import numpy as np

def is_psd(M):
    """Check PSD by computing eigenvalues."""
    evals = np.linalg.eigvalsh(M)
    return np.all(evals >= -1e-10), evals

def project_psd(M):
    """Project symmetric M onto the PSD cone by zeroing negative eigenvalues."""
    evals, evecs = np.linalg.eigh(M)
    evals_pos = np.maximum(evals, 0)
    return evecs @ np.diag(evals_pos) @ evecs.T

# Test matrices
matrices = {
    "PSD": np.array([[2, 1, 0.5], [1, 2, 0.3], [0.5, 0.3, 1.5]]),
    "Indefinite": np.array([[1, 3, 0], [3, 1, 0], [0, 0, -0.5]]),
    "Negative definite": np.array([[-2, 0, 1], [0, -1, 0], [1, 0, -2]]),
    "Near-PSD (rank deficient)": np.array([[1, 1, 0], [1, 1, 0], [0, 0, 0.5]]),
}

for name, M in matrices.items():
    psd_flag, evals = is_psd(M)
    print(f"{name:30s} PSD={psd_flag}  evals={np.round(evals, 4)}")

print()

# Demonstrate projection onto PSD cone
print("Spectral projection onto PSD cone:")
M_inf = np.array([[1.0,  3.0, 0.0],
                  [3.0,  1.0, 0.0],
                  [0.0,  0.0, 1.0]])  # eigenvalues: 4, -2, 1

print("Original matrix:")
print(M_inf)
_, evals_orig = is_psd(M_inf)
print(f"Eigenvalues: {np.round(evals_orig, 4)}")

M_proj = project_psd(M_inf)
print("\nProjected matrix (negative eigenvalues zeroed):")
print(np.round(M_proj, 4))
_, evals_proj = is_psd(M_proj)
print(f"Eigenvalues: {np.round(evals_proj, 4)}")

# Verify projection is PSD
psd_flag_proj, _ = is_psd(M_proj)
print(f"\nProjected matrix is PSD: {psd_flag_proj}")

# Frobenius distance (minimal among all PSD matrices)
print(f"Frobenius distance ||M - proj(M)||_F = {np.linalg.norm(M_inf - M_proj, 'fro'):.4f}")

print("Notice: zeroing the negative eigenvalues is the nearest PSD matrix: the projection is PSD, at Frobenius distance 2.0000 from the indefinite input.")

Key takeaways#

  • The PSD cone is convex. It generalises the nonnegative orthant: diagonal PSD is elementwise nonnegativity, with off-diagonal coupling added.
  • An SDP has a matrix variable X⪰0X \succeq 0X⪰0 and a linear objective ⟨C,X⟩\langle C, X \rangle⟨C,X⟩; every LP is the diagonal special case.
  • The dual of an SDP is another SDP, with a linear matrix inequality C−∑iyiAi⪰0C - \sum_i y_i A_i \succeq 0C−∑i​yi​Ai​⪰0. Its feasible set is a spectrahedron, which can have curved boundaries no polyhedron can produce.
  • Relaxation lifts a vector xxx to a matrix X=xxTX = xx^TX=xxT and drops the nonconvex rank-1 constraint. The SDP gives a lower bound, exact when the solution is rank 1.
  • Nuclear-norm minimisation is the convex envelope of rank, which is why matrix completion is an SDP relaxation.
  • SDPs appear in machine learning wherever a matrix decision must be PSD — kernel learning, covariance estimation, robust PCA, and robustness certification.

Further reading#

  • Lieven Vandenberghe & Stephen Boyd, "Semidefinite Programming" (SIAM Review, 1996) — the canonical survey, freely available.
  • Henry Wolkowicz, Romesh Saigal & Lieven Vandenberghe (eds.), Handbook of Semidefinite Programming (Springer, 2000) — theory, algorithms, and applications.
  • Stephen Boyd & Lieven Vandenberghe, Convex Optimization (Cambridge University Press, 2004) — §4.6 introduces the SDP cone and spectrahedra.

Reading is free. PDF and ePub unlock with the newsletter. Join once and every lesson opens in this browser.

← Previous
Week 4: LP, QP, and Conic Form
Next →
Week 6: Interior-Point Methods
On this page
  • The PSD cone
  • SDP standard form
  • Spectrahedra
  • Relaxations
  • When SDPs appear in learning
  • Knowledge Check
  • Browser lab
  • Key takeaways
  • Further reading