liveBook · Manning

Diagonalization

As explained in Math and Architectures of Deep Learning

A matrix transformation technique that expresses a square matrix in a basis where it becomes diagonal, simplifying computations such as powers.

Diagonalization changes coordinates so a square matrix becomes diagonal. For a matrix A with linearly independent eigenvectors, place those eigenvectors in S and its eigenvalues in diagonal Λ: A = SΛS⁻¹. For symmetric A, the eigenvectors are orthogonal, so A = SΛSᵀ and S represents a rotation. section 2.15

Diagonalization supports two useful interpretations:

  • It separates a transformation into eigenvector directions, where scaling is represented by the diagonal entries of Λ. section 2.15
  • It solves symmetric linear systems without explicitly forming a potentially unstable matrix inverse: transform with Sᵀ, divide by diagonal Λ, then transform with S. section 2.15.2
  • It reveals the axes of a hyperellipse: the eigenvectors become the rotated coordinate axes, and the quadratic-form matrix becomes diagonal. section 2.17

A rotated ellipse

For 5x² + 6xy + 5y² = 20, use A = [[5, 3], [3, 5]]. Computing its eigenvectors gives an orthogonal rotation; the major axis forms a 45° angle with the x-axis. Rotating by that basis aligns the ellipse with the coordinate axes. section 2.17.1

Listing 2.21 Axes of a hyperellipse
ellipse_eq = sy.Eq(5*x**2 + 5*y**2 +
                      6*x*y, 20)                   ①

A = torch.tensor([[5, 3], [3, 5]]).float()

l, S = torch.linalg.eig(A)

x_axis_vec = torch.zeros((A.shape[0]))             ②

first_eigen_vec = S[:, 0]                          ③

dot_prod = torch.dot(x_axis_vec, first_eigen_vec)  ④

theta = math.acos(dot_prod)
theta = math.degrees(theta)                        ⑤

① Equation of the ellipse: 5x2 + 6xy + 5y2 = 20 or TA = 20, where

② X-axis vector

③ Major axis of the ellipse

④ The dot product between two vectors is the cosine of the angle between them.

⑤ The angle between the ellipse’s major axis and the X-axis: 45° (see figure 2.16)

Inspect the PyTorch implementation that constructs the ellipse matrix, computes eigenvectors, and measures the major-axis angle. section 2.17.1

How Math and Architectures of Deep Learning covers it

How deep it goes
Derives the symmetric-matrix form, gives a multistep linear solve, and applies rotations to hyperellipses.
Examples
Uses the ellipse 5x² + 6xy + 5y² = 20 and a PyTorch eigenvector calculation producing a 45° major-axis angle.
What it assumes
Assumes eigenvectors, eigenvalues, matrix multiplication, transposes, symmetric matrices, and quadratic-form notation.
What you can do after
Apply diagonalization to solve symmetric systems and identify hyperellipse axes with PyTorch eigenvalue routines.
How it connects
Connects eigenvectors, eigenvalues, linear systems, quadratic forms, hyperellipses, and principal component analysis.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math and Architectures of Deep Learning. The section links point to the parts of the book it draws on.