在机器学习中,常常会涉及到凸优化相关内容,例如最大熵原理、SVM、神经网络的优化器。
本文对机器学习中涉及到的必须要掌握的凸优化相关内容做一个简单归纳。
一般优化问题
无约束优化问题
⾃变量为⽮量的函数 f f f: R n → R R^n \rightarrow R Rn→R
min f ( x ) x ∈ R n \min f(\mathbf{x})\quad\mathbf{x}\in\mathbb{R}^n minf(x)x∈Rn
局部最优解常规方法
- 直接法
- 梯度等于 0,求得驻点,必要时 Hessian 矩阵再进⼀步判断
- 迭代法
- 梯度下降法
- 牛顿法
- 拟牛顿法
⼀般约束优化问题案例
考虑以下约束优化问题
minimize f ( x ) = x 1 2 + x 2 2 − 4 x 1 + 4 = ( x 1 − 2 ) 2 + x 2 2 subject to c 1 ( x ) = x 1 − 2 x 2 + 6 ≥ 0 c 2 ( x ) = − x 1 2 + x 2 − 1 ≥ 0 ; c 3 ( x ) = x 1 ≥ 0 ; c 4 ( x ) = x 2 ≥ 0 \begin{aligned} \text{minimize}\quad&f(\mathbf{x})=x_1^2+x_2^2-4x_1+4=\left(x_1-2\right)^2+x_2^2 \\ \text{subject to}\quad&c_1(\mathbf{x})=x_1-2x_2+6\geq0 \\ &c_{2}\left(\mathbf{x}\right)=-x_{1}^{2}+x_{2}-1\geq0;c_{3}\left(\mathbf{x}\right)=x_{1}\geq0;c_{4}\left(\mathbf{x}\right)=x_{2}\geq0 \end{aligned} minimizesubject tof(x)=x12+x22−4x1+4=(x1−2)2+x22c1(x)=x1−2x2+6≥0c2(x)=−x12+x2−1≥0;c3(x)=x1≥0;c4(x)=x2≥0
目标函数是圆的半径,不断向外扩,找到可行域内使得圆半径最小的值即为解。
行视图
矩阵乘法
[ 2 − 1 1 1 ] ⏟ A ∈ R 2 × 2 [ x y ] ⏟ x ∈ R 2 = [ 1 5 ] ⏟ b ∈ R 2 [ 2 1 1 4 − 6 0 − 2 7 2 ] ⏟ A ∈ R 3 × 3 [ u v w ] ⏟ x ∈ R 3 = [ 5 − 2 9 ] ⏟ b ∈ R 3 \begin{gathered}\underbrace{\left[\begin{array}{cc}2&-1\\1&1\end{array}\right]}_{\mathbf{A}\in\mathbb{R}^{2\times2}}\underbrace{\left[\begin{array}{c}x\\y\end{array}\right]}_{\mathbf{x}\in\mathbb{R}^{2}}=\underbrace{\left[\begin{array}{c}1\\5\end{array}\right]}_{\mathbf{b}\in\mathbb{R}^{2}}\\\underbrace{\left[\begin{array}{ccc}2&1&1\\4&-6&0\\-2&7&2\end{array}\right]}_{\mathbf{A}\in\mathbb{R}^{3\times3}}\underbrace{\left[\begin{array}{c}u\\v\\w\end{array}\right]}_{\mathbf{x}\in\mathbb{R}^{3}}=\underbrace{\left[\begin{array}{c}5\\-2\\9\end{array}\right]}_{\mathbf{b}\in\mathbb{R}^{3}}\end{gathered} A∈R2×2
[21−11]x∈R2
[xy]=b∈R2
[15]A∈R3×3
24−21−67102
x∈R3
uvw
=b∈R3
5−29
行视图-超平面
2 x − y = 1 x + y = 5 \begin{aligned} 2x-y&=1\\ x+y&=5 \end{aligned} 2x−yx+y=1=5
凸集/凸优化函数
为什么要凸优化
- 思考:对于⽆约束优化问题,梯度等于 0 这⼀条件是否可以成为充要条件?
- 思考:什么样的情况局部最⼩解可以成为全局最⼩解?
- 思考:约束优化问题怎么办?
- 思考:研究凸优化问题对于⾮凸问题⼜有什么帮助?
仿射集 (Affine Sets) 和凸集
仿射
⼀个集合 C ∈ R n C \in R^n C∈Rn 是仿射的,则 C C C 中两点间的直线也在 C C C 中
例如 x = θ x 1 + ( 1 − θ ) x 2 ∈ C ; θ ∈ R x = \theta x_1+(1−\theta)x_2\in C; \theta \in R x=θx1+(1−θ)x2∈C;θ∈R,即 A x = b Ax = b Ax=b 的解
凸集
⼀个集合 C ∈ R n C \in R^n C∈Rn 是凸的,则对于任意的 x ; y ∈ C x;y\in C x;y∈C,有 θ x 1 + ( 1 − θ ) x 2 ∈ C ; 0 ≤ θ ≤ 1 \theta x_1+(1−\theta)x_2\in C; 0 \le\theta\le1 θx1+(1−θ)x2∈C;0≤θ≤1
注意:国内很多教材为了与汉字 “凸” 与 “凹” 相呼应,对于凹凸性与国外教材正好是相反的,这里Boyd编写的教材《Convex Optimization》为准。
常见的凸集
空间与平面
- 所有 R n R^n Rn ,给定任意 x ; y ∈ R n x; y \in R^n x;y∈Rn , 则有 θ x + ( 1 − θ ) y ∈ R n θx + (1 − θ)y \in R^n θx+(1−θ)y∈Rn
- 所有 R + n R_+^n R+n
- 超平⾯ (Hyperplane): 既是仿射⼜是凸
C = { x ∣ a T x = b } C=\{\mathbf{x}\mid\mathbf{a}^T\mathbf{x}=b\} C={ x∣aTx=b} - 半空间 (Halfspace):只是凸
范数球
范数回顾
- 2-norm
∥ x ∥ 2 = ∑ i = 1 n ∣ x i ∣ 2 = ( x T x ) 1 / 2 \|\mathbf{x}\|_2=\sqrt{\sum_{i=1}^n|x_i|^2}=(\mathbf{x}^T\mathbf{x})^{1/2} ∥x∥2=i=1∑n∣xi∣2=(xTx)1/2 - 1-norm:
∥ x ∥ 1 = ∑ i = 1 n ∣ x i ∣ \|\mathbf{x}\|_1=\sum_{i=1}^n|x_i| ∥x∥1=i=1∑n∣xi∣ - ∞-norm
∥ x ∥ ∞ = max i = 1 , . . . , n ∣ x i ∣ \|\mathbf{x}\|_\infty= \max_{i=1,...,n}|x_i| ∥x∥∞=i=1,...,nmax∣xi∣ - p-norm, p ≥ 1:
∥ x ∥ p = ∑ i = 1 n ∣ x i ∣ p p \|\mathbf{x}\|_p=\sqrt[p]{\sum_{i=1}^n|x_i|^p} ∥x∥p=pi=1∑n∣xi∣p
范数球也是凸集
范数球,例1如 ∣ ∣ x ∣ ∣ 2 ≤ 1 ||x||_2 ≤ 1 ∣∣x∣∣2≤1. 给定任意 x ; y ∈ R n 且 ∣ ∣ x ∣ ∣ —— 2 ≤ 1 , ∣ ∣ y ∣ ∣ —— 2 ≤ 1 x; y \in R_n 且 || x ||——2 ≤ 1 , ||y||——2 ≤ 1 x;y∈Rn且∣∣x∣∣——2≤1,∣∣y∣∣——2≤1 ,则有
∣ ∣ θ x + ( 1 − θ ) y ∣ ∣ 2 ≤ θ ∣ ∣ x ∣ ∣ 2 + ( 1 − θ ) ∣ ∣ y ∣ ∣ 2 ≤ 1 ||θx + (1 − θ) y||_2 ≤ θ|| x ||_2 + (1 − θ) ||y||_2 ≤ 1 ∣∣θx+(1−θ)y∣∣2≤θ∣∣x∣∣2+(1−θ)∣∣y∣∣2≤1
多面体
多⾯体 (Polyhedron): 有限个半空间和半平⾯的交集
P = { x ∣ A x ≤ b ; C x = d } , 其中 A ∈ R m × n , b ∈ R m , C ∈ R p × n , d ∈ R p \begin{aligned}\mathbf{P}=\{\mathbf{x}\mid\mathbf{A}\mathbf{x}\leq\mathbf{b};\mathbf{C}\mathbf{x}=\mathbf{d}\},\text{其中 A}\in\mathbb{R}^{m\times n},\mathbf{b}\in\mathbb{R}^m,\mathbf{C}\in\mathbb{R}_{p\times n},\mathbf{d}\in\mathbb{R}_p\end{aligned} P={
x∣Ax≤b;Cx=d},其中 A∈Rm×n,b∈Rm,C∈Rp×n,d∈Rp
凸集的性质
凸集的交集是凸集
例如: S = ∥ x ∥ ≤ 1 ; x ≥ 0 S = {∥x ∥ ≤ 1; x \ge 0} S=∥x∥≤1;x≥0
证明:假定 S 1 ; ⋯ ; S k S_1;\cdots;S_k S1;⋯;Sk是凸集,给定\ x ; y ∈ ∩ i = 1 k S i \mathbf{x};\mathbf{y}\in\cap_{i=1}^kS_i x;y∈∩i=1kSi,则有
θ x + ( 1 − θ ) y ∈ S i ; i = 1 ; ⋯ ; k \theta\mathbf{x}+(1-\theta)\mathbf{y}\in S_i;\quad i=1;\cdots;k θx+(1−θ)y∈Si;i=1;⋯;k
因此,
θ x + ( 1 − θ ) y ∈ ∩ i = 1 k S i \theta\mathbf{x}\:+\:(1\:-\:\theta)\mathbf{y}\:\in\cap_{i=1}^kS_i θx+(1−θ)y∈∩i=1kSi