参考资料
1 📖 解超定方程
工程中很多问题会归结为求超定方程 A x = 0 \mathbf{A x}=\mathbf{0} Ax=0 , A \mathbf{A} A是
m*n
的矩阵,且m>n
。如SLAM中三角化地图点,PnP等一些问题都是求解这个方程。很显然,这个方程有一个0解,但这不是我们想要的,我们实际想求非零解。
为了求非零解,我们对
A
\mathbf{A}
A加上一个约束
∥
x
∥
2
=
1
\|\mathbf{x}\|^{2}=1
∥x∥2=1。也就是限制
x
\mathbf{x}
x的长度为1,并构建成一个带约束的最小二乘问题:
x
^
=
arg
min
∥
A
x
∥
2
,
subject to
∥
x
∥
2
=
1
(
1
)
\hat{\mathbf{x}}=\arg \min \|\mathbf{A} \mathbf{x}\|^{2}, \text { subject to }\|\mathbf{x}\|^{2}=1 \space\space(1)
x^=argmin∥Ax∥2, subject to ∥x∥2=1 (1)
这是一个带约束的最小二乘问题,我们把拉格朗日搬出来:
L
(
x
,
λ
)
=
∥
A
x
∥
2
+
λ
(
1
−
∥
x
∥
2
)
=
x
T
A
T
A
x
+
λ
(
1
−
x
T
x
)
(
2
)
\begin{aligned} L(\mathbf{x}, \lambda) &=\|\mathbf{A} \mathbf{x}\|^{2}+\lambda\left(1-\|\mathbf{x}\|^{2}\right) \\ &=\mathbf{x}^{T} \mathbf{A}^{T} \mathbf{A} \mathbf{x}+\lambda\left(1-\mathbf{x}^{T} \mathbf{x}\right) \end{aligned} \space\space(2)
L(x,λ)=∥Ax∥2+λ(1−∥x∥2)=xTATAx+λ(1−xTx) (2)
为了求极值,我们分别对
A
\mathbf{A}
A和
λ
\mathbf{\lambda}
λ求偏导数,令为0
∂
L
(
x
,
λ
)
∂
x
=
2
A
T
A
x
−
2
λ
x
=
0
(
3
)
∂
L
(
x
,
λ
)
∂
λ
=
1
−
x
T
x
=
0
(
4
)
\begin{aligned} \frac{\partial L(\mathbf{x}, \lambda)}{\partial \mathbf{x}}=2 \mathbf{A}^{T} \mathbf{A} \mathbf{x}-2 \lambda \mathbf{x}=0 \end{aligned} \space\space(3) \\ \begin{aligned} \frac{\partial L(\mathbf{x}, \lambda)}{\partial \lambda}=1-\mathbf{x}^{T} \mathbf{x}=0 \end{aligned} \space\space(4)
∂x∂L(x,λ)=2ATAx−2λx=0 (3)∂λ∂L(x,λ)=1−xTx=0 (4)
把(3)式整理一下:
(
A
T
A
−
λ
I
)
x
=
0
(
5
)
A
T
A
x
=
λ
x
(
6
)
\begin{array}{r} \left(\mathbf{A}^{T} \mathbf{A}-\lambda \mathbf{I}\right) \mathbf{x}=0 \space\space(5) \\ \mathbf{A}^{T} \mathbf{A} \mathbf{x}=\lambda \mathbf{x} \space\space(6) \end{array}
(ATA−λI)x=0 (5)ATAx=λx (6)
注意:可以看出
λ
\mathbf{\lambda}
λ和
x
\mathbf{x}
x分别是
A
T
A
\mathbf{A}^{T}\mathbf{A}
ATA 的特征值和特征向量。也就是说(1)式的解,就是这些特征向量中的一个。
问题来了,那么多的特征向量,应该选择哪个作为解呢?我们展开
∥
A
x
∥
2
\|\mathbf{A} \mathbf{x}\|^{2}
∥Ax∥2看一下:
∥
A
x
∥
2
=
x
T
A
T
A
x
=
x
T
λ
x
=
λ
x
T
x
=
λ
(
7
)
\|\mathbf{A} \mathbf{x}\|^{2}=\mathbf{x}^{T} \mathbf{A}^{T} \mathbf{A} \mathbf{x}=\mathbf{x}^{T} \lambda \mathbf{x}=\lambda \mathbf{x}^{T} \mathbf{x}=\lambda \space\space(7)
∥Ax∥2=xTATAx=xTλx=λxTx=λ (7)
上面(7)推导利用(6)和 ∥ x ∥ 2 = 1 \|\mathbf{x}\|^{2}=1 ∥x∥2=1
也就是说,我们想要 ∥ A x ∥ 2 \|\mathbf{A} \mathbf{x}\|^{2} ∥Ax∥2最小,就需要 λ \lambda λ最小。
那方程(1)的非零解就是 A T A \mathbf{A}^{T}\mathbf{A} ATA的最小特征值和对应的特征向量
2 📖 关于SVD分解
假设
A
A
A为8*9的矩阵,则SVD分解结果为
A
=
U
D
V
T
A=U D V^{T}
A=UDVT
- U:左奇异向量,为8*8的正交矩阵
- V:右奇异向量,为9*9的正交矩阵,其转置为 V T V^T VT
- D:一个8*9的对角矩阵,除了对角线元素均为0,对角线元素称为奇异值,一般来说奇异值是按照从大到小的顺序降序排列。因为每一个奇异值都是一个残差项,因此最后一个奇异值最小,其含义是最优的残差。因此其对用的奇异值向量就是最优解。这一部分可以参考我的关于SVD的笔记。