拉格朗日乘数法 (Lagrange Multiper) 以及拉格朗日对偶 (Lagrange duality) 都是在求最值中非常常用且有用的方法。其作用不在于帮你找到最值,而是帮你提供更多的约束条件,从而让你计算出最值。
这里主要讨论的形式如下:
$$
\begin{gathered}
\min_{x} f(x) \\
\text{subject to:} \\
g_i(x) \le 0, \quad i=1,\dots,m \\
h_j(x) = 0, \quad j=1,\dots,p
\end{gathered}
$$
拉格朗日乘数法
而拉格朗日数乘是上述式子的简化形式,即没有小于 0 的约束项,只有等于 0 的约束项。以下是其具体的形式(这里为了方便替换为了向量形式):
$$
\begin{gathered}
\min_{\mathbf{x} \in \mathbb{R}^n} \quad f(\mathbf{x}) \\
\text{s.t.} \quad \mathbf{h}(\mathbf{x}) = \mathbf{0}
\end{gathered}
$$
拉格朗日函数的形式:
$$
\begin{gathered}
\mathcal{L}(\mathbf{x}, \boldsymbol{\lambda}) = f(\mathbf{x}) + \langle \boldsymbol{\lambda}, \mathbf{h}(\mathbf{x}) \rangle \\
\text{s.t.} \quad \mathbf{h}(\mathbf{x}) = \mathbf{0}
\end{gathered}
$$
$\boldsymbol{\lambda}$ 被叫做拉格朗日乘数,而拉格朗日乘数法要求:
$$
\begin{gathered}
\nabla_{\mathbf{x}} \mathcal{L} = \nabla f(\mathbf{x}) + \nabla \langle \boldsymbol{\lambda}, \mathbf{h}(\mathbf{x}) \rangle = \mathbf{0}
\end{gathered}
$$
具体应用
这里就举一个最近用到的例子。
$$
\begin{aligned}
& \min_{\mathbf{x} \in \mathbb{R}^n} && \langle \boldsymbol{p}, \mathbf{x} \rangle \\
& \text{s.t.} && \sum_{i=1}^n 2^{-x_i} – 1 = 0
\end{aligned}
$$
这是原本是一个信息论里面最优编码的问题,他的拉格朗日函数形式如下:
$$
\begin{gathered}
\mathcal{L}(\mathbf{x}, \lambda) = \langle \boldsymbol{p}, \mathbf{x} \rangle + \lambda \left( \sum_{i=1}^n 2^{-x_i} – 1 \right)
\end{gathered}
$$
对其求导并结合之前的约束:
$$
\begin{aligned}
\nabla_{\mathbf{x}} \mathcal{L} &= \boldsymbol{p} – \lambda (\ln 2) 2^{-\mathbf{x}} = \mathbf{0} \\
\frac{\partial \mathcal{L}}{\partial \lambda} &= \sum_{i=1}^n 2^{-x_i} – 1 = 0
\end{aligned}
$$
我们就可以求得其解为:
$$
x_i^* = \log_2 \left( \frac{1}{p_i} \right)
$$
相关资料(推导)
具体的细节强烈建议去看 wiki 上面的解释,先看中文后看英文,会又有不一样的结果。这里只给出简要的证明。
xxxxx