We want to find an orthogonal matrix O that is closest to a matrix A. If A=UΣVT, then:
O∗=UVTProof that O* = UVᵀ∥A−O∥F2=tr((A−O)T(A−O))=∥A∥F2, no Otr(ATA)−2tr(OTA)+tr(I)=ntr(OTO)Omin∥A−O∥F⟺Omaxtr(OTA)tr(OTA)=tr(OTAUΣVT)=tr(Z, orthogonalVTOTUΣ)tr(ZΣ)=i∑≤1zii≥0σi is largest when Z=I⟺VTOTU=I⟺O∗=UVT
The difference is:
∥A−UVT∥F=i∑(σi−1)2
2. How A and O transform a circle
You can change the value of A in the code below to whatever you want.
import numpy as np
# Change A, run this, then run the editor below
A = np.array([[1.6, 0.6],
[0.4, 0.8]])
U, _, Vt = np.linalg.svd(A)
O = U @ Vt
pie.clear()
pie.scalar(90, out='unit')
DARK = '#3f3f46'
def shown_matrix(w_a, w_o, A, O):
# The radio buttons move these weights between 0 and 1
return w_a * A + w_o * O
w = pie.scalar([1, 0], out='w')
M = pie.lift(shown_matrix, pie.Array[pie.Scalar])(w[0], w[1], A, O)
# Drawing
origin = pie.point(0, 0, hidden=True)
pie.circle(origin, 1, stroke='rgba(63, 63, 70, 0.35)')
pie.la_circle_transform(M, 24)
pie.la_mat_to_ellipse(M, origin, stroke=DARK)
pie.ui.animated_radio(w, options=['A', 'O = UVᵀ'], label='show')
def bmatrix(M):
rows = [' & '.join(f'{x:.2f}' for x in row) for row in M]
return r'\begin{bmatrix}' + r' \\ '.join(rows) + r'\end{bmatrix}'
pie.ui.latex(pie.text(f'A = {bmatrix(A)}, \\quad O = UV^T = {bmatrix(O)}'))
3. Muon optimizer
Muon replaces the gradient of a matrix G=UΣVT with its nearest orthogonal matrix UVT:
W←W−ηUVT,G=UΣVT
However it only approximates UVT instead of calculating the exact value using SVD to save time.
4. Connection with Orthogonal Procrustes problem
The Procrustes problem relates to finding an orthogonal matrix O so that OX gets as close as possible to Y (under Frobenius norm).
O∗=argOTO=Imin∥OX−Y∥F
If YXT=UΣVT then
O∗=UVTProof that O* = UVᵀ∥OX−Y∥F2=tr((OX−Y)T(OX−Y))=∥X∥F2, no Otr(XTOTOX)−2tr(YTOX)+∥Y∥F2, no Otr(YTY)Omin∥OX−Y∥F⟺Omaxtr(YTOX)tr(YTOX)=tr(OTUΣVTYXT)=tr(Z, orthogonalVTOTUΣ)tr(ZΣ)=i∑≤1zii≥0σi is largest when Z=I⟺VTOTU=I⟺O∗=UVT
The nearest orthogonal matrix to A is the Procrustes problem with X=I and Y=A: