SVD 公式: M = U Σ V T M = UΣV^T M=UΣVT
我们以二维空间为例,通过观察解释为什么U和V一定存在。

在二维空间里 SVD 需要找到2个互相垂直的单位向量(就是U),在经过M的转化(相乘)后依然互相垂直(就是V)。
这个2个互相垂直的单位向量一定位于一个半径为1的圆上。
那么个圆在经过M的空间转换后会是什么形状呢,答案是:一个椭圆。

M = [[0.5, -1], [2, -0.5]] 时,我们可以观察到左边的圆转化成了右边的椭圆:
奇异值分解(SVD)一定能分解的几何理解_奇异值分解
左边的圆变为右边的椭圆可以拆分成三步:

  • 放大/缩小圆
  • 旋转/翻转圆
  • 从某一角度压扁圆成椭圆

这里只有压扁操作会让椭圆上出现固定的互相垂直的向量,那就是椭圆的最长半径和最短半径,也就是我们要找的转化后的2个向量。反过来我们也一定能在左边的圆上找到对应的2个向量。

延伸

那么为什么U和V可以用来表达M所携带的信息呢?
这是因为U和V都是正交基,他们在空间转换上的效果只有旋转和翻转,也就意味着他们不会改变原空间中"物体"的形状。形状就是信息的表达。
而Σ仅仅是放大/缩小了各个坐标,就跟我们将数据normilize不会导致信息丢失是一样的。
所以U在跟Σ和V相乘之后,并没有带来任何其携带的信息的变化。既然 M = U Σ V T M = UΣV^T M=UΣVT,那也就意味着U和M携带的信息是一样的。
我们也可以对比理解成将一张图片拉伸/翻转/斜着压扁并不会导致图片上的信息丢失一样,也因为我们进行逆向操作就可以恢复图片。这也意味着V只需要是可逆矩阵就不会影响U表达的信息。


画图的代码:

import numpy as np

import matplotlib.pyplot as plt
import math

pi = math.pi


def pointsInCircum(r, n=100):
    return [(math.cos(2 * pi / n * x) * r, math.sin(2 * pi / n * x) * r) for x in range(0, n + 1)]


points = pointsInCircum(1, 32)

points = np.asarray(points)
M = np.asarray([[0.5, -1]
                   , [2, -0.5]])
points_after = points.dot(M)
print(M)
# points_1 = points_1.dot([[1,0]
#                       , [0,2]])


plt.rcParams['figure.figsize'] = [12, 6]
f, axarr = plt.subplots(nrows=1, ncols=2)
for ax in axarr:
    # ax.axis('off')
    ax.spines['left'].set_position('center')
    ax.spines['bottom'].set_position('center')
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.axis('equal')
    ax.set_xlim(-2.5, 2.5)
    ax.set_ylim(-2.5, 2.5)

for i in range(len(points)):
    # print(point)
    if i < 8:
        color = 'red'
    elif i < 16:
        color = 'green'
    elif i < 24:
        color = 'yellow'
    else:
        color = 'blue'
    point = points[i]
    axarr[0].plot([0, point[0]], [0, point[1]], color=color)
    point = points_after[i]
    axarr[1].plot([0, point[0]], [0, point[1]], color=color)
    # axarr[1].plot([0, point[0]],[0, point[1]],)

# # here must be something like circle.plot() or not?
plt.show()

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.