目录通过优化进行平滑

第 13 章 通过优化进行平滑Chapter 13 Smoothing by optimization

当函数不可微(甚至更糟:不连续)时,一种合理的做法是用可微近似(或至少用连续松弛)取而代之。我们将把不可微函数变换为可微函数的过程称为对原函数的“平滑”。本章先回顾一种基于下确卷积的平滑技术,再回顾一种与之等价、基于 Legendre-Fenchel 变换的对偶方法,并举例说明如何运用这些技术计算平滑的 ReLU 与平滑的 max 算子,以及阶跃函数与 argmax 算子的连续松弛。When a function is non-differentiable (or worse, discontinuous), a reasonable approach is to replace it by a differentiable approximation (or at least, by a continuous relaxation). We refer to the process of transforming a non-differentiable function into a differentiable one as “smoothing” the original function. In this chapter, we begin by reviewing a smoothing technique based on infimal convolution. We then review an equivalent dual approach, based on the Legendre-Fenchel transform. We illustrate how to apply these techniques to compute smoothed ReLUs and smoothed max operators, as well as continuous relaxations of step functions and argmax operators.

13.1 原始方法13.1 Primal approach

我们首先回顾如何在函数原本的原始空间中对其加以平滑,所用工具是下确卷积,更具体地说,是 Moreau 包络,又称 Moreau-Yoshida 正则化。本章考虑的函数可以取值为正无穷,也就是说,其取值落在半扩展实数轴 R∪{∞}\mathbb{R}\cup\{\infty\} 上。对函数 f:RM→R∪{∞}f:\mathbb{R}^{M}\rightarrow\mathbb{R}\cup\{\infty\},我们将其定义域定义为We first review how to smooth functions in the original, primal space of the function, using the infimal convolution and more particularly the Moreau envelope, a.k.a. Moreau-Yoshida regularization. In this chapter, we consider functions taking potentially infinite positive values, that is, functions taking values in the half-extended real line R∪{∞}\mathbb{R}\cup\{\infty\}. For a function f:RM→R∪{∞}f:\mathbb{R}^{M}\rightarrow\mathbb{R}\cup\{\infty\}, we define its domain as

dom(f)={u∈RM:f(u)<∞}.\mathrm{dom}(f)=\{{\bm{u}}\in\mathbb{R}^{M}:f({\bm{u}})<\infty\}.

13.1.1 下确卷积Infimal convolution

下确卷积有时简称为 inf-conv。两个函数 ff 与 gg 的下确卷积会生成一个新函数 f□gf\square g,其定义如下。Sometimes abbreviated inf-conv, the infimal convolution between two functions ff and gg creates a new function f□gf\square g. It is defined as follows.

定义 13.1.1(下确卷积)。Definition 13.1.1 (Infimal convolution).
两个函数 f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\} 与 g ⁣:RM→R∪{∞}g\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\} 之间的下确卷积定义为The infimal convolution between two functions f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\} and g ⁣:RM→R∪{∞}g\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\} is defined by (f□g)(μ)\displaystyle(f\square g)({\bm{\mu}}) :=inf⁡u∈RMf(u)+g(μ−u)\displaystyle\coloneqq\inf_{{\bm{u}}\in\mathbb{R}^{M}}f({\bm{u}})+g({\bm{\mu}}-{\bm{u}}) =inf⁡z∈RMf(μ+z)+g(−z)\displaystyle=\inf_{{\bm{z}}\in\mathbb{R}^{M}}f({\bm{\mu}}+{\bm{z}})+g(-{\bm{z}}) =inf⁡u,z∈RMf(u)+g(−z) s.t. u=μ+z.\displaystyle=\inf_{{\bm{u}},{\bm{z}}\in\mathbb{R}^{M}}f({\bm{u}})+g(-{\bm{z}})\text{ s.t. }{\bm{u}}={\bm{\mu}}+{\bm{z}}.

借助变量替换 u:=μ+z{\bm{u}}\coloneqq{\bm{\mu}}+{\bm{z}}(这是一种位置—尺度变换,见 12.4.1 节),不难验证这三个定义确实彼此等价。It is easy to check that the three definitions are indeed equivalent, by using the change of variable u:=μ+z{\bm{u}}\coloneqq{\bm{\mu}}+{\bm{z}}, which is a location-scale transform; see Section 12.4.1.

下确卷积可看作通常卷积的对应物,只是其中的积分被换成了最小化,其名称也正由此而来。与经典卷积一样,它具有交换性,即对任意 μ∈RM{\bm{\mu}}\in\mathbb{R}^{M},都有The infimal convolution can be seen as a counterpart of the usual convolution, in which integration has been replaced by minimization (hence its name). Similarly to the classical convolution, it is commutative, meaning that for all μ∈RM{\bm{\mu}}\in\mathbb{R}^{M}, we have

(f□g)(μ)=(g□f)(μ).(f\square g)({\bm{\mu}})=(g\square f)({\bm{\mu}}).

计算下确卷积需要求解一个最小化问题,而该问题未必有解析解。表 13.1 列出了若干例子。Computing the infimal convolution involves the resolution of a minimization problem, that may or may not enjoy an analytical solution. Some examples are given in Table 13.1.

存在性Existence

若下确界 inf⁡u∈RMf(u)+g(μ−u)\inf_{{\bm{u}}\in\mathbb{R}^{M}}f({\bm{u}})+g({\bm{\mu}}-{\bm{u}}) 有限,则下确卷积 (f□g)(μ)(f\square g)({\bm{\mu}}) 存在 [15, 命题 12.6]。一个充分条件是:对任意 μ∈RM{\bm{\mu}}\in\mathbb{R}^{M},u↦f(u)+g(μ−u){\bm{u}}\mapsto f({\bm{u}})+g({\bm{\mu}}-{\bm{u}}) 均为凸函数。但这并非必要条件。例如,即便 ff 或 gg 非凸,只要其定义域是紧集,下确界仍可能有限。The infimal convolution (f□g)(μ)(f\square g)({\bm{\mu}}) exists if the infimum inf⁡u∈RMf(u)+g(μ−u)\inf_{{\bm{u}}\in\mathbb{R}^{M}}f({\bm{u}})+g({\bm{\mu}}-{\bm{u}}) is finite [15, Proposition 12.6]. A sufficient condition to achieve this is that u↦f(u)+g(μ−u){\bm{u}}\mapsto f({\bm{u}})+g({\bm{\mu}}-{\bm{u}}) is convex for all μ∈RM{\bm{\mu}}\in\mathbb{R}^{M}. However, this is not a necessary condition. For example, the infimum can be finite even if ff or gg are nonconvex, for example if their domain is a compact set.

与正则化函数的下确卷积Infimal convolution with a regularization function

当函数 ff 不可微时,一种常用技巧是用它与某个正则项 RR 的下确卷积 f□Rf\square R 来替代它。最常用的正则项是平方 22-范数,由此便得到 Moreau 包络,下面我们来回顾。When a function ff is non-differentiable, a commonly-used technique is to replace it by its infimal convolution f□Rf\square R, with some regularization RR. The most used regularization is the squared 22-norm, leading to the Moreau envelope, as we now review.

表 13.1:下确卷积的示例。我们用 ιC\iota_{\mathcal{C}} 表示集合 C\mathcal{C} 的指示函数。Table 13.1: Examples of infimal convolutions. We use ιC\iota_{\mathcal{C}} to denote the indicator function of the set C\mathcal{C}.
f(u)f({\bm{u}}) g(z)g({\bm{z}}) (f□g)(μ)(f\square g)({\bm{\mu}})
f(u)f({\bm{u}}) 00 inf⁡u∈RMf(u)\inf_{{\bm{u}}\in\mathbb{R}^{M}}f({\bm{u}})
f(u)f({\bm{u}}) ι{v}(z)\iota_{\{{\bm{v}}\}}({\bm{z}}) f(μ−v)f({\bm{\mu}}-{\bm{v}})
ιC(u)\iota_{\mathcal{C}}({\bm{u}}) ιD(z)\iota_{\mathcal{D}}({\bm{z}}) ιC+D(μ)\iota_{\mathcal{C}+\mathcal{D}}({\bm{\mu}})
ιC(u)\iota_{\mathcal{C}}({\bm{u}}) ∥z∥2\|{\bm{z}}\|_{2} dC(μ)=inf⁡u∈C∥μ−u∥2d_{\mathcal{C}}({\bm{\mu}})=\inf_{{\bm{u}}\in\mathcal{C}}\|{\bm{\mu}}-{\bm{u}}\|_{2}
f(u)f({\bm{u}}) 12∥z∥22\frac{1}{2}\|{\bm{z}}\|_{2}^{2}   envf(μ)=inf⁡u∈RM12∥μ−u∥22+f(u)\mathrm{env}_{f}({\bm{\mu}})=\inf_{{\bm{u}}\in\mathbb{R}^{M}}\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|_{2}^{2}+f({\bm{u}})

13.1.2 Moreau 包络Moreau envelope

当 R(z):=12∥z∥22R({\bm{z}})\coloneqq\frac{1}{2}\|{\bm{z}}\|^{2}_{2} 时,下确卷积 f□Rf\square R 给出所谓的 ff 的 Moreau 包络,它也称为 ff 的 Moreau-Yoshida 正则化。When R(z):=12∥z∥22R({\bm{z}})\coloneqq\frac{1}{2}\|{\bm{z}}\|^{2}_{2}, the infimal convolution f□Rf\square R gives the so-called Moreau envelope of ff, which is also known as Moreau-Yoshida regularization of ff.

定义 13.1.2(Moreau 包络)。Definition 13.1.2 (Moreau envelope).
给定函数 f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\},其 Moreau 包络定义为Given a function f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\}, its Moreau envelope is defined as envf(μ)\displaystyle\mathrm{env}_{f}({\bm{\mu}}) :=(f□12∥⋅∥22)(μ)\displaystyle\coloneqq\left(f\square\frac{1}{2}\|\cdot\|^{2}_{2}\right)({\bm{\mu}}) =inf⁡u∈RMf(u)+12∥μ−u∥22\displaystyle=\inf_{{\bm{u}}\in\mathbb{R}^{M}}f({\bm{u}})+\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|_{2}^{2} =inf⁡z∈RMf(μ+z)+12∥z∥22.\displaystyle=\inf_{{\bm{z}}\in\mathbb{R}^{M}}f({\bm{\mu}}+{\bm{z}})+\frac{1}{2}\|{\bm{z}}\|_{2}^{2}.

直观地说,Moreau 包络是在 u∈RM{\bm{u}}\in\mathbb{R}^{M} 上取到的最小值,它在按邻近项 12∥μ−u∥22\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|_{2}^{2} 保持与输入 μ{\bm{\mu}} 接近与最小化 f(u)f({\bm{u}}) 之间做出权衡。只要该最小值点存在且唯一,便可定义 ff 的相应邻近算子:Intuitively, the Moreau envelope is the minimal value over u∈RM{\bm{u}}\in\mathbb{R}^{M} of a trade-off between staying close to the input μ{\bm{\mu}} according to the proximity term 12∥μ−u∥22\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|_{2}^{2} and minimizing f(u)f({\bm{u}}). Provided that the minimizer exists and is unique, we can define the associated proximal operator of ff as

proxf(μ):=arg min⁡u∈RM12∥μ−u∥22+f(u).\mathrm{prox}_{f}({\bm{\mu}})\coloneqq\argmin_{{\bm{u}}\in\mathbb{R}^{M}}\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|_{2}^{2}+f({\bm{u}}).

换言之,对良定义的 proxf(μ)\mathrm{prox}_{f}({\bm{\mu}}),有In other words, we have for proxf(μ)\mathrm{prox}_{f}({\bm{\mu}}) well defined,

envf(μ)=f(proxf(μ))+12∥μ−proxf(μ)∥22.\mathrm{env}_{f}({\bm{\mu}})=f(\mathrm{prox}_{f}({\bm{\mu}}))+\frac{1}{2}\|{\bm{\mu}}-\mathrm{prox}_{f}({\bm{\mu}})\|_{2}^{2}. (13.1)

性质Properties

Moreau 包络 envf\mathrm{env}_{f} 的一个关键性质在于:无论凸函数 ff 如何,它始终是光滑函数,即便 ff 本身并不光滑。这里所说的光滑,正式而言是指所得函数 envf\mathrm{env}_{f} 处处可微,且梯度是Lipschitz 连续的。若其梯度是 LL-Lipschitz 连续的,则称该函数是 LL-光滑的。如 15.4 节所述,这一性质可决定优化算法的效率。下面回顾 Moreau 包络的若干有用性质。A crucial property of the Moreau envelope envf\mathrm{env}_{f} is that for any convex function ff, it is always a smooth function, even when ff itself is not smooth. By smooth, we formally mean that the resulting function envf\mathrm{env}_{f} is differentiable everywhere with Lipschitz-continuous gradients. We say LL-smooth, if the gradients are LL-Lipschitz continuous. Such a property can determine the efficiency of optimization algorithms as reviewed in Section 15.4. We recap below useful properties of the Moreau envelope.

命题 13.1.3(Moreau 包络的性质)。Proposition 13.1.3 (Properties of Moreau envelope).
设 f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\}。Let f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\}. 1. 光滑性:若 ff 为凸,则函数 envf\mathrm{env}_{f} 是 11-光滑的。Smoothness: If ff is convex, the function envf\mathrm{env}_{f} is 11-smooth. 2. 梯度:只要 proxf(μ)\mathrm{prox}_{f}({\bm{\mu}}) 在 μ∈RM{\bm{\mu}}\in\mathbb{R}^{M} 上有良定义,Moreau 包络的梯度便可用近端算子表示为Gradient: Provided that proxf(μ)\mathrm{prox}_{f}({\bm{\mu}}) is well-defined on μ∈RM{\bm{\mu}}\in\mathbb{R}^{M}, the gradient of the Moreau envelope can be expressed in terms of the proximal operator as ∇envf(μ)=μ−proxf(μ).\nabla\mathrm{env}_{f}({\bm{\mu}})={\bm{\mu}}-\mathrm{prox}_{f}({\bm{\mu}}). 3. Moreau 分解:若 ff 为凸,则对任意 μ∈RM{\bm{\mu}}\in\mathbb{R}^{M},有下述恒等式Moreau decomposition: If ff is convex, then for any μ∈RM{\bm{\mu}}\in\mathbb{R}^{M}, we have the following identity proxf(μ)+proxf∗(μ)=μ,\mathrm{prox}_{f}({\bm{\mu}})+\mathrm{prox}_{f^{*}}({\bm{\mu}})={\bm{\mu}}, 其中 f∗f^{*} 是 ff 的凸共轭,详见第 13.2 节。特别地,我们得到where f∗f^{*} is the convex conjugate of ff, detailed in Section 13.2. In particular, we get ∇envf∗(μ)=proxf(μ).\nabla\mathrm{env}_{f^{*}}({\bm{\mu}})=\mathrm{prox}_{f}({\bm{\mu}}). 4. 凸性:若 ff 为凸,则 envf\mathrm{env}_{f} 为凸。Convexity: envf\mathrm{env}_{f} is convex if ff is convex. 5. 下确界重合:envf\mathrm{env}_{f} 与原函数 ff 具有相同的下确界:Infimums coincide: envf\mathrm{env}_{f} has the same infimum as the original function ff: min⁡μ∈RMenvf(μ)=min⁡u∈RMf(u).\min_{{\bm{\mu}}\in\mathbb{R}^{M}}\mathrm{env}_{f}({\bm{\mu}})=\min_{{\bm{u}}\in\mathbb{R}^{M}}f({\bm{u}}).
证明 13.1.4。Proof 13.1.4.
  1. 1.

    借助 13.3 节详述的对偶方法,这一点最易于看清。This is best seen using the dual approach detailed in Section 13.3.

  2. 2.

    此结论可由 11.2 节回顾的 Danskin 定理推出。This follows from Danskin’s theorem, reviewed in Section 11.2.

  3. 3.

    参见,例如 [15,定理 14.3]。See, e.g., [15, Theorem 14.3].

  4. 4.

    这源于如下事实:联合凸函数的下确界仍为凸。This follows from the fact that the infimum of a jointly convex function is convex.

  5. 5.

    我们有We have

    inf⁡μ∈RMenvf(μ)\displaystyle\inf_{{\bm{\mu}}\in\mathbb{R}^{M}}\mathrm{env}_{f}({\bm{\mu}}) =inf⁡μ∈RMinf⁡u∈RM12∥μ−u∥22+f(u)\displaystyle=\inf_{{\bm{\mu}}\in\mathbb{R}^{M}}\inf_{{\bm{u}}\in\mathbb{R}^{M}}\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|^{2}_{2}+f({\bm{u}})
    =inf⁡u∈RMinf⁡μ∈RM12∥μ−u∥22+f(u)\displaystyle=\inf_{{\bm{u}}\in\mathbb{R}^{M}}\inf_{{\bm{\mu}}\in\mathbb{R}^{M}}\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|^{2}_{2}+f({\bm{u}})
    =inf⁡u∈RMf(u).\displaystyle=\inf_{{\bm{u}}\in\mathbb{R}^{M}}f({\bm{u}}).

示例Examples

图 13.1:Huber 损失即绝对损失的 Moreau 包络。Figure 13.1: The Huber loss is the Moreau envelope of the absolute loss.

为从 Moreau 包络的视角说明平滑过程,我们展示如何对 11-范数进行平滑。此时可得到 Moreau 包络的解析表达式。To illustrate smoothing from the Moreau envelope perspective, we show how to smooth the 11-norm. In this case, we obtain an analytical expression for the Moreau envelope.

例 13.1.5(通过下确卷积平滑 11-范数)。Example 13.1.5 (Smoothing the 11-norm via infimal convolution).
我们希望平滑 f(u):=∥u∥1=∑j=1M∣uj∣f({\bm{u}})\coloneqq\|{\bm{u}}\|_{1}=\sum_{j=1}^{M}|u_{j}|。相应的近端算子是软阈值算子(见第 16.4 节),We wish to smooth f(u):=∥u∥1=∑j=1M∣uj∣f({\bm{u}})\coloneqq\|{\bm{u}}\|_{1}=\sum_{j=1}^{M}|u_{j}|. The corresponding proximal operator is the soft-thresholding operator (see Section 16.4), proxf(μ)\displaystyle\mathrm{prox}_{f}({\bm{\mu}}) =arg min⁡u∈RM12∥μ−u∥22+∥u∥1\displaystyle=\argmin_{{\bm{u}}\in\mathbb{R}^{M}}\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|^{2}_{2}+\|{\bm{u}}\|_{1} =sign(μ)⋅max⁡(∣μ∣−1,0).\displaystyle=\mathrm{sign}({\bm{\mu}})\cdot\max(|{\bm{\mu}}|-1,0). 利用式 13.1 并经若干代数运算,我们得到Using Eq. 13.1 and after some algebraic manipulations, we obtain envf(μ)=∑j=1Mhuber(μj)≈∑j=1M∣μj∣,\mathrm{env}_{f}({\bm{\mu}})=\sum_{j=1}^{M}\mathrm{huber}(\mu_{j})\approx\sum_{j=1}^{M}|\mu_{j}|, 其中我们定义了 Huber 损失where we defined the Huber loss huber(μj):={μj22 if ∣μj∣≤1∣μj∣−12 if ∣μj∣>1.\mathrm{huber}(\mu_{j})\coloneqq\begin{cases}\frac{\mu_{j}^{2}}{2}&\text{ if }|\mu_{j}|\leq 1\\ |\mu_{j}|-\frac{1}{2}&\text{ if }|\mu_{j}|>1\end{cases}. 这由图 13.1 在 M=1M=1 下说明。This is illustrated in Fig. 13.1 with M=1M=1.

我们还在图 13.2 中表明,非凸函数的 Moreau 包络可以借助数值方法近似计算。We also illustrate in Fig. 13.2 that the Moreau envelope of nonconvex functions can be approximately computed numerically.

图 13.2:Moreau 包络并不局限于凸函数。例如,斜坡函数连续但非凸,阶跃函数则不仅非凸,而且不连续。在本图中,我们把搜索范围限制在一个闭区间内的有限网格上,从而近似计算了定义 13.1.2 中关于 u∈Ru\in\mathbb{R} 的下确界。Figure 13.2: The Moreau envelope is not limited to convex functions. For instance, the ramp function is continuous but nonconvex, and the step function is not only nonconvex but also discontinuous. In this figure, we approximately computed the infimum over u∈Ru\in\mathbb{R} in Definition 13.1.2 by restricting the search on a finite grid, in a closed interval.

13.1.3 向量值函数Vector-valued functions

Moreau 包络由 envf(μ):=inf⁡u∈RMf(u)+12∥μ−u∥22\mathrm{env}_{f}({\bm{\mu}})\coloneqq\inf_{{\bm{u}}\in\mathbb{R}^{M}}f({\bm{u}})+\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|_{2}^{2} 定义,因此仅适用于标量值函数 f ⁣:RM→Rf\colon\mathbb{R}^{M}\to\mathbb{R}。为把 Moreau 包络推广到向量值函数 f ⁣:RM→RTf\colon\mathbb{R}^{M}\to\mathbb{R}^{T},其中 f(u)=(f1(u),…,fT(u))f({\bm{u}})=(f_{1}({\bm{u}}),\dots,f_{T}({\bm{u}})),且对 i∈[T]i\in[T] 有 fi ⁣:RM→Rf_{i}\colon\mathbb{R}^{M}\to\mathbb{R},我们可以选择对每个 fjf_{j} 分别进行平滑,从而定义The Moreau envelope is defined by envf(μ):=inf⁡u∈RMf(u)+12∥μ−u∥22\mathrm{env}_{f}({\bm{\mu}})\coloneqq\inf_{{\bm{u}}\in\mathbb{R}^{M}}f({\bm{u}})+\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|_{2}^{2}. As such, it is limited to scalar-valued functions f ⁣:RM→Rf\colon\mathbb{R}^{M}\to\mathbb{R}. To extend the Moreau envelope to vector-valued functions f ⁣:RM→RTf\colon\mathbb{R}^{M}\to\mathbb{R}^{T}, where f(u)=(f1(u),…,fT(u))f({\bm{u}})=(f_{1}({\bm{u}}),\dots,f_{T}({\bm{u}})) and fi ⁣:RM→Rf_{i}\colon\mathbb{R}^{M}\to\mathbb{R} for i∈[T]i\in[T], we may choose to smooth each fjf_{j} separately to define

envf(μ):=(envf1(μ),…,envfT(μ)),\mathrm{\mathbf{env}}_{f}({\bm{\mu}})\coloneqq(\mathrm{env}_{f_{1}}({\bm{\mu}}),\dots,\mathrm{env}_{f_{T}}({\bm{\mu}})),

其中where

envfi(μ)=inf⁡ui∈RMfi(ui)+12∥μ−ui∥22.\mathrm{env}_{f_{i}}({\bm{\mu}})=\inf_{{\bm{u}}_{i}\in\mathbb{R}^{M}}f_{i}({\bm{u}}_{i})+\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}_{i}\|_{2}^{2}.

这一做法需要求解 TT 个各自独立的极小化问题,并对每个输出坐标 i∈[T]i\in[T] 分别做平滑。由命题 2.3.16 可知,envf(μ)\mathrm{\mathbf{env}}_{f}({\bm{\mu}}) 沿任意方向 d=(d1,…,dT)∈RT{\bm{d}}=(d_{1},\dots,d_{T})\in\mathbb{R}^{T} 的 VJP 即为This approach requires to solve TT separate minimization problems and performs the smoothing of each output coordinate i∈[T]i\in[T] independently. From Proposition 2.3.16, we then have that the VJP of envf(μ)\mathrm{\mathbf{env}}_{f}({\bm{\mu}}) with any direction d=(d1,…,dT)∈RT{\bm{d}}=(d_{1},\dots,d_{T})\in\mathbb{R}^{T} is

∂envf(μ)∗[d]\displaystyle\partial\mathrm{\mathbf{env}}_{f}({\bm{\mu}})^{*}[{\bm{d}}] =∑i=1T∂envfi(μ)∗[di]\displaystyle=\sum_{i=1}^{T}\partial\mathrm{env}_{f_{i}}({\bm{\mu}})^{*}[d_{i}]
=∑i=1Tdi∇envfi(μ).\displaystyle=\sum_{i=1}^{T}d_{i}\nabla\mathrm{env}_{f_{i}}({\bm{\mu}}).

在 f(u)=(f1(u1),…,fT(uT))f({\bm{u}})=(f_{1}(u_{1}),\dots,f_{T}(u_{T})) 这一特殊情形下,可得In the particular case f(u)=(f1(u1),…,fT(uT))f({\bm{u}})=(f_{1}(u_{1}),\dots,f_{T}(u_{T})), we obtain

∂envf(μ)∗[d]=∑i=1Tdi∇envfi(μi).\partial\mathrm{\mathbf{env}}_{f}({\bm{\mu}})^{*}[{\bm{d}}]=\sum_{i=1}^{T}d_{i}\nabla\mathrm{env}_{f_{i}}(\mu_{i}).

文献 [171] 提出了另一种方案。回顾一下,对可微函数 f ⁣:RM→RTf\colon\mathbb{R}^{M}\to\mathbb{R}^{T},ff 沿方向 d∈RT{\bm{d}}\in\mathbb{R}^{T} 的 VJP 为An alternative was proposed by [171]. For a differentiable function f ⁣:RM→RTf\colon\mathbb{R}^{M}\to\mathbb{R}^{T}, we recall that the VJP of ff with a direction d∈RT{\bm{d}}\in\mathbb{R}^{T} reads

∂f(u)∗[d]=∇⟨f,d⟩(u),\partial f({\bm{u}})^{*}[{\bm{d}}]=\nabla\langle f,{\bm{d}}\rangle({\bm{u}}),

其中我们定义了标量值函数 ⟨f,d⟩(u):=⟨f(u),d⟩\langle f,{\bm{d}}\rangle({\bm{u}})\coloneqq\langle f({\bm{u}}),{\bm{d}}\rangle。于是,倘若 ff 不可微,一个自然的思路便是:用 Moreau 包络的梯度 ∇env⟨f,d⟩(μ)\nabla\mathrm{env}_{\langle f,{\bm{d}}\rangle}({\bm{\mu}}) 来近似其(假若存在的话)VJP ∂f(u)∗[d]\partial f({\bm{u}})^{*}[{\bm{d}}]:where we defined the scalar-valued function ⟨f,d⟩(u):=⟨f(u),d⟩\langle f,{\bm{d}}\rangle({\bm{u}})\coloneqq\langle f({\bm{u}}),{\bm{d}}\rangle. As a result, if ff is non-differentiable, a natural idea is to approximate its VJP ∂f(u)∗[d]\partial f({\bm{u}})^{*}[{\bm{d}}] (had it existed) by the gradient ∇env⟨f,d⟩(μ)\nabla\mathrm{env}_{\langle f,{\bm{d}}\rangle}({\bm{\mu}}) of the Moreau envelope

env⟨f,d⟩(μ)=inf⁡u∈RM⟨f(u),d⟩+12∥μ−u∥22.\mathrm{env}_{\langle f,{\bm{d}}\rangle}({\bm{\mu}})=\inf_{{\bm{u}}\in\mathbb{R}^{M}}\langle f({\bm{u}}),{\bm{d}}\rangle+\frac{1}{2}\|{\bm{\mu}}-{\bm{u}}\|^{2}_{2}. (13.2)

这样只需解一个优化问题,与输出个数 TT 无关;而且当 d=ei{\bm{d}}={\bm{e}}_{i} 时,还能把 envfi(μ)\mathrm{env}_{f_{i}}({\bm{\mu}}) 作为一种特殊情形包含进来。This requires solving a single optimization problem, independently of the number of outputs TT. Moreover, for d=ei{\bm{d}}={\bm{e}}_{i}, this recovers envfi(μ)\mathrm{env}_{f_{i}}({\bm{\mu}}) as a special case.

原则上,这一方案使我们能够对层中使用 Moreau 包络的神经网络执行反向模式自动微分(梯度反向传播)。事实上,由命题 13.1.3,ff 沿方向 d{\bm{d}} 的近似 VJP 由下式给出This approach allows in principle to perform reverse-mode autodiff (gradient backpropagation) on a neural network whose layers use the Moreau envelope. Indeed, following Proposition 13.1.3, the approximate VJP of ff with a direction d{\bm{d}} is given by

∂f(μ)∗[d]≈∇env⟨f,d⟩(μ)=μ−u⋆,\partial f({\bm{\mu}})^{*}[{\bm{d}}]\approx\nabla\mathrm{env}_{\langle f,{\bm{d}}\rangle}({\bm{\mu}})={\bm{\mu}}-{\bm{u}}^{\star},

其中 u⋆{\bm{u}}^{\star} 是式 13.2 中极小化问题的解。但需要强调,这一极小化问题在一般情况下可能难以求解:执行梯度反向传播时,方向 d{\bm{d}} 未必非负,因此即便每个 fif_{i} 都是凸的,式 13.2 中所极小化的函数仍可能是非凸的。另一个隐患是:方向 d{\bm{d}} 会影响平滑强度,而按理说,无论是否计算函数的 VJP,我们都应能对该函数做平滑。举例来说,在 f(u)=(f1(u1),…,fT(uT))f({\bm{u}})=(f_{1}(u_{1}),\dots,f_{T}(u_{T})) 这一特殊情形下,容易验证:当 d=(d1,…,dT){\bm{d}}=(d_{1},\dots,d_{T}) 时,可得where u⋆{\bm{u}}^{\star} is the solution of the minimization problem in Eq. 13.2. However, we emphasize that this minimization problem could be difficult to solve in general. Indeed, when performing gradient backpropagation, the direction d{\bm{d}} is not necessarily non-negative, therefore the function being minimized in Eq. 13.2 could be nonconvex, even if each fif_{i} is convex. Another potential caveat is that the direction d{\bm{d}} influences the smoothing strength, while in principle we should be able to smooth a function independently of whether we compute its VJP or not. To see that, for example in the particular case f(u)=(f1(u1),…,fT(uT))f({\bm{u}})=(f_{1}(u_{1}),\dots,f_{T}(u_{T})), one easily checks that for d=(d1,…,dT){\bm{d}}=(d_{1},\dots,d_{T}), we get

env⟨f,d⟩(μ)=∑i=1Tenvdifi(μi).\mathrm{env}_{\langle f,{\bm{d}}\rangle}({\bm{\mu}})=\sum_{i=1}^{T}\mathrm{env}_{d_{i}f_{i}}(\mu_{i}).

用 Moreau 包络(更一般地说,用下确卷积)平滑向量值函数,仍是尚待探索的研究方向。第 14 章将说明,用卷积做平滑能更自然地处理向量值函数。Smoothing vector-valued functions by Moreau envelope (or more generally, by infimal convolution) remains an open area of research. We will see in Chapter 14 that smoothing by convolution more naturally supports vector-valued functions.

13.2 Legendre–Fenchel 变换与凸共轭13.2 Legendre–Fenchel transforms, convex conjugates

Legendre-Fenchel 变换又称凸共轭,它把函数 ff 变为一个新函数,记作 f∗f^{*}。由于它在对偶平滑方法中举足轻重,下面我们详细加以回顾。The Legendre-Fenchel transform, a.k.a. convex conjugate, is a way to turn a function ff into a new function, denoted f∗f^{*}. We now review it in detail, as it plays a major role for the dual approach to smoothing.

13.2.1 定义Definition

考虑如下形式的一类仿射函数Consider the class of affine functions of the form

u↦⟨u,v⟩−b.{\bm{u}}\mapsto\langle{\bm{u}},{\bm{v}}\rangle-b.

这些函数由斜率 v∈RM{\bm{v}}\in\mathbb{R}^{M} 与截距 −b∈R-b\in\mathbb{R} 参数化。现设 v{\bm{v}} 固定。给定函数 f(u)f({\bm{u}}),f(u)f({\bm{u}}) 的仿射下界即所有形如 u{\bm{u}} 的函数,其中 bb 对所有 u∈RM{\bm{u}}\in\mathbb{R}^{M} 均满足These functions are parametrized by their slope v∈RM{\bm{v}}\in\mathbb{R}^{M} and their intercept −b∈R-b\in\mathbb{R}. Now, suppose we fix v{\bm{v}}. Given a function f(u)f({\bm{u}}), affine lower bounds of f(u)f({\bm{u}}) are all the functions of u{\bm{u}} such that bb satisfies for all u∈RM{\bm{u}}\in\mathbb{R}^{M},

⟨u,v⟩−b≤f(u)  ⟺  ⟨u,v⟩−f(u)≤b.\langle{\bm{u}},{\bm{v}}\rangle-b\leq f({\bm{u}})\iff\langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}})\leq b.

最紧的下界由 bb 定义,使得The tightest lower bound is then defined by bb such that

b:=sup⁡u∈dom⁡(f)⟨u,v⟩−f(u),b\coloneqq\sup_{{\bm{u}}\in\dom(f)}\langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}}),

其中,我们记得 ff 的定义域定义为where we recall that the domain of ff is defined by

dom⁡(f):={u∈RM ⁣:f(u)<∞}.\dom(f)\coloneqq\{{\bm{u}}\in\mathbb{R}^{M}\colon f({\bm{u}})<\infty\}.

由此引出 Legendre-Fenchel 变换的定义,又称凸共轭。This leads to the definition of Legendre-Fenchel transform, a.k.a. convex conjugate.

定义 13.2.1(Legendre-Fenchel 变换,凸共轭)。Definition 13.2.1 (Legendre-Fenchel transform, convex conjugate).
给定函数 f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\},其凸共轭定义为Given a function f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\}, its convex conjugate is defined by f∗(v):=sup⁡u∈dom⁡(f)⟨u,v⟩−f(u).f^{*}({\bm{v}})\coloneqq\sup_{{\bm{u}}\in\dom(f)}\langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}}).

我们使用 sup⁡\sup 而非 max⁡\max,以表明 f∗(v)f^{*}({\bm{v}}) 可能为 ∞\infty。依据前述讨论,−f∗(v)-f^{*}({\bm{v}}) 是 f(u)f({\bm{u}}) 斜率为 v{\bm{v}} 的最紧仿射下界的截距。图 13.3 对此作了图示。We use a sup⁡\sup rather than a max⁡\max to indicate that f∗(v)f^{*}({\bm{v}}) is potentially ∞\infty. Following the previous discussion, −f∗(v)-f^{*}({\bm{v}}) is the intercept of the tightest affine lower bound with slope v{\bm{v}} of f(u)f({\bm{u}}). This is illustrated in Fig. 13.3.

图 13.3:当斜率 vv 固定时,函数 u↦uv−f∗(v)u\mapsto uv-f^{*}(v) 是 ff 斜率为 vv 的最紧仿射下界。Figure 13.3: For a fixed slope vv, the function u↦uv−f∗(v)u\mapsto uv-f^{*}(v) is the tightest affine lower bound of ff with slope vv.

Legendre-Fenchel 变换是一种函数变换,因为它生成一个新的函数 f∗f^{*}。它可以视为函数的一种对偶表示:我们不必再用凸函数 ff 在 u∈dom⁡(f){\bm{u}}\in\dom(f) 上的图像 (u,f(u))({\bm{u}},f({\bm{u}})) 来表示它,而可以用一族切线来表示它:对 v∈dom⁡(f∗){\bm{v}}\in\dom(f^{*}),这些切线的斜率为 v{\bm{v}}、截距为 −f∗(v)-f^{*}({\bm{v}}),如图 13.4 所示。正如“凸共轭”这一名称所示,即便原函数不是凸的,它也是凸的。The Legendre-Fenchel transform is a function transformation, as it produces a new function f∗f^{*}. It can be seen as a dual representation of a function: instead of representing a convex function ff by its graph (u,f(u))({\bm{u}},f({\bm{u}})) for u∈dom⁡(f){\bm{u}}\in\dom(f), we can represent it by the set of tangents with slope v{\bm{v}} and intercept −f∗(v)-f^{*}({\bm{v}}) for v∈dom⁡(f∗){\bm{v}}\in\dom(f^{*}), as illustrated in Fig. 13.4. As the name “convex conjugate” indicates, it is convex, even if the original function is not.

图 13.4:左图:我们不必再用凸函数 ff 在 u∈dom⁡(f){\bm{u}}\in\dom(f) 上的图像 (u,f(u))({\bm{u}},f({\bm{u}})) 来表示它,而可以用一族切线来表示它:对 v∈dom⁡(f∗){\bm{v}}\in\dom(f^{*}),这些切线的斜率为 v{\bm{v}}、截距为 −f∗(v)-f^{*}({\bm{v}})。右图:令所有可能切线的斜率 vv 变化,我们便得到关于斜率 vv 的函数,而非关于原始输入 uu 的函数。左图中各切线的颜色与右图中各竖线的颜色相对应。Figure 13.4: Left: instead of representing a convex function ff by its graph (u,f(u))({\bm{u}},f({\bm{u}})) for u∈dom⁡(f){\bm{u}}\in\dom(f), we can represent it by the set of tangents with slope v{\bm{v}} and intercept −f∗(v)-f^{*}({\bm{v}}) for v∈dom⁡(f∗){\bm{v}}\in\dom(f^{*}). Right: by varying the slope vv of all possible tangents, we obtain a function of the slope vv rather than of the original input uu. The colors of the tangents on the left are chosen to match the colors of the vertical lines on the right.

13.2.2 闭式示例Closed-form examples

计算 f∗(v)f^{*}({\bm{v}}) 需要求解一个极大化问题;若对 ff 不加任何假设,一般情形下这往往颇为棘手。不过,在某些情形下仍可求得解析表达式,下面举例说明。Computing f∗(v)f^{*}({\bm{v}}) involves the resolution of a maximization problem, which could be difficult in general without assumption on ff. In some cases, however, we can compute an analytical expression, as we now illustrate.

例 13.2.2(解析共轭示例)。Example 13.2.2 (Analytical conjugate examples).
当 f(u)=12∥u∥22f({\bm{u}})=\frac{1}{2}\|{\bm{u}}\|_{2}^{2},其中 dom⁡(f)=RM\dom(f)=\mathbb{R}^{M} 时,共轭为When f(u)=12∥u∥22f({\bm{u}})=\frac{1}{2}\|{\bm{u}}\|_{2}^{2}, with dom⁡(f)=RM\dom(f)=\mathbb{R}^{M}, the conjugate is f∗(v)=max⁡u∈RM⟨u,v⟩−12∥u∥22.f^{*}({\bm{v}})=\max_{{\bm{u}}\in\mathbb{R}^{M}}\langle{\bm{u}},{\bm{v}}\rangle-\frac{1}{2}\|{\bm{u}}\|^{2}_{2}. 令梯度 u↦⟨u,v⟩−12∥u∥22{\bm{u}}\mapsto\langle{\bm{u}},{\bm{v}}\rangle-\frac{1}{2}\|{\bm{u}}\|^{2}_{2} 为零,我们得到 u⋆=v{\bm{u}}^{\star}={\bm{v}}。将 u⋆{\bm{u}}^{\star} 代回,于是得到Setting the gradient u↦⟨u,v⟩−12∥u∥22{\bm{u}}\mapsto\langle{\bm{u}},{\bm{v}}\rangle-\frac{1}{2}\|{\bm{u}}\|^{2}_{2} to zero, we obtain u⋆=v{\bm{u}}^{\star}={\bm{v}}. Plugging u⋆{\bm{u}}^{\star} back, we therefore obtain f∗(v)=⟨u⋆,v⟩−12∥u⋆∥22=12∥v∥22.f^{*}({\bm{v}})=\langle{\bm{u}}^{\star},{\bm{v}}\rangle-\frac{1}{2}\|{\bm{u}}^{\star}\|^{2}_{2}=\frac{1}{2}\|{\bm{v}}\|^{2}_{2}. 因此,此情形下 f=f∗f=f^{*}。Therefore, f=f∗f=f^{*} in this case. 当 f(u)=⟨u,log⁡u⟩f({\bm{u}})=\langle{\bm{u}},\log{\bm{u}}\rangle,其中 dom⁡(f)=R+M\dom(f)=\mathbb{R}_{+}^{M} 时,u↦⟨u,v⟩−⟨u,log⁡u⟩{\bm{u}}\mapsto\langle{\bm{u}},{\bm{v}}\rangle-\langle{\bm{u}},\log{\bm{u}}\rangle 的最小值点为 u⋆=exp⁡(v−1⁡){\bm{u}}^{\star}=\exp({\bm{v}}-\operatorname{\mathbf{1}}),共轭为When f(u)=⟨u,log⁡u⟩f({\bm{u}})=\langle{\bm{u}},\log{\bm{u}}\rangle, with dom⁡(f)=R+M\dom(f)=\mathbb{R}_{+}^{M}, the minimizer of u↦⟨u,v⟩−⟨u,log⁡u⟩{\bm{u}}\mapsto\langle{\bm{u}},{\bm{v}}\rangle-\langle{\bm{u}},\log{\bm{u}}\rangle is u⋆=exp⁡(v−1⁡){\bm{u}}^{\star}=\exp({\bm{v}}-\operatorname{\mathbf{1}}) and the conjugate is f∗(v)=∑j=1Mexp⁡(vj−1).f^{*}({\bm{v}})=\sum_{j=1}^{M}\exp(v_{j}-1).

更多示例可参见 [33] 或 [18]。See for instance [33] or [18] for many more examples.

约束定义域Constraining the domain

我们可以借助取值于扩展实数轴 R∪{∞}\mathbb{R}\cup\{\infty\} 的指示函数来施加约束,We can incorporate constraints using an indicator function with values in the extended real line R∪{∞}\mathbb{R}\cup\{\infty\},

ιC(u):={0 if u∈C+∞ otherwise .\iota_{\mathcal{C}}({\bm{u}})\coloneqq\begin{cases}0&\text{ if }{\bm{u}}\in\mathcal{C}\\ +\infty&\text{ otherwise }\end{cases}.
例 13.2.3(约束的引入)。Example 13.2.3 (Incorporating constraints).
若 f(u)=ιC(u)f({\bm{u}})=\iota_{\mathcal{C}}({\bm{u}}),其中 C\mathcal{C} 为凸集,则If f(u)=ιC(u)f({\bm{u}})=\iota_{\mathcal{C}}({\bm{u}}), where C\mathcal{C} is a convex set, then f∗(v)=sup⁡u∈dom⁡(f) ⟨u,v⟩−f(u)=sup⁡u∈C ⟨u,v⟩:=σC(v),f^{*}({\bm{v}})=\sup_{{\bm{u}}\in\dom(f)} \ \langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}})=\sup_{{\bm{u}}\in\mathcal{C}} \ \langle{\bm{u}},{\bm{v}}\rangle\coloneqq\sigma_{\mathcal{C}}({\bm{v}}), 这称为 C\mathcal{C} 的支撑函数。相应的 argmax(假定其存在),which is known as the support function of C\mathcal{C}. The corresponding argmax (assuming that it exists), v↦arg max⁡u∈C⟨u,v⟩,{\bm{v}}\mapsto\argmax_{{\bm{u}}\in\mathcal{C}}\langle{\bm{u}},{\bm{v}}\rangle, 称为 C\mathcal{C} 的线性最大化预言机(LMO)。作为另一个例子,若 f(u)=⟨u,log⁡u⟩+ι△M(u)f({\bm{u}})=\langle{\bm{u}},\log{\bm{u}}\rangle+\iota_{\triangle^{M}}({\bm{u}}),则is known as the linear maximization oracle (LMO) of C\mathcal{C}. As another example, if f(u)=⟨u,log⁡u⟩+ι△M(u)f({\bm{u}})=\langle{\bm{u}},\log{\bm{u}}\rangle+\iota_{\triangle^{M}}({\bm{u}}) then f∗(v)=logsumexp(v)=log⁡∑i=1Mexp⁡(vi).f^{*}({\bm{v}})=\mathrm{logsumexp}({\bm{v}})=\log\sum_{i=1}^{M}\exp(v_{i}). 其证明推迟至命题 13.5.4。We postpone a proof to Proposition 13.5.4.

13.2.3 性质Properties

凸共轭具有若干有用的性质,现总结如下。The conjugate enjoys several useful properties, that we now summarize.

命题 13.2.4(凸共轭的性质)。Proposition 13.2.4 (Convex conjugate properties).
1. 凸性:对所有 f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\},f∗(v)f^{*}({\bm{v}}) 均为凸函数(即使 ff 非凸)。Convexity: f∗(v)f^{*}({\bm{v}}) is a convex function for all f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\} (even if ff is nonconvex). 2. Fenchel-Young 不等式:对所有 u,v∈RM{\bm{u}},{\bm{v}}\in\mathbb{R}^{M}Fenchel-Young inequality: for all u,v∈RM{\bm{u}},{\bm{v}}\in\mathbb{R}^{M} f(u)+f∗(v)−⟨u,v⟩≥0.f({\bm{u}})+f^{*}({\bm{v}})-\langle{\bm{u}},{\bm{v}}\rangle\geq 0. 3. 梯度:若定义 13.2.1 中的上确界被唯一取到,则 f∗(v)f^{*}({\bm{v}}) 在 v{\bm{v}} 处可微,其梯度为Gradient: if the supremum in Definition 13.2.1 is uniquely achieved, then f∗(v)f^{*}({\bm{v}}) is differentiable at v{\bm{v}} and its gradient is ∇f∗(v)=arg max⁡u∈dom⁡(f)⟨u,v⟩−f(u).\nabla f^{*}({\bm{v}})=\argmax_{{\bm{u}}\in\dom(f)}\langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}}). 否则,f∗(v)f^{*}({\bm{v}}) 在 v{\bm{v}} 处次可微,此时得到的是次梯度。Otherwise, f∗(v)f^{*}({\bm{v}}) is sub-differentiable at v{\bm{v}} and we get a sub-gradient instead. 4. 映射:若 ff 与 f∗f^{*} 均可微,则Maps: If ff and f∗f^{*} are differentiable, then v=∇f(u)  ⟺  u=∇f∗(v)  ⟺  f∗(v)+f(u)−⟨u,v⟩=0.{\bm{v}}=\nabla f({\bm{u}})\iff{\bm{u}}=\nabla f^{*}({\bm{v}})\iff f^{*}({\bm{v}})+f({\bm{u}})-\langle{\bm{u}},{\bm{v}}\rangle=0. 5. 双共轭:f=f∗∗f=f^{**} 当且仅当 ff 凸且闭(即其下水平集构成闭集);否则 f∗∗≤ff^{**}\leq f。Biconjugate: f=f∗∗f=f^{**} if and only if ff is convex and closed (i.e., its sublevel sets form a closed set), otherwise f∗∗≤ff^{**}\leq f.
证明 13.2.5。Proof 13.2.5.
  1. 1.

    此结论源于如下事实:若 gg 关于 v{\bm{v}} 为凸,则 v↦sup⁡u∈Cg(u,v){\bm{v}}\mapsto\sup_{{\bm{u}}\in\mathcal{C}}g({\bm{u}},{\bm{v}}) 为凸。注意,即便 gg 关于 u{\bm{u}} 非凸,该结论依然成立。此处 g(u,v)=⟨u,v⟩−f(u)g({\bm{u}},{\bm{v}})=\langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}}) 关于 v{\bm{v}} 为仿射,因而关于 v{\bm{v}} 为凸。This follows from the fact that v↦sup⁡u∈Cg(u,v){\bm{v}}\mapsto\sup_{{\bm{u}}\in\mathcal{C}}g({\bm{u}},{\bm{v}}) is convex if gg is convex in v{\bm{v}}. Note that this is true even if gg is nonconvex in u{\bm{u}}. Here, g(u,v)=⟨u,v⟩−f(u)g({\bm{u}},{\bm{v}})=\langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}}), which is affine in v{\bm{v}} and therefore convex in v{\bm{v}}.

  2. 2.

    此结论由定义 13.2.1 直接得出。This follows immediately from Definition 13.2.1.

  3. 3.

    此结论由 Danskin 定理得出,该定理已在 11.2 节中回顾。另一种理解方式,是注意到This follows from Danskin’s theorem, reviewed in Section 11.2. Another way to see this is by observing that

    f∗(v)\displaystyle f^{*}({\bm{v}}) =⟨g,v⟩−f(g)\displaystyle=\langle{\bm{g}},{\bm{v}}\rangle-f({\bm{g}})
    f∗(v′)\displaystyle f^{*}({\bm{v}}^{\prime}) ≥⟨g,v′⟩−f(g),\displaystyle\geq\langle{\bm{g}},{\bm{v}}^{\prime}\rangle-f({\bm{g}}),

    其中 g:=arg max⁡u∈dom⁡(f)⟨u,v⟩−f(u){\bm{g}}\coloneqq\displaystyle{\argmax_{{\bm{u}}\in\dom(f)}}\langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}})。将两式相减,即得where g:=arg max⁡u∈dom⁡(f)⟨u,v⟩−f(u){\bm{g}}\coloneqq\displaystyle{\argmax_{{\bm{u}}\in\dom(f)}}\langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}}). Subtracting the two, we obtain

    f∗(v′)≥f∗(v)+⟨g,v′−v⟩.f^{*}({\bm{v}}^{\prime})\geq f^{*}({\bm{v}})+\langle{\bm{g}},{\bm{v}}^{\prime}-{\bm{v}}\rangle.

    现在,利用 f∗f^{*} 的凸性以及定义 15.4.10,可得 g=∇f∗(v){\bm{g}}=\nabla f^{*}({\bm{v}})。Now, using that f∗f^{*} is convex and Definition 15.4.10, we obtain that g=∇f∗(v){\bm{g}}=\nabla f^{*}({\bm{v}}).

  4. 4.

    例如参见 [15, 命题 16.10]。See, e.g., [15, Proposition 16.10].

  5. 5.

    参见 [33, 3.3 节]。See [33, Section 3.3].

13.2.4 共轭运算法则Conjugate calculus

推导凸共轭的表达式一般可能相当困难,但在某些情形下,可以借助简单的法则,由其他共轭推导出所需的共轭。While deriving a convex conjugate expression can be difficult in general, in some cases, it is possible to use simple rules to derive conjugates in terms of other conjugates.

命题 13.2.6(共轭运算法则)。Proposition 13.2.6 (Conjugate calculus rules).
1. 函数的可分离和:若 f(u)=∑j=1Mfj(uj)f({\bm{u}})=\sum_{j=1}^{M}f_{j}(u_{j}),则Separable sum of functions: if f(u)=∑j=1Mfj(uj)f({\bm{u}})=\sum_{j=1}^{M}f_{j}(u_{j}), then f∗(v)=∑j=1Mfj∗(vj).f^{*}({\bm{v}})=\sum_{j=1}^{M}f^{*}_{j}(v_{j}). 2. 标量乘法:若 f(u)=c⋅g(u)f({\bm{u}})=c\cdot g({\bm{u}}),其中 c>0c>0,则Scalar multiplication: if f(u)=c⋅g(u)f({\bm{u}})=c\cdot g({\bm{u}}), for c>0c>0, then f∗(v)=c⋅g∗(v/c).f^{*}({\bm{v}})=c\cdot g^{*}({\bm{v}}/c). 3. 加上仿射函数与平移:若 f(u)=g(u)+⟨α,u⟩+βf({\bm{u}})=g({\bm{u}})+\langle{\bm{\alpha}},{\bm{u}}\rangle+\beta,则Addition to an affine function and translation: if f(u)=g(u)+⟨α,u⟩+βf({\bm{u}})=g({\bm{u}})+\langle{\bm{\alpha}},{\bm{u}}\rangle+\beta, then f∗(v)=g∗(v−α)−β.f^{*}({\bm{v}})=g^{*}({\bm{v}}-{\bm{\alpha}})-\beta. 4. 与可逆线性映射复合:若 f(u)=g(Mu)f({\bm{u}})=g(M{\bm{u}}),其中 x↦Mxx\mapsto M{\bm{x}} 为可逆线性映射,则Composition with an invertible linear map: if f(u)=g(Mu)f({\bm{u}})=g(M{\bm{u}}), where x↦Mxx\mapsto M{\bm{x}} is an invertible linear map, then f∗(v)=g∗(M−Tv).f^{*}({\bm{v}})=g^{*}(M^{-T}{\bm{v}}). 5. 函数的不可分离和:若 h1h_{1} 与 h2h_{2} 均为凸函数,则 (h1+h2)∗=h1∗□h2∗(h_{1}+h_{2})^{*}=h_{1}^{*}\square h_{2}^{*},其中 □\square 为下确卷积算子。Non-separable sum of functions: if h1h_{1} and h2h_{2} are convex functions, then (h1+h2)∗=h1∗□h2∗(h_{1}+h_{2})^{*}=h_{1}^{*}\square h_{2}^{*}, where □\square is the infimal convolution operator.

13.2.5 快速 Legendre 变换Fast Legendre transform

当解析表达式不可用时,可借助数值方案近似计算该变换/共轭。当 ff 为凸时,由于 −f-f 为凹,定义 13.2.1 中的极大化即为凹函数的极大化。因此,借助经典的约束优化迭代算法,如投影梯度下降(16.3 节)或条件梯度法(又称 Frank-Wolfe 算法 [100]),可在多项式时间内以任意精度算出该共轭。若不对 ff 作凸性假设,则 f∗(v)f^{*}({\bm{v}}) 可近似为When an analytical expression is not available, we can resort to numerical schemes to approximately compute the transform / conjugate. When ff is convex, because −f-f is concave, the maximization in Definition 13.2.1 is that of a concave function. Therefore, the conjugate can be computed to arbitrary precision in polynomial time using classical iterative algorithms for constrained optimization such as projected gradient descent (Section 16.3) or conditional gradient a.k.a. Frank-Wolfe [100]. Without convexity assumption on ff, f∗(v)f^{*}({\bm{v}}) can be approximated by

f∗(v)≈sup⁡u∈U⟨u,v⟩−f(u),f^{*}({\bm{v}})\approx\sup_{{\bm{u}}\in\mathcal{U}}\langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}}),

其中 U⊆dom⁡(f)\mathcal{U}\subseteq\dom(f) 是取值的离散网格。随后,我们可以利用线性时间 Legendre 变换算法 [123],针对若干个输入 v∈V{\bm{v}}\in\mathcal{V} 计算对应的 f∗(v)f^{*}({\bm{v}}),其中 V⊆dom⁡(f∗)\mathcal{V}\subseteq\dom(f^{*}) 是另一个离散网格。其复杂度为 O(∣U∣⋅∣V∣)O(|\mathcal{U}|\cdot|\mathcal{V}|),随网格规模线性增长。然而,网格规模通常为 ∣U∣=∣V∣=O(NM)|\mathcal{U}|=|\mathcal{V}|=O(N^{M}),即在 MM 个维度上各取 NN 个均匀分布的点。因此,该方法仅限于低维情形,例如 M∈{1,2,3}M\in\{1,2,3\}。where U⊆dom⁡(f)\mathcal{U}\subseteq\dom(f) is a discrete grid of values. We can then compute f∗(v)f^{*}({\bm{v}}) for several inputs v∈V{\bm{v}}\in\mathcal{V} using the linear-time Legendre transform algorithm [123], where V⊆dom⁡(f∗)\mathcal{V}\subseteq\dom(f^{*}) is another discrete grid. The complexity is O(∣U∣⋅∣V∣)O(|\mathcal{U}|\cdot|\mathcal{V}|), which is linear in the grid sizes. However, the grid sizes are typically ∣U∣=∣V∣=O(NM)|\mathcal{U}|=|\mathcal{V}|=O(N^{M}), for NN equally-distributed points in each of the MM dimensions. Therefore, this approach is limited to small-dimensional settings, e.g., M∈{1,2,3}M\in\{1,2,3\}.

13.3 对偶方法13.3 Dual approach

前面我们介绍了如何通过与原始空间中的正则化项 RR 做下确卷积来平滑一个函数。现在,我们介绍另一种做法:改为对函数的 Legendre-Fenchel 变换(凸共轭)进行正则化,从而平滑该函数。这种对偶的等价方法在数学上往往更为方便。Previously, we presented how to smooth a function by performing its infimal convolution with a primal-space regularization RR. We now present how to smooth a function by regularizing its Legendre-Fenchel transform (convex conjugate) instead. This dual, equivalent approach, is often mathematically more convenient.

13.3.1 强凸性与光滑性之间的对偶性Duality between strong convexity and smoothness

我们首先陈述一个众所周知的结果,本节的全部内容都建立在它之上:光滑性与强凸性彼此对偶 [96, 103, 18, 215]。We begin by stating a well-known result that will underpin this whole section: smoothness and strong convexity are dual to each other [96, 103, 18, 215].

命题 13.3.1(强凸性与光滑性之间的对偶性)。Proposition 13.3.1 (Duality between strong convexity and smoothness).
ff 在 dom⁡(f)\dom(f) 上关于范数 ∥⋅∥\|\cdot\| 为 1μ\frac{1}{\mu}-强凸,当且仅当 f∗f^{*} 在 dom⁡(f∗)\dom(f^{*}) 上关于对偶范数 ∥⋅∥∗\|\cdot\|_{*} 为 μ\mu-光滑。ff is 1μ\frac{1}{\mu}-strongly convex w.r.t. the norm ∥⋅∥\|\cdot\| over dom⁡(f)\dom(f) if and only if f∗f^{*} is μ\mu-smooth w.r.t. the dual norm ∥⋅∥∗\|\cdot\|_{*} over dom⁡(f∗)\dom(f^{*}).

关于光滑性与强凸性这两个概念的回顾,见 15.4 节。表 13.2 给出了强凸与光滑共轭对的两个例子。For a review of the notions of smoothness and strong convexity, see Section 15.4. We give two examples of strongly-convex and smooth conjugate pairs in Table 13.2.

表 13.2:强凸与光滑共轭对的示例。Table 13.2: Examples of strongly-convex and smooth conjugate pairs.
函数Function 范数Norm 定义域Domain 共轭Conjugate 对偶范数Dual norm 对偶定义域Dual domain
12∥u∥22\frac{1}{2}\|{\bm{u}}\|_{2}^{2} ∥⋅∥2\|\cdot\|_{2} RM\mathbb{R}^{M} 12∥v∥22\frac{1}{2}\|{\bm{v}}\|_{2}^{2} ∥⋅∥2\|\cdot\|_{2} RM\mathbb{R}^{M}
⟨u,log⁡u⟩\langle{\bm{u}},\log{\bm{u}}\rangle ∥⋅∥1\|\cdot\|_{1} △M\triangle^{M} logsumexp(v)\mathrm{logsumexp}({\bm{v}}) ∥⋅∥∞\|\cdot\|_{\infty} RM\mathbb{R}^{M}

13.3.2 通过对偶正则化进行平滑Smoothing by dual regularization

光滑性与强凸性之间的对偶性提示了一种平滑函数 f ⁣:RM→Rf\colon\mathbb{R}^{M}\to\mathbb{R} 的通用方法,即经由对偶空间来完成。The duality between smoothness and strong convexity suggests a generic approach in order to smooth a function f ⁣:RM→Rf\colon\mathbb{R}^{M}\to\mathbb{R}, by going through the dual space.

  1. 1.

    计算共轭 f∗f^{*}:Compute the conjugate f∗f^{*}:

    f∗(v):=sup⁡u∈dom⁡(f)⟨u,v⟩−f(u).f^{*}({\bm{v}})\coloneqq\sup_{{\bm{u}}\in\dom(f)}\langle{\bm{u}},{\bm{v}}\rangle-f({\bm{u}}).
  2. 2.

    为共轭加上强凸正则化项 Ω\Omega:Add strongly-convex regularization Ω\Omega to the conjugate:

    fΩ∗(v):=f∗(v)+Ω(v).f_{\Omega}^{*}({\bm{v}})\coloneqq f^{*}({\bm{v}})+\Omega({\bm{v}}). (13.3)
  3. 3.

    再回到原始空间,即计算 fΩ∗f^{*}_{\Omega} 的共轭:Go back to the primal space, by computing the conjugate of fΩ∗f^{*}_{\Omega}:

    fΩ(u):=fΩ∗∗(u)=max⁡v∈RM⟨u,v⟩−fΩ∗(v).f_{\Omega}({\bm{u}})\coloneqq f^{**}_{\Omega}({\bm{u}})=\max_{{\bm{v}}\in\mathbb{R}^{M}}\langle{\bm{u}},{\bm{v}}\rangle-f_{\Omega}^{*}({\bm{v}}).

注意,u{\bm{u}} 与 v{\bm{v}} 属于不同的空间,即 u∈dom⁡(f){\bm{u}}\in\dom(f) 与 v∈dom⁡(f∗){\bm{v}}\in\dom(f^{*})。根据命题 13.3.1,若 Ω\Omega 为 μ\mu-强凸,则 fΩ(u)f_{\Omega}({\bm{u}}) 为 1μ\frac{1}{\mu}-光滑。此外,根据命题 13.2.4,即便 ff 非凸,fΩ(u)f_{\Omega}({\bm{u}}) 也是凸的。因此,fΩ(u)f_{\Omega}({\bm{u}}) 是 f(u)f({\bm{u}}) 的一个光滑且凸的松弛。Note that u{\bm{u}} and v{\bm{v}} belong to different spaces, i.e., u∈dom⁡(f){\bm{u}}\in\dom(f) and v∈dom⁡(f∗){\bm{v}}\in\dom(f^{*}). Following Proposition 13.3.1, if Ω\Omega is μ\mu-strongly convex, then fΩ(u)f_{\Omega}({\bm{u}}) is 1μ\frac{1}{\mu}-smooth. Furthermore, following Proposition 13.2.4, fΩ(u)f_{\Omega}({\bm{u}}) is convex, even if ff is nonconvex. Therefore, fΩ(u)f_{\Omega}({\bm{u}}) is a smooth and convex relaxation of f(u)f({\bm{u}}).

步骤 11 与 33 最具挑战性,因为二者都需要推导共轭。一般情况下解析解可能并不存在,但在某些简单情形下确实存在,下面我们对此加以说明。Steps 11 and 33 are the most challenging, as they both require the derivation of a conjugate. While an analytical solution may not exist in general, in some simple cases, there is, as we now illustrate.

例 13.3.2(通过对偶正则化平滑 11-范数)。Example 13.3.2 (Smoothing the 11-norm via dual regularization).
我们重新审视例 13.1.5,此次改从对偶的视角出发。我们希望将 11-范数 f(u):=∥u∥1=∑j=1M∣uj∣f({\bm{u}})\coloneqq\|{\bm{u}}\|_{1}=\sum_{j=1}^{M}|u_{j}| 平滑化。We revisit Example 13.1.5, this time from the dual perspective. We wish to smooth out the 11-norm f(u):=∥u∥1=∑j=1M∣uj∣f({\bm{u}})\coloneqq\|{\bm{u}}\|_{1}=\sum_{j=1}^{M}|u_{j}|. 1. 计算共轭。任意范数 ∥⋅∥\|\cdot\| 的共轭,即其对偶范数的单位球 {v∈RM ⁣:∥v∥∗≤1}\{{\bm{v}}\in\mathbb{R}^{M}\colon\|{\bm{v}}\|_{*}\leq 1\} 的指示函数(参见例如 [33, 例 3.26])。∥u∥1\|{\bm{u}}\|_{1} 的对偶范数为 ∥v∥∞\|{\bm{v}}\|_{\infty}。此外,Compute the conjugate. The conjugate of any norm ∥⋅∥\|\cdot\| is the indicator function of the dual norm’s unit ball {v∈RM ⁣:∥v∥∗≤1}\{{\bm{v}}\in\mathbb{R}^{M}\colon\|{\bm{v}}\|_{*}\leq 1\} (see e.g. [33, Example 3.26]). The dual norm of ∥u∥1\|{\bm{u}}\|_{1} is ∥v∥∞\|{\bm{v}}\|_{\infty}. Moreover, {v∈RM ⁣:∥v∥∞≤1}=[−1,1]M.\{{\bm{v}}\in\mathbb{R}^{M}\colon\|{\bm{v}}\|_{\infty}\leq 1\}=[-1,1]^{M}. 回顾到 ιC\iota_{\mathcal{C}} 是 C\mathcal{C} 的指示函数,由此得到Recalling that ιC\iota_{\mathcal{C}} is the indicator function of C\mathcal{C}, we obtain f∗(v)=ι[−1,1]M(v).f^{*}({\bm{v}})=\iota_{[-1,1]^{M}}({\bm{v}}). 2. 加入强凸正则化。我们加入二次正则化项 Ω(v):=12∥v∥22\Omega({\bm{v}})\coloneqq\frac{1}{2}\|{\bm{v}}\|_{2}^{2},以定义Adding strongly-convex regularization. We add quadratic regularization Ω(v):=12∥v∥22\Omega({\bm{v}})\coloneqq\frac{1}{2}\|{\bm{v}}\|_{2}^{2} to define fΩ∗(v):=ι[−1,1]M(v)+Ω(v).f^{*}_{\Omega}({\bm{v}})\coloneqq\iota_{[-1,1]^{M}}({\bm{v}})+\Omega({\bm{v}}). 3. 回到原问题。Going back to the primal. fΩ(u)=fΩ∗∗(u)=⟨u,v⋆⟩−Ω(v⋆)=∑i=1Mhuber(ui),f_{\Omega}({\bm{u}})=f_{\Omega}^{**}({\bm{u}})=\langle{\bm{u}},{\bm{v}}^{\star}\rangle-\Omega({\bm{v}}^{\star})=\sum_{i=1}^{M}\mathrm{huber}(u_{i}), 其中 v⋆=clip(u):=max⁡(min⁡(u,1),−1){\bm{v}}^{\star}=\mathrm{clip}\left({\bm{u}}\right)\coloneqq\max\left(\min\left({\bm{u}},1\right),-1\right)。where v⋆=clip(u):=max⁡(min⁡(u,1),−1){\bm{v}}^{\star}=\mathrm{clip}\left({\bm{u}}\right)\coloneqq\max\left(\min\left({\bm{u}},1\right),-1\right). 因此,我们的确从例 13.1.5 中恢复了 Huber 损失。We therefore indeed recover the Huber loss from Example 13.1.5.

ReLU 函数也可以用类似的方式平滑,我们将在 13.4 节中更详细地说明这一点。ReLU functions can be smoothed out in a similar way, as we see in more details in Section 13.4.

对偶方法使我们能够方便地借助原函数来界定平滑后的函数。The dual approach allows us to easily bound the smoothed function in terms of the original function.

命题 13.3.3(对平滑后的函数进行界定)。Proposition 13.3.3 (Bounding the smoothed function).
设 ff 为闭凸函数,Ω\Omega 为凸函数。若 Ω\Omega 满足:对任意 v∈dom⁡(Ω){\bm{v}}\in\dom(\Omega) 都有 LΩ≤Ω(v)≤UΩ\mathcal{L}_{\Omega}\leq\Omega({\bm{v}})\leq\mathcal{U}_{\Omega},则对任意 u∈RM{\bm{u}}\in\mathbb{R}^{M},Let ff be a closed convex function. Let Ω\Omega be a convex function. If Ω\Omega is such that LΩ≤Ω(v)≤UΩ\mathcal{L}_{\Omega}\leq\Omega({\bm{v}})\leq\mathcal{U}_{\Omega} for all v∈dom⁡(Ω){\bm{v}}\in\dom(\Omega), then for all u∈RM{\bm{u}}\in\mathbb{R}^{M}, f(u)−UΩ≤fΩ(u)≤f(u)−LΩ.f({\bm{u}})-\mathcal{U}_{\Omega}\leq f_{\Omega}({\bm{u}})\leq f({\bm{u}})-\mathcal{L}_{\Omega}.
证明 13.3.4。Proof 13.3.4.

我们定义Let us define

v⋆\displaystyle{\bm{v}}^{\star} :=arg max⁡v∈RM⟨u,v⟩−f∗(v)\displaystyle\coloneqq\argmax_{{\bm{v}}\in\mathbb{R}^{M}}\langle{\bm{u}},{\bm{v}}\rangle-f^{*}({\bm{v}})
vΩ⋆\displaystyle{\bm{v}}^{\star}_{\Omega} :=arg max⁡v∈RM⟨u,v⟩−fΩ∗(v),\displaystyle\coloneqq\argmax_{{\bm{v}}\in\mathbb{R}^{M}}\langle{\bm{u}},{\bm{v}}\rangle-f^{*}_{\Omega}({\bm{v}}),

其中我们回顾 fΩ∗:=f∗+Ωf^{*}_{\Omega}\coloneqq f^{*}+\Omega。于是对任意 u∈RM{\bm{u}}\in\mathbb{R}^{M},都有where we recall that fΩ∗:=f∗+Ωf^{*}_{\Omega}\coloneqq f^{*}+\Omega. We then have for all u∈RM{\bm{u}}\in\mathbb{R}^{M}

fΩ(u)\displaystyle f_{\Omega}({\bm{u}}) =⟨u,vΩ⋆⟩−fΩ∗(vΩ⋆)\displaystyle=\langle{\bm{u}},{\bm{v}}^{\star}_{\Omega}\rangle-f_{\Omega}^{*}({\bm{v}}^{\star}_{\Omega})
≥⟨u,v⋆⟩−fΩ∗(v⋆)\displaystyle\geq\langle{\bm{u}},{\bm{v}}^{\star}\rangle-f_{\Omega}^{*}({\bm{v}}^{\star})
=⟨u,v⋆⟩−f∗(v⋆)−Ω(v⋆)\displaystyle=\langle{\bm{u}},{\bm{v}}^{\star}\rangle-f^{*}({\bm{v}}^{\star})-\Omega({\bm{v}}^{\star})
=f∗∗(u)−Ω(v⋆)\displaystyle=f^{**}({\bm{u}})-\Omega({\bm{v}}^{\star})
=f(u)−Ω(v⋆),\displaystyle=f({\bm{u}})-\Omega({\bm{v}}^{\star}),

类似地,Similarly,

f(u)−Ω(vΩ⋆)\displaystyle f({\bm{u}})-\Omega({\bm{v}}^{\star}_{\Omega}) =⟨u,v⋆⟩−f∗(v⋆)−Ω(vΩ⋆)\displaystyle=\langle{\bm{u}},{\bm{v}}^{\star}\rangle-f^{*}({\bm{v}}^{\star})-\Omega({\bm{v}}^{\star}_{\Omega})
≥⟨u,vΩ⋆⟩−fΩ∗(vΩ⋆)\displaystyle\geq\langle{\bm{u}},{\bm{v}}^{\star}_{\Omega}\rangle-f_{\Omega}^{*}({\bm{v}}^{\star}_{\Omega})
=fΩ∗∗(u)\displaystyle=f_{\Omega}^{**}({\bm{u}})
=fΩ(u).\displaystyle=f_{\Omega}({\bm{u}}).

结合二者,并利用对任意 v∈dom⁡(Ω){\bm{v}}\in\dom(\Omega) 都有 LΩ≤Ω(v)≤UΩ\mathcal{L}_{\Omega}\leq\Omega({\bm{v}})\leq\mathcal{U}_{\Omega} 这一事实,我们得到Combining the two with LΩ≤Ω(v)≤UΩ\mathcal{L}_{\Omega}\leq\Omega({\bm{v}})\leq\mathcal{U}_{\Omega} for all v∈dom⁡(Ω){\bm{v}}\in\dom(\Omega), we obtain

f(u)−UΩ\displaystyle f({\bm{u}})-\mathcal{U}_{\Omega} ≤f(u)−Ω(v⋆)\displaystyle\leq f({\bm{u}})-\Omega({\bm{v}}^{\star})
≤fΩ(u)\displaystyle\leq f_{\Omega}({\bm{u}})
≤f(u)−Ω(vΩ⋆)\displaystyle\leq f({\bm{u}})-\Omega({\bm{v}}^{\star}_{\Omega})
≤f(u)−LΩ.\displaystyle\leq f({\bm{u}})-\mathcal{L}_{\Omega}.
注 13.3.5(该梯度几乎处处可微)。Remark 13.3.5 (The gradient is differentiable almost everywhere).
由命题 13.2.4,fΩ(u)f_{\Omega}({\bm{u}}) 的梯度等于From Proposition 13.2.4, the gradient of fΩ(u)f_{\Omega}({\bm{u}}) equals ∇fΩ(u)=arg max⁡v∈RM⟨u,v⟩−fΩ∗(v).\nabla f_{\Omega}({\bm{u}})=\argmax_{{\bm{v}}\in\mathbb{R}^{M}}\langle{\bm{u}},{\bm{v}}\rangle-f_{\Omega}^{*}({\bm{v}}). 若 Ω\Omega 强凸,则 fΩf_{\Omega} 光滑,即 ∇fΩ\nabla f_{\Omega} Lipschitz 连续。由第 2.7.1 节回顾的 Rademacher 定理,此时 ∇fΩ\nabla f_{\Omega} 几乎处处可微(也就是说,fΩf_{\Omega} 几乎处处二次可微)。后文中,我们将利用这一性质来定义阶跃函数与 argmax 算子的几乎处处连续可微松弛。If Ω\Omega is strongly convex, then fΩf_{\Omega} is smooth, meaning that ∇fΩ\nabla f_{\Omega} is Lipschitz continuous. From Rademacher’s theorem reviewed in Section 2.7.1, ∇fΩ\nabla f_{\Omega} is then differentiable almost everywhere (that is, fΩf_{\Omega} is twice differentiable almost everywhere). We use this property in the sequel to define continuous differentiable almost everywhere relaxations of step functions and argmax operators.

13.3.3 原始正则化与对偶正则化的等价性Equivalence between primal and dual regularizations

至此,我们已经看到两种获得函数 ff 的光滑近似的方法。第一种方法基于下确卷积 f□Rf\square R,其中 R ⁣:dom⁡(f)→RR\colon\dom(f)\to\mathbb{R} 表示原始正则化;第二种方法则基于用某个对偶正则化 Ω\Omega 对 ff 的 Legendre-Fenchel 变换(凸共轭)f∗f^{*} 进行正则化,以定义 fΩ=(f∗+Ω)∗f_{\Omega}=(f^{*}+\Omega)^{*}。结果表明,这两种方法是等价的。So far, we saw two approaches to obtain a smooth approximation of a function ff. The first approach is based on the infimal convolution f□Rf\square R, where R ⁣:dom⁡(f)→RR\colon\dom(f)\to\mathbb{R} denotes primal regularization. The second approach is based on regularizing the Legendre-Fenchel transform (convex conjugate) f∗f^{*} of ff with some dual regularization Ω\Omega, to define fΩ=(f∗+Ω)∗f_{\Omega}=(f^{*}+\Omega)^{*}. It turns out that both approaches are equivalent.

命题 13.3.6(原始正则化与对偶正则化的等价性)。Proposition 13.3.6 (Equivalence between primal and dual regularizations).
设 f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\} 与 R ⁣:RM→R∪{∞}R\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\} 均为凸且闭,则 fΩ=(f∗+Ω)∗=f□Rf_{\Omega}=(f^{*}+\Omega)^{*}=f\square R,其中 Ω=R∗\Omega=R^{*}。Let f ⁣:RM→R∪{∞}f\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\} and R ⁣:RM→R∪{∞}R\colon\mathbb{R}^{M}\to\mathbb{R}\cup\{\infty\}, both convex and closed. Then, fΩ=(f∗+Ω)∗=f□Rf_{\Omega}=(f^{*}+\Omega)^{*}=f\square R with Ω=R∗\Omega=R^{*}.
证明 13.3.7。Proof 13.3.7.

我们有We have

fΩ(u)=(f∗+Ω)∗(u)=sup⁡v∈dom⁡(f∗)⟨u,v⟩−f∗(v)−Ω(v).f_{\Omega}({\bm{u}})=(f^{*}+\Omega)^{*}({\bm{u}})=\sup_{{\bm{v}}\in\dom(f^{*})}\langle{\bm{u}},{\bm{v}}\rangle-f^{*}({\bm{v}})-\Omega({\bm{v}}).

若 h1h_{1} 与 h2h_{2} 为凸,则 (h1+h2)∗=h1∗□h2∗(h_{1}+h_{2})^{*}=h_{1}^{*}\square h_{2}^{*} [18, 定理 4.17]。利用 h1=f∗h_{1}=f^{*} 与 h2=Ω=R∗h_{2}=\Omega=R^{*},并考虑到 f∗∗=ff^{**}=f 与 R∗∗=RR^{**}=R(因为二者既凸又闭,见命题 13.2.4),即可得到所需结果。If h1h_{1} and h2h_{2} are convex, we have (h1+h2)∗=h1∗□h2∗(h_{1}+h_{2})^{*}=h_{1}^{*}\square h_{2}^{*} [18, Theorem 4.17]. Using h1=f∗h_{1}=f^{*} and h2=Ω=R∗h_{2}=\Omega=R^{*} gives the desired result using that f∗∗=ff^{**}=f and R∗∗=RR^{**}=R since both are convex and closed (see Proposition 13.2.4).

特别地,取 Ω=12∥⋅∥22=Ω∗\Omega=\frac{1}{2}\|\cdot\|^{2}_{2}=\Omega^{*},这表明 Moreau 包络可以等价地写成In particular, with Ω=12∥⋅∥22=Ω∗\Omega=\frac{1}{2}\|\cdot\|^{2}_{2}=\Omega^{*}, this shows that the Moreau envelope can equivalently be written as

envf=fΩ=fΩ∗.\mathrm{env}_{f}=f_{\Omega}=f_{\Omega^{*}}.

鉴于原始方法与对偶方法之间的等价性,采用哪一种方法主要取决于具体情形下数学上或算法上的便利性。Given the equivalence between the primal and dual approaches, using one approach or the other is mainly a matter of mathematical or algorithmic convenience, depending on the case.

在本书中,我们关注平滑技术在可微编程中的应用;至于其在非光滑优化中的应用,请参见 [144, 19]。In this book, we focus on applications of smoothing techniques to differentiable programming. For applications to non-smooth optimization, see [144, 19].

13.3.4 正则化的缩放Regularization scaling

对偶方法Dual approach

若 Ω\Omega 是 11-强凸的,则 fΩf_{\Omega} 构成原函数 ff 的一个 11-光滑近似。为控制该近似的光滑程度,我们用 εΩ\varepsilon\Omega 作正则化,其中 ε>0\varepsilon>0,并定义If Ω\Omega is 11-strongly convex, then fΩf_{\Omega} is a 11-smooth approximation of the original function ff. To control the smoothness of the approximation, we regularize with εΩ\varepsilon\Omega for ε>0\varepsilon>0, defining

fεΩ(u):=(f∗+εΩ)∗(u)=sup⁡v∈dom⁡(f∗)⟨u,v⟩−f∗(v)−εΩ(v).f_{\varepsilon\Omega}({\bm{u}})\coloneqq(f^{*}+\varepsilon\Omega)^{*}({\bm{u}})=\sup_{{\bm{v}}\in\dom(f^{*})}\langle{\bm{u}},{\bm{v}}\rangle-f^{*}({\bm{v}})-\varepsilon\Omega({\bm{v}}).

据此,梯度可表示为Consequently, the gradient is given by

∇fεΩ(u)=arg max⁡v∈dom⁡(f∗)⟨u,v⟩−f∗(v)−εΩ(v).\nabla f_{\varepsilon\Omega}({\bm{u}})=\argmax_{{\bm{v}}\in\dom(f^{*})}\langle{\bm{u}},{\bm{v}}\rangle-f^{*}({\bm{v}})-\varepsilon\Omega({\bm{v}}).

该表述对任意闭凸的 ff 均成立。平滑所带来的近似误差可用命题 13.3.3 加以量化。只要对所有 v∈dom⁡(Ω){\bm{v}}\in\dom(\Omega) 都有 LΩ≤Ω(v)≤UΩ\mathcal{L}_{\Omega}\leq\Omega({\bm{v}})\leq\mathcal{U}_{\Omega},便有This formulation works for any closed convex ff. The approximation error induced by the smoothing can be quantified using Proposition 13.3.3. Provided that LΩ≤Ω(v)≤UΩ\mathcal{L}_{\Omega}\leq\Omega({\bm{v}})\leq\mathcal{U}_{\Omega} for all v∈dom⁡(Ω){\bm{v}}\in\dom(\Omega), we have

f(u)−εUΩ≤fεΩ(u)≤f(u)−εLΩ.f({\bm{u}})-\varepsilon\mathcal{U}_{\Omega}\leq f_{\varepsilon\Omega}({\bm{u}})\leq f({\bm{u}})-\varepsilon\mathcal{L}_{\Omega}.
注 13.3.8(齐次情形)。Remark 13.3.8 (Homogeneous case).
若 ff 为 11 次正齐次(例如范数),则其共轭 f∗f^{*} 是满足 f∗=εf∗f^{*}=\varepsilon f^{*} 的指示函数。在这一特定设定下,我们得到如下缩放关系:In the special case where ff is positively homogeneous of degree 11 (e.g., a norm), its conjugate f∗f^{*} is an indicator function satisfying f∗=εf∗f^{*}=\varepsilon f^{*}. In this specific setting, we recover the scaling relationships: fεΩ(u)\displaystyle f_{\varepsilon\Omega}({\bm{u}}) =εfΩ(u/ε)\displaystyle=\varepsilon f_{\Omega}({\bm{u}}/\varepsilon) ∇fεΩ(u)\displaystyle\nabla f_{\varepsilon\Omega}({\bm{u}}) =∇fΩ(u/ε).\displaystyle=\nabla f_{\Omega}({\bm{u}}/\varepsilon).

原始方法Primal approach

根据定义 13.1.2,若采用对偶正则化 εΩ\varepsilon\Omega,其中 ε>0\varepsilon>0 控制正则化强度,并假设 ff 为凸,则对应的原始正则化为 R=εΩ∗(⋅/ε)R=\varepsilon\Omega^{*}(\cdot/\varepsilon),且有Following Definition 13.1.2, if we use dual regularization εΩ\varepsilon\Omega, where ε>0\varepsilon>0 controls the regularization strength, assuming ff is convex, the corresponding primal regularization is R=εΩ∗(⋅/ε)R=\varepsilon\Omega^{*}(\cdot/\varepsilon) and we have

fεΩ=f□εΩ∗(⋅/ε).f_{\varepsilon\Omega}=f\square\varepsilon\Omega^{*}(\cdot/\varepsilon).

在 Ω(v)=12∥v∥22\Omega({\bm{v}})=\frac{1}{2}\|{\bm{v}}\|^{2}_{2} 这一特殊情形下,可得In the particular case Ω(v)=12∥v∥22\Omega({\bm{v}})=\frac{1}{2}\|{\bm{v}}\|^{2}_{2}, we have

R(u)=ε2∥u/ε∥22=12ε∥u∥22=1εΩ(u).R({\bm{u}})=\frac{\varepsilon}{2}\|{\bm{u}}/\varepsilon\|^{2}_{2}=\frac{1}{2\varepsilon}\|{\bm{u}}\|^{2}_{2}=\frac{1}{\varepsilon}\Omega({\bm{u}}).

由此得到We therefore get

fεΩ=f□1εΩ=1ε(εf□Ω)=1εenvεf.f_{\varepsilon\Omega}=f\square\frac{1}{\varepsilon}\Omega=\frac{1}{\varepsilon}(\varepsilon f\square\Omega)=\frac{1}{\varepsilon}\mathrm{env}_{\varepsilon f}.

13.3.5 广义熵Generalized entropies

当 π∈△M{\bm{\pi}}\in\triangle^{M} 为离散概率分布时,对偶正则化 Ω(π)\Omega({\bm{\pi}}) 的一个自然选择是负熵函数,亦称负熵。由于负熵在平滑的 max 算子中扮演重要角色,此处对其详加讨论。A natural choice of dual regularization Ω(π)\Omega({\bm{\pi}}), when π∈△M{\bm{\pi}}\in\triangle^{M} is a discrete probability distribution, is a negative entropy function, also known as negentropy. Since negentropies play a major role in smoothed max operators, we discuss them in detail here.

信息量与熵Information content and entropy

熵函数衡量的是随机变量、亦或分布的“意外”程度。要定义熵,首先须定义事件 EE 的信息量 I(E)I(E)。若事件的概率为 11,则该函数应返回 00,因为此时并无意外;反之,若事件的概率为 00,信息量应取到最大值,因为此时意外程度最大。此外,事件 EE 越可能发生,其意外程度便越小。因此,当 p(E)p(E) 增大时,I(E)I(E) 应当减小。此处略微滥用记号,我们也把随机变量 YY 的取值 yy 的信息量记作事件 {Y=y}\{Y=y\} 的信息量,An entropy function measures the amount of “surprise” of a random variable or equivalently of a distribution. To define an entropy, we must first define the information content I(E)I(E) of an event EE. The value returned by such a function should be 00 if the probability of the event is 11, as there is no surprise. Conversely, information content should attain its maximal value if the probability of the event is 00, as it is maximally surprising. Furthermore, the more probable an event EE is, the less surprising it is. Therefore, when p(E)p(E) increases, I(E)I(E) should decrease. Overloading the notation, we also write the information content of the outcome yy of a random variable YY as the information content of the event {Y=y}\{Y=y\},

I(y):=I({Y=y}).I(y)\coloneqq I(\{Y=y\}).

有了信息量函数,便可把随机变量 Y∈YY\in\mathcal{Y} 的熵 H(Y)H(Y) 定义为信息量的期望,Given an information content function, we can then define the entropy H(Y)H(Y) of a random variable Y∈YY\in\mathcal{Y} as the expected information content,

H(Y):=E[I(Y)].H(Y)\coloneqq\mathbb{E}[I(Y)].

信息量的定义不同,导出的熵的定义也便不同。Different definitions of information content lead to different definitions of entropy.

Shannon 熵Shannon’s entropy

满足上述各项标准的一种信息量定义是A definition of information content satisfying the criteria above is

I(E):=log⁡(1p(E))=−log⁡p(E).I(E)\coloneqq\log\left(\frac{1}{p(E)}\right)=-\log p(E).

事实上,−log⁡1=0-\log 1=0、−log⁡0=∞-\log 0=\infty 与 −log⁡-\log 在 (0,1](0,1] 上均为递减函数。采用这一信息量定义,便得到 Shannon 熵 [184]Indeed, −log⁡1=0-\log 1=0, −log⁡0=∞-\log 0=\infty and −log⁡-\log is a decreasing function over (0,1](0,1]. Using this information content definition leads to Shannon’s entropy [184]

H(Y)=E[I(Y)]=−∑y∈Yp(y)log⁡p(y).H(Y)=\mathbb{E}[I(Y)]=-\sum_{y\in\mathcal{Y}}p(y)\log p(y).

据此,我们可以把离散概率分布 π∈△M{\bm{\pi}}\in\triangle^{M} 的 Shannon 熵定义为We can therefore define the Shannon entropy of a discrete probability distribution π∈△M{\bm{\pi}}\in\triangle^{M} as

H(π)=−∑i=1Mπilog⁡πi=−⟨π,log⁡π⟩H({\bm{\pi}})=-\sum_{i=1}^{M}\pi_{i}\log\pi_{i}=-\langle{\bm{\pi}},\log{\bm{\pi}}\rangle

并将相应的负熵用作正则化and use the corresponding negentropy as regularization

Ω(π)=−H(π)=⟨π,log⁡π⟩.\Omega({\bm{\pi}})=-H({\bm{\pi}})=\langle{\bm{\pi}},\log{\bm{\pi}}\rangle.

该函数关于 ∥⋅∥1\|\cdot\|_{1} 在 △M\triangle^{M} 上是强凸的;但它并非在 R+M\mathbb{R}_{+}^{M} 上强凸,因为后者不是有界集,例如参见 [26, 命题 2]。由于式 13.3 将 Ω\Omega 加到 f∗f^{*} 上,因此只要 dom⁡(f∗)⊆△M\dom(f^{*})\subseteq\triangle^{M},我们便能以这样选取的 Ω\Omega 来平滑函数 ff。The function is strongly convex w.r.t. ∥⋅∥1\|\cdot\|_{1} over △M\triangle^{M}. However, it is not strongly convex over R+M\mathbb{R}_{+}^{M}, since this is not a bounded set; see for instance [26, Proposition 2]. Since Ω\Omega is added to f∗f^{*} in Eq. 13.3, we can therefore use this choice of Ω\Omega to smooth out a function ff if dom⁡(f∗)⊆△M\dom(f^{*})\subseteq\triangle^{M}.

Gini 熵Gini’s entropy

作为另一种选择,我们也可以把信息量定义为As an alternative, we can define information content as

I(E)=12(1−p(E)).I(E)=\frac{1}{2}(1-p(E)).

其中 12\frac{1}{2} 因子是为了后文在数学上处理方便。它同样满足信息量函数的各项要求。事实上:i)当 p(E)=1p(E)=1 时,I(E)=0I(E)=0;ii)当 p(E)=0p(E)=0 时,I(E)I(E) 取到最大值 12\frac{1}{2};iii)该函数关于 p(E)p(E) 递减。采用这一信息量定义,便得到 Gini 熵,又称 Gini 指数 [78]The 12\frac{1}{2} factor is for later mathematical convenience. This again satisfies the criteria of an information content function. Indeed, i) when p(E)=1p(E)=1, I(E)=0I(E)=0 ii) when p(E)=0p(E)=0, I(E)I(E) attains its maximum of 12\frac{1}{2} iii) the function is decreasing w.r.t. p(E)p(E). Using this information content definition leads to Gini’s entropy a.k.a. Gini index [78]

H(Y)=E[I(Y)]=12∑y∈Yp(y)(1−p(y)).H(Y)=\mathbb{E}[I(Y)]=\frac{1}{2}\sum_{y\in\mathcal{Y}}p(y)(1-p(y)).

我们可以借助 Gini 负熵,对所有 π∈△M{\bm{\pi}}\in\triangle^{M} 定义We can use Gini’s negative entropy to define for all π∈△M{\bm{\pi}}\in\triangle^{M}

Ω(π)=12⟨π,π−1⁡⟩=12(∥π∥22−1).\Omega({\bm{\pi}})=\frac{1}{2}\langle{\bm{\pi}},{\bm{\pi}}-\operatorname{\mathbf{1}}\rangle=\frac{1}{2}(\|{\bm{\pi}}\|^{2}_{2}-1).

该函数关于 ∥⋅∥2\|\cdot\|_{2} 在 RM\mathbb{R}^{M} 上是强凸的。因此只要 dom⁡(f∗)⊆RM\dom(f^{*})\subseteq\mathbb{R}^{M},我们便能以这样选取的 Ω\Omega 来平滑函数 ff。这意味着,可用 Gini 熵平滑的函数集合,大于可用 Shannon 熵平滑的函数集合。The function is strongly convex w.r.t. ∥⋅∥2\|\cdot\|_{2} over RM\mathbb{R}^{M}. We can therefore use this choice of Ω\Omega to smooth out a function ff if dom⁡(f∗)⊆RM\dom(f^{*})\subseteq\mathbb{R}^{M}. This means that the set of functions that we can smooth out with Gini entropy is larger than the set of functions we can smooth out with Shannon entropy.

图 13.5:分布 π=(π,1−π)∈△2{\bm{\pi}}=(\pi,1-\pi)\in\triangle^{2} 的 Tsallis 熵(π∈[0,1]\pi\in[0,1])。熵是一个非负的凹函数,在均匀分布处取到最大值,此处即 (0.5,0.5)(0.5,0.5)。负熵(又称 negentropy)可作为对偶正则化函数 Ω\Omega,在 dom⁡(f∗)⊆△M\dom(f^{*})\subseteq\triangle^{M} 时用以平滑函数 ff。Figure 13.5: Tsallis entropies of the distribution π=(π,1−π)∈△2{\bm{\pi}}=(\pi,1-\pi)\in\triangle^{2}, for π∈[0,1]\pi\in[0,1]. An entropy is a non-negative concave function that attains its maximum at the uniform distribution, here (0.5,0.5)(0.5,0.5). A negative entropy, a.k.a. negentropy, can be used as a dual regularization function Ω\Omega to smooth out a function ff when dom⁡(f∗)⊆△M\dom(f^{*})\subseteq\triangle^{M}.

Tsallis 熵Tsallis entropies

给定 α≥1\alpha\geq 1,一种更一般的信息量定义为Given α≥1\alpha\geq 1, a more general information content definition is

I(E)=1α(α−1)(1−p(E)α−1).I(E)=\frac{1}{\alpha(\alpha-1)}(1-p(E)^{\alpha-1}).

采用这一信息量定义,便得到 Tsallis 熵 [197]Using this definition leads to the Tsallis entropy [197]

H(Y)=E[I(Y)]=1α(α−1)∑y∈Yp(y)(1−pα−1(y)).H(Y)=\mathbb{E}[I(Y)]=\frac{1}{\alpha(\alpha-1)}\sum_{y\in\mathcal{Y}}p(y)(1-p^{\alpha-1}(y)).

Tsallis 熵在 α→1\alpha\to 1 的极限下退化为 Shannon 熵,而当 α=2\alpha=2 时则退化为 Gini 熵。借助 Tsallis 负熵,我们可以对任意 π∈△M{\bm{\pi}}\in\triangle^{M} 定义The Tsallis entropy recovers the Shannon entropy in the limit α→1\alpha\to 1 and the Gini entropy when α=2\alpha=2. We can use the Tsallis negative entropy to define for all π∈△M{\bm{\pi}}\in\triangle^{M}

Ω(π)=1α(α−1)⟨π,πα−1−1⁡⟩=1α(α−1)(∥π∥αα−1),\Omega({\bm{\pi}})=\frac{1}{\alpha(\alpha-1)}\langle{\bm{\pi}},{\bm{\pi}}^{\alpha-1}-\operatorname{\mathbf{1}}\rangle=\frac{1}{\alpha(\alpha-1)}(\|{\bm{\pi}}\|^{\alpha}_{\alpha}-1),

其中 ∥v∥p\|{\bm{v}}\|_{p} 为 pp-范数(p≥1p\geq 1)where ∥v∥p\|{\bm{v}}\|_{p} is the pp-norm for (p≥1p\geq 1)

∥v∥p:=(∑i=1Mvip)1p,\|{\bm{v}}\|_{p}\coloneqq\left(\sum_{i=1}^{M}v_{i}^{p}\right)^{\frac{1}{p}},

于是so that

∥v∥pp=∑i=1Mvip.\|{\bm{v}}\|_{p}^{p}=\sum_{i=1}^{M}v_{i}^{p}.

α→1\alpha\to 1(Shannon 熵)、α=1.5\alpha=1.5 与 α=2\alpha=2(Gini 熵)对应的 Tsallis 熵如图 13.5 和图 13.6 所示。Tsallis entropies for α→1\alpha\to 1 (Shannon entropy), α=1.5\alpha=1.5 and α=2\alpha=2 (Gini entropy) are illustrated in Fig. 13.5 and Fig. 13.6.

图 13.6:概率单纯形上 Tsallis 熵的等高线。Figure 13.6: Contours of Tsallis entropies on the probability simplex.

广义熵的定义与性质Definition and properties of generalized entropies

至此,我们已看到如何将熵定义为期望信息量。然而,广义熵 [53, 89] 未必需要采取这种形式。我们沿用 [28] 的定义。So far, we saw how to define an entropy as the expected information content. However, generalized entropies [53, 89] do not necessarily need to take this form. We follow the definition of [28].

定义 13.3.9(熵函数)。Definition 13.3.9 (Entropy function).
函数 H ⁣:△M→R+H\colon\triangle^{M}\to\mathbb{R}_{+} 为熵,若A function H ⁣:△M→R+H\colon\triangle^{M}\to\mathbb{R}_{+} is an entropy if 1. 若 π∈{e1,…,eM}{\bm{\pi}}\in\{{\bm{e}}_{1},\dots,{\bm{e}}_{M}\},则 H(π)=0H({\bm{\pi}})=0,H(π)=0H({\bm{\pi}})=0 if π∈{e1,…,eM}{\bm{\pi}}\in\{{\bm{e}}_{1},\dots,{\bm{e}}_{M}\}, 2. HH 严格凹,HH is strictly concave, 3. 对任意置换矩阵 PP,H(Pπ)=H(π)H(P{\bm{\pi}})=H({\bm{\pi}})。H(Pπ)=H(π)H(P{\bm{\pi}})=H({\bm{\pi}}) for any permutation matrix PP.

由该定义可知,HH 非负,且均匀分布是其唯一的极大值点 [28, 命题 4]。这正是人们对熵函数的预期。平方 pp-范数熵便是一例 [28]This definition implies that HH is non-negative and is uniquely maximized by the uniform distribution [28, Proposition 4]. This is indeed what we expect from an entropy function. An example is the squared pp-norm entropy [28]

H(π)=12−12∥π∥p2.H({\bm{\pi}})=\frac{1}{2}-\frac{1}{2}\|{\bm{\pi}}\|_{p}^{2}.

由于平方 pp-范数在 p∈(1,2]p\in(1,2] 时强凸 [8],该熵在 p∈(1,2]p\in(1,2] 时强凹,因而可用于平滑函数。Since the squared pp-norm is strongly convex for p∈(1,2]p\in(1,2] [8], this entropy is strongly concave for p∈(1,2]p\in(1,2] and can therefore be used to smooth out functions.

下面我们说明如何应用这些技术,计算平滑的 ReLU 与平滑的 max 算子,以及阶跃函数与 argmax 算子的连续松弛。We now illustrate how to apply these techniques to compute smoothed ReLUs and smoothed max operators, as well as continuous relaxations of step functions and argmax operators.

13.4 平滑的 ReLU 函数13.4 Smoothed ReLU functions

为演示本章所讨论的平滑技术如何应用,我们先说明如何平滑 ReLU 函数。ReLU 函数定义为To demonstrate the application of the smoothing techniques discussed in this chapter, we begin by explaining how to smooth the ReLU function. The ReLU function is defined by

relu(u):={u if u≥00 otherwise =max⁡(u,0).\mathrm{relu}(u)\coloneqq\begin{cases}u&\text{ if }u\geq 0\\ 0&\text{ otherwise }\end{cases}=\max(u,0).

我们记得,要用对偶方法平滑函数 ff,需先求其共轭 f∗f^{*},对其施加正则化项 Ω\Omega 得到 fΩ∗:=f∗+Ωf^{*}_{\Omega}\coloneqq f^{*}+\Omega,再通过计算 fΩ∗∗f_{\Omega}^{**} 得到 fΩf_{\Omega}。We recall that in order to smooth a function ff by the dual approach, we calculate its conjugate f∗f^{*}, add regularization Ω\Omega to it to obtain fΩ∗:=f∗+Ωf^{*}_{\Omega}\coloneqq f^{*}+\Omega and then obtain fΩf_{\Omega} by computing fΩ∗∗f_{\Omega}^{**}.

这里我们希望平滑 f=reluf=\mathrm{relu}。它的凸共轭为Here, we wish to smooth out f=reluf=\mathrm{relu}. Its convex conjugate is

relu∗(π)=ι[0,1](π)={0 if π∈[0,1]∞ if π∉[0,1].\mathrm{relu}^{*}(\pi)=\iota_{[0,1]}(\pi)=\begin{cases}0&\text{ if }\pi\in[0,1]\\ \infty&\text{ if }\pi\not\in[0,1]\end{cases}.

要弄清其中缘由,我们观察到To notice why, we observe that

relu(u)=max⁡π∈[0,1]u⋅π=max⁡π∈{0,1}u⋅π={u if u≥00 otherwise.\mathrm{relu}(u)=\max_{\pi\in[0,1]}u\cdot\pi=\max_{\pi\in\{0,1\}}u\cdot\pi=\begin{cases}u&\text{ if }u\geq 0\\ 0&\text{ otherwise}\end{cases}. (13.4)

确实,目标函数关于 π\pi 是线性的,故最大值必在 [0,1][0,1] 的某个极点处取得,于是可将约束 π∈[0,1]\pi\in[0,1] 换成 π∈{0,1}\pi\in\{0,1\}。这说明 ReLU 恰是 [0,1][0,1] 的支撑函数。而支撑函数的共轭为指示函数,故确实得到 relu∗=ι[0,1]\mathrm{relu}^{*}=\iota_{[0,1]}。于是有Indeed, since the objective is linear in π\pi, the maximum is attained at one of the extreme points of [0,1][0,1], so that we can replace the constraint π∈[0,1]\pi\in[0,1] with π∈{0,1}\pi\in\{0,1\}. This shows that the ReLU is exactly the support function of [0,1][0,1]. Since the conjugate of the support function is the indicator function, we indeed obtain relu∗=ι[0,1]\mathrm{relu}^{*}=\iota_{[0,1]}. We therefore have

reluΩ∗(π)=relu∗(π)+Ω(π)=ι[0,1](π)+Ω(π)\mathrm{relu}^{*}_{\Omega}(\pi)=\mathrm{relu}^{*}(\pi)+\Omega(\pi)=\iota_{[0,1]}(\pi)+\Omega(\pi)

并且,对 Ω\Omega 的某种选取,我们需要能够计算and for some choice of Ω\Omega, we need to be able to compute

reluΩ(u)\displaystyle\mathrm{relu}_{\Omega}(u) =max⁡π∈Ru⋅π−(ι[0,1](π)+Ω(π))\displaystyle=\max_{\pi\in\mathbb{R}}u\cdot\pi-(\iota_{[0,1]}(\pi)+\Omega(\pi))
=max⁡π∈[0,1]u⋅π−Ω(π).\displaystyle=\max_{\pi\in[0,1]}u\cdot\pi-\Omega(\pi).

softplusThe softplus

若采用正则化项 Ω(π)=πlog⁡π+(1−π)log⁡(1−π)\Omega(\pi)=\pi\log\pi+(1-\pi)\log(1-\pi),它源于使用 Shannon 负熵 ⟨π,log⁡π⟩\langle{\bm{\pi}},\log{\bm{\pi}}\rangle 并取 π=(π,1−π){\bm{\pi}}=(\pi,1-\pi),则得到If we use the regularizer Ω(π)=πlog⁡π+(1−π)log⁡(1−π)\Omega(\pi)=\pi\log\pi+(1-\pi)\log(1-\pi), which comes from using Shannon’s negentropy ⟨π,log⁡π⟩\langle{\bm{\pi}},\log{\bm{\pi}}\rangle with π=(π,1−π){\bm{\pi}}=(\pi,1-\pi), we obtain

reluΩ(u)=softplus(u)=log⁡(1+exp⁡(u)).\mathrm{relu}_{\Omega}(u)=\mathrm{softplus}(u)=\log(1+\exp(u)).

这一结果是命题 13.5.4 的一个特例。This result is a special case of Proposition 13.5.4.

稀疏 plus(sparseplus)The sparseplus

若采用正则化项 Ω(π)=π(π−1)\Omega({\bm{\pi}})=\pi(\pi-1),它源于使用 Gini 负熵并取 12⟨π,π−1⁡⟩\frac{1}{2}\langle{\bm{\pi}},{\bm{\pi}}-\operatorname{\mathbf{1}}\rangle 与 π=(π,1−π){\bm{\pi}}=(\pi,1-\pi),则得到If we use the regularizer Ω(π)=π(π−1)\Omega({\bm{\pi}})=\pi(\pi-1), which comes from using Gini’s negentropy with 12⟨π,π−1⁡⟩\frac{1}{2}\langle{\bm{\pi}},{\bm{\pi}}-\operatorname{\mathbf{1}}\rangle with π=(π,1−π){\bm{\pi}}=(\pi,1-\pi), we obtain

reluΩ(u)=sparseplus(u)={0,u≤−114(u+1)2,−1<u<1u,u≥1.\mathrm{relu}_{\Omega}(u)=\mathrm{sparseplus}(u)=\begin{cases}0,&u\leq-1\\ \frac{1}{4}(u+1)^{2},&-1<u<1\\ u,&u\geq 1\end{cases}.

softplus 与 sparseplus 的对比见图 13.8(左图)。See Fig. 13.8 (left figure) for a comparison of softplus and sparseplus.

13.5 平滑的 max 算子13.5 Smoothed max operators

作为本章所讨论的平滑技巧的一个更精细的应用,我们说明如何平滑 max 算子。平滑的 max 算子将平滑的 ReLU 函数作为特例包含在内。As a more elaborate application of the smoothing techniques discussed in this chapter, we explain how to smooth max operators. Smoothed max operators include smoothed ReLU functions as a special case.

13.5.1 定义与性质Definition and properties

略微重载记号,给定向量 u=(u1,…,uM)∈RM{\bm{u}}=(u_{1},\dots,u_{M})\in\mathbb{R}^{M},我们将其最大值定义为With a slight notation overloading, given a vector u=(u1,…,uM)∈RM{\bm{u}}=(u_{1},\dots,u_{M})\in\mathbb{R}^{M}, we define its maximum as

max(u):=max⁡j∈[M]uj.\mathrm{max}({\bm{u}})\coloneqq\max_{j\in[M]}u_{j}.

为得到 max⁡\max 的光滑近似 max⁡Ω\max_{\Omega},我们再次采用对偶方法。max⁡\max 的共轭为To obtain a smooth approximation max⁡Ω\max_{\Omega} of max⁡\max, we again apply the dual approach. The conjugate of max⁡\max is

max∗(π)=ι△M(π).\mathrm{max}^{*}({\bm{\pi}})=\iota_{\triangle^{M}}({\bm{\pi}}).

要理解其中缘由,我们观察到概率单纯形 △M\triangle^{M} 的极点是标准基向量 e1,…,eM{\bm{e}}_{1},\dots,{\bm{e}}_{M}。由于目标函数是线性的,于是有To notice why, we observe that the vertices of the probability simplex △M\triangle^{M} are the standard basis vectors e1,…,eM{\bm{e}}_{1},\dots,{\bm{e}}_{M}. Since the objective is linear, we then have

max⁡(u)=max⁡π∈△M⟨u,π⟩=max⁡π∈{e1,…,eM}⟨u,π⟩.\max({\bm{u}})=\max_{{\bm{\pi}}\in\triangle^{M}}\langle{\bm{u}},{\bm{\pi}}\rangle=\max_{{\bm{\pi}}\in\{{\bm{e}}_{1},\dots,{\bm{e}}_{M}\}}\langle{\bm{u}},{\bm{\pi}}\rangle.

换言之,max 算子恰是 △M\triangle^{M} 的支撑函数。由于支撑函数的共轭为指示函数,我们确实得到 max∗=ι△M\mathrm{max}^{*}=\iota_{\triangle^{M}}。因此可以将其写成In other words, the maximum operator is exactly the support function of △M\triangle^{M}. Since the conjugate of the support function is the indicator function, we indeed obtain max∗=ι△M\mathrm{max}^{*}=\iota_{\triangle^{M}}. We can therefore write

maxΩ∗(π)=max∗(π)+Ω(π)=Ω(π)+ι△M(π)\text{max}_{\Omega}^{*}({\bm{\pi}})=\text{max}^{*}({\bm{\pi}})+\Omega({\bm{\pi}})=\Omega({\bm{\pi}})+\iota_{\triangle^{M}}({\bm{\pi}})

以及and

maxΩ(u)\displaystyle\mathrm{max}_{\Omega}({\bm{u}}) =(Ω+ι△M)∗(u)\displaystyle=(\Omega+\iota_{\triangle^{M}})^{*}({\bm{u}})
=max⁡π∈RM⟨u,π⟩−(Ω(π)+ι△M(π))\displaystyle=\max_{{\bm{\pi}}\in\mathbb{R}^{M}}\langle{\bm{u}},{\bm{\pi}}\rangle-(\Omega({\bm{\pi}})+\iota_{\triangle^{M}}({\bm{\pi}}))
=max⁡π∈△M⟨u,π⟩−Ω(π).\displaystyle=\max_{{\bm{\pi}}\in\triangle^{M}}\langle{\bm{u}},{\bm{\pi}}\rangle-\Omega({\bm{\pi}}).

平滑的 max 算子 max⁡Ω\max_{\Omega} 在神经网络中可能很有用,例如可用作平滑的最大池化层。其性质已在 [132, 引理 1] 中研究,为方便起见我们在此回顾。The smoothed max operator max⁡Ω\max_{\Omega} can be useful in a neural network, for example as a smoothed max pooling layer. Its properties have been studied in [132, Lemma 1], as we recall here for convenience.

命题 13.5.1(max⁡Ω\max_{\Omega} 的性质)。Proposition 13.5.1 (Properties of max⁡Ω\max_{\Omega}).
以下性质成立。The following properties hold. 1. 界:若对任意 π∈△M{\bm{\pi}}\in\triangle^{M} 都有 LΩ≤Ω(π)≤UΩ\mathcal{L}_{\Omega}\leq\Omega({\bm{\pi}})\leq\mathcal{U}_{\Omega},则对任意 u∈RM{\bm{u}}\in\mathbb{R}^{M} 都有 max⁡(u)−UΩ≤maxΩ(u)≤max⁡(u)−LΩ\max({\bm{u}})-\mathcal{U}_{\Omega}\leq\text{max}_{\Omega}({\bm{u}})\leq\max({\bm{u}})-\mathcal{L}_{\Omega}。Bounds: if LΩ≤Ω(π)≤UΩ\mathcal{L}_{\Omega}\leq\Omega({\bm{\pi}})\leq\mathcal{U}_{\Omega} for all π∈△M{\bm{\pi}}\in\triangle^{M}, then max⁡(u)−UΩ≤maxΩ(u)≤max⁡(u)−LΩ\max({\bm{u}})-\mathcal{U}_{\Omega}\leq\text{max}_{\Omega}({\bm{u}})\leq\max({\bm{u}})-\mathcal{L}_{\Omega} for all u∈RM{\bm{u}}\in\mathbb{R}^{M}. 2. 单调性:若 u≤v{\bm{u}}\leq{\bm{v}}(逐元素),则 maxΩ(u)≤maxΩ(v)\text{max}_{\Omega}({\bm{u}})\leq\text{max}_{\Omega}({\bm{v}})。Monotonicity: if u≤v{\bm{u}}\leq{\bm{v}} (element-wise), then maxΩ(u)≤maxΩ(v)\text{max}_{\Omega}({\bm{u}})\leq\text{max}_{\Omega}({\bm{v}}). 3. 交换律:若对任意置换矩阵 PP 及任意 π∈△M{\bm{\pi}}\in\triangle^{M} 都有 Ω(Pπ)=Ω(π)\Omega(P{\bm{\pi}})=\Omega({\bm{\pi}}),则对任意置换矩阵 PP 都有 maxΩ(Pu)=maxΩ(u)\text{max}_{\Omega}(P{\bm{u}})=\text{max}_{\Omega}({\bm{u}})。Commutativity: if Ω(Pπ)=Ω(π)\Omega(P{\bm{\pi}})=\Omega({\bm{\pi}}) for any permutation matrix PP and any π∈△M{\bm{\pi}}\in\triangle^{M}, then maxΩ(Pu)=maxΩ(u)\text{max}_{\Omega}(P{\bm{u}})=\text{max}_{\Omega}({\bm{u}}) for any permutation matrix PP. 4. ++ 的分配律:对任意 u∈RM{\bm{u}}\in\mathbb{R}^{M} 及任意 c∈Rc\in\mathbb{R},maxΩ(u+c1⁡)=maxΩ(u)+c\text{max}_{\Omega}({\bm{u}}+c\operatorname{\mathbf{1}})=\text{max}_{\Omega}({\bm{u}})+c。Distributivity of ++: maxΩ(u+c1⁡)=maxΩ(u)+c\text{max}_{\Omega}({\bm{u}}+c\operatorname{\mathbf{1}})=\text{max}_{\Omega}({\bm{u}})+c for all u∈RM{\bm{u}}\in\mathbb{R}^{M} and all c∈Rc\in\mathbb{R}.

这些性质在 [132] 中被用于构造可微的动态规划。下面我们考虑 Ω\Omega 的两种可能选择,它们分别引出图 13.7 所示的 softmax 与 sparsemax 算子。These properties are leveraged in [132] to create differentiable dynamic programs. We consider in the following two possible choices of Ω\Omega leading to the softmax and sparsemax operators illustrated in Fig. 13.7.

平滑的 min 算子Smoothed min operators

min 算子可以用 max 算子表示,因为对所有 u∈RM{\bm{u}}\in\mathbb{R}^{M},The minimum operator can be expressed in terms of the maximum operator, since for all u∈RM{\bm{u}}\in\mathbb{R}^{M},

min⁡(u)=−max⁡(−u).\min({\bm{u}})=-\max(-{\bm{u}}).

因此,给定平滑的 max 算子 maxΩ\mathrm{max}_{\Omega},我们可以很容易地将平滑的 min 算子定义为Given a smoothed max operator maxΩ\mathrm{max}_{\Omega}, we can therefore easily define a smoothed min operator as

minΩ(u)\displaystyle\mathrm{min}_{\Omega}({\bm{u}}) :=−maxΩ(−u).\displaystyle\coloneqq-\mathrm{max}_{\Omega}(-{\bm{u}}).

13.5.2 化归为求根Reduction to root finding

对一般的强凸正则化项 Ω\Omega 计算 max⁡Ω(u)\max_{\Omega}({\bm{u}}),涉及在概率单纯形约束下求解一个极大化问题。为方便起见,我们定义记号Computing max⁡Ω(u)\max_{\Omega}({\bm{u}}) for a general strongly-convex regularization Ω\Omega involves the resolution of a maximum over probability simplex constraints. For convenience, let us define the notation

δΩ(u):=(Ω+ιR+M)∗(u)=max⁡v∈R+M⟨u,v⟩−Ω(v).\delta_{\Omega}({\bm{u}})\coloneqq(\Omega+\iota_{\mathbb{R}_{+}^{M}})^{*}({\bm{u}})=\max_{{\bm{v}}\in\mathbb{R}^{M}_{+}}\langle{\bm{u}},{\bm{v}}\rangle-\Omega({\bm{v}}).

下面的命题表明,我们可以把 max⁡Ω\max_{\Omega} 的计算化归为求解一个涉及 δΩ\delta_{\Omega} 的根方程。The following proposition shows that we can reduce computing max⁡Ω\max_{\Omega} to solving a root equation involving δΩ\delta_{\Omega}.

命题 13.5.2(将 max⁡Ω\max_{\Omega} 的计算化归为求根)。Proposition 13.5.2 (Computing max⁡Ω\max_{\Omega} as root finding).
设 Ω\Omega 强凸,则对任意 u∈RM{\bm{u}}\in\mathbb{R}^{M},Suppose Ω\Omega is strongly convex. For all u∈RM{\bm{u}}\in\mathbb{R}^{M}, maxΩ(u)\displaystyle\text{max}_{\Omega}({\bm{u}}) =min⁡τ∈Rτ+δΩ(u−τ1⁡)\displaystyle=\min_{\tau\in\mathbb{R}}\tau+\delta_{\Omega}({\bm{u}}-\tau\operatorname{\mathbf{1}}) =τ⋆+δΩ(u−τ⋆1⁡)\displaystyle=\tau^{\star}+\delta_{\Omega}({\bm{u}}-\tau^{\star}\operatorname{\mathbf{1}}) 以及and ∇maxΩ(u)=∇δΩ(u−τ⋆1⁡),\nabla\text{max}_{\Omega}({\bm{u}})=\nabla\delta_{\Omega}({\bm{u}}-\tau^{\star}\operatorname{\mathbf{1}}), 其中 τ⋆\tau^{\star} 是关于 τ\tau 的上述 min⁡\min 的解,满足求根方程where τ⋆\tau^{\star} is the solution w.r.t. τ\tau of the above min⁡\min, which satisfies the root equation ⟨∇δΩ(u−τ⋆1⁡),1⁡⟩=1.\langle\nabla\delta_{\Omega}({\bm{u}}-\tau^{\star}\operatorname{\mathbf{1}}),\operatorname{\mathbf{1}}\rangle=1.
证明 13.5.3。Proof 13.5.3.

思路是保留非负约束为显式约束,而对概率单纯形的等式约束使用拉格朗日乘子。于是有The idea is to keep the non-negativity constraint explicit, but to use a Lagrange multiplier for the equality constraint of the probability simplex. We then have

maxΩ(u)\displaystyle\text{max}_{\Omega}({\bm{u}}) =max⁡v∈△M⟨u,v⟩−Ω(v)\displaystyle=\max_{{\bm{v}}\in\triangle^{M}}\langle{\bm{u}},{\bm{v}}\rangle-\Omega({\bm{v}})
=max⁡v∈R+Mmin⁡τ∈R⟨u,v⟩−Ω(v)−τ(⟨v,1⁡⟩−1)\displaystyle=\max_{{\bm{v}}\in\mathbb{R}_{+}^{M}}\min_{\tau\in\mathbb{R}}\langle{\bm{u}},{\bm{v}}\rangle-\Omega({\bm{v}})-\tau(\langle{\bm{v}},\operatorname{\mathbf{1}}\rangle-1)
=min⁡τ∈Rτ+max⁡v∈R+M⟨u−τ1⁡,v⟩−Ω(v)\displaystyle=\min_{\tau\in\mathbb{R}}\tau+\max_{{\bm{v}}\in\mathbb{R}_{+}^{M}}\langle{\bm{u}}-\tau\operatorname{\mathbf{1}},{\bm{v}}\rangle-\Omega({\bm{v}})
=min⁡τ∈Rτ+δΩ(u−τ1⁡),\displaystyle=\min_{\tau\in\mathbb{R}}\tau+\delta_{\Omega}({\bm{u}}-\tau\operatorname{\mathbf{1}}),

这里我们利用了可以交换 min⁡\min 与 max⁡\max 的次序,因为 (u,v)↦⟨u,v⟩−Ω(v)({\bm{u}},{\bm{v}})\mapsto\langle{\bm{u}},{\bm{v}}\rangle-\Omega({\bm{v}}) 是凸—凹的,且 v∈△M{\bm{v}}\in\triangle^{M} 为仿射约束。梯度 ∇δΩ(u)\nabla\delta_{\Omega}({\bm{u}}) 由 Danskin 定理给出。根方程则来自对 τ↦τ+δΩ(u−τ1⁡)\tau\mapsto\tau+\delta_{\Omega}({\bm{u}}-\tau\operatorname{\mathbf{1}}) 求导并令其等于零。where we used that we can swap the min⁡\min and the max⁡\max, since (u,v)↦⟨u,v⟩−Ω(v)({\bm{u}},{\bm{v}})\mapsto\langle{\bm{u}},{\bm{v}}\rangle-\Omega({\bm{v}}) is convex-concave and v∈△M{\bm{v}}\in\triangle^{M} is an affine constraint. The gradient ∇δΩ(u)\nabla\delta_{\Omega}({\bm{u}}) follows from Danskin’s theorem. The root equation follows from computing the derivative of τ↦τ+δΩ(u−τ1⁡)\tau\mapsto\tau+\delta_{\Omega}({\bm{u}}-\tau\operatorname{\mathbf{1}}) and setting it to zero.

13.5.3 softmaxThe softmax

当 Ω\Omega 取 Shannon 负熵时,可得 max⁡Ω\max_{\Omega} 就是 softmax,这一点已在 4.4.2 节中简要讨论过。When Ω\Omega is Shannon’s negentropy, we obtain that max⁡Ω\max_{\Omega} is the softmax, already briefly discussed in Section 4.4.2.

命题 13.5.4(softmax 的解析表达式)。Proposition 13.5.4 (Analytical expression of the softmax).
当 Ω(π)=⟨π,log⁡π⟩\Omega({\bm{\pi}})=\langle{\bm{\pi}},\log{\bm{\pi}}\rangle 时,可得When Ω(π)=⟨π,log⁡π⟩\Omega({\bm{\pi}})=\langle{\bm{\pi}},\log{\bm{\pi}}\rangle, we get softmax(u)\displaystyle\mathrm{softmax}({\bm{u}}) :=maxΩ(u)\displaystyle\coloneqq\mathrm{max}_{\Omega}({\bm{u}}) =max⁡π∈△M⟨u,π⟩−Ω(π)\displaystyle=\max_{{\bm{\pi}}\in\triangle^{M}}\langle{\bm{u}},{\bm{\pi}}\rangle-\Omega({\bm{\pi}}) =logsumexp(u)\displaystyle=\mathrm{logsumexp}({\bm{u}}) =log⁡∑j=1Meuj.\displaystyle=\log\sum_{j=1}^{M}e^{u_{j}}.
证明 13.5.5。Proof 13.5.5.

由于 dom⁡(Ω)=R+M\dom(\Omega)=\mathbb{R}_{+}^{M},故有 δΩ=Ω∗\delta_{\Omega}=\Omega^{*}(即非负约束是多余的)。于是由例 13.2.2 得 δΩ(u)=∑j=1Mexp⁡(uj−1)\delta_{\Omega}({\bm{u}})=\sum_{j=1}^{M}\exp(u_{j}-1)。根据命题 13.5.2,max⁡Ω(u)=τ⋆+δΩ(u−τ⋆1⁡)\max_{\Omega}({\bm{u}})=\tau^{\star}+\delta_{\Omega}({\bm{u}}-\tau^{\star}\operatorname{\mathbf{1}}),其中 τ⋆\tau^{\star} 满足 ⟨∇δΩ(u−τ⋆1⁡),1⁡⟩=1.\langle\nabla\delta_{\Omega}({\bm{u}}-\tau^{\star}\operatorname{\mathbf{1}}),\operatorname{\mathbf{1}}\rangle=1.。由于 ∇δΩ(u)=exp⁡(u−1⁡)\nabla\delta_{\Omega}({\bm{u}})=\exp({\bm{u}}-\operatorname{\mathbf{1}}),我们需解 ∑j=1Mexp⁡(uj−1−τ)=1\sum_{j=1}^{M}\exp(u_{j}-1-\tau)=1。由此得到 τ⋆+1=logsumexp(u)\tau^{\star}+1=\mathrm{logsumexp}({\bm{u}}),从而有 max⁡Ω(u)=logsumexp(u)−1+∑j=1Mexp⁡(uj−logsumexp(u))=logsumexp(u)\max_{\Omega}({\bm{u}})=\mathrm{logsumexp}({\bm{u}})-1+\sum_{j=1}^{M}\exp(u_{j}-\mathrm{logsumexp}({\bm{u}}))=\mathrm{logsumexp}({\bm{u}})。Since dom⁡(Ω)=R+M\dom(\Omega)=\mathbb{R}_{+}^{M}, we have δΩ=Ω∗\delta_{\Omega}=\Omega^{*} (i.e., the non-negativity constraint is redundant). From Example 13.2.2, we therefore have δΩ(u)=∑j=1Mexp⁡(uj−1)\delta_{\Omega}({\bm{u}})=\sum_{j=1}^{M}\exp(u_{j}-1). From Proposition 13.5.2, max⁡Ω(u)=τ⋆+δΩ(u−τ⋆1⁡)\max_{\Omega}({\bm{u}})=\tau^{\star}+\delta_{\Omega}({\bm{u}}-\tau^{\star}\operatorname{\mathbf{1}}) where τ⋆\tau^{\star} satisfies ⟨∇δΩ(u−τ⋆1⁡),1⁡⟩=1.\langle\nabla\delta_{\Omega}({\bm{u}}-\tau^{\star}\operatorname{\mathbf{1}}),\operatorname{\mathbf{1}}\rangle=1. Since ∇δΩ(u)=exp⁡(u−1⁡)\nabla\delta_{\Omega}({\bm{u}})=\exp({\bm{u}}-\operatorname{\mathbf{1}}), we need to solve ∑j=1Mexp⁡(uj−1−τ)=1\sum_{j=1}^{M}\exp(u_{j}-1-\tau)=1. We therefore get τ⋆+1=logsumexp(u)\tau^{\star}+1=\mathrm{logsumexp}({\bm{u}}) and therefore max⁡Ω(u)=logsumexp(u)−1+∑j=1Mexp⁡(uj−logsumexp(u))=logsumexp(u)\max_{\Omega}({\bm{u}})=\mathrm{logsumexp}({\bm{u}})-1+\sum_{j=1}^{M}\exp(u_{j}-\mathrm{logsumexp}({\bm{u}}))=\mathrm{logsumexp}({\bm{u}}).

由于对所有 π∈△M{\bm{\pi}}\in\triangle^{M} 都有 −log⁡M≤Ω(π)≤0-\log M\leq\Omega({\bm{\pi}})\leq 0,依命题 13.5.1 可得,对所有 u∈RM{\bm{u}}\in\mathbb{R}^{M} 均有Since −log⁡M≤Ω(π)≤0-\log M\leq\Omega({\bm{\pi}})\leq 0 for all π∈△M{\bm{\pi}}\in\triangle^{M}, following Proposition 13.5.1, we get for all u∈RM{\bm{u}}\in\mathbb{R}^{M}

max⁡(u)≤softmax(u)≤max⁡(u)+log⁡M.\max({\bm{u}})\leq\mathrm{softmax}({\bm{u}})\leq\max({\bm{u}})+\log M.

softmax 有一项独特之处:它支持结合律,而这一点并非所有 max⁡Ω\max_{\Omega} 算子都具备。A unique property of the softmax, which is not the case of all max⁡Ω\max_{\Omega} operators, is that it supports associativity.

命题 13.5.6(softmax 的结合律)。Proposition 13.5.6 (Associativity of the softmax).
对所有 a,b,c∈Ra,b,c\in\mathbb{R},For all a,b,c∈Ra,b,c\in\mathbb{R}, softmax(softmax(a,b),c)=softmax(a,softmax(b,c)).\text{softmax}(\text{softmax}(a,b),c)=\text{softmax}(a,\text{softmax}(b,c)).

13.5.4 sparsemaxThe sparsemax

另一种选择是将 Ω\Omega 取为 Gini 负熵,由此便得到 sparsemax [129, 132]。Alternatively, choosing Ω\Omega to be Gini’s negentropy leads to the sparsemax [129, 132].

命题 13.5.7(sparsemax 的变分表述)。Proposition 13.5.7 (Variational formulation of sparsemax).
当 Ω(π)=12⟨π,π−1⁡⟩\Omega({\bm{\pi}})=\frac{1}{2}\langle{\bm{\pi}},{\bm{\pi}}-\operatorname{\mathbf{1}}\rangle 时,有When Ω(π)=12⟨π,π−1⁡⟩\Omega({\bm{\pi}})=\frac{1}{2}\langle{\bm{\pi}},{\bm{\pi}}-\operatorname{\mathbf{1}}\rangle, we have sparsemax(u)\displaystyle\mathrm{sparsemax}({\bm{u}}) :=maxΩ(u)\displaystyle\coloneqq\text{max}_{\Omega}({\bm{u}}) =max⁡π∈△M⟨u,π⟩−Ω(π)\displaystyle=\max_{{\bm{\pi}}\in\triangle^{M}}\langle{\bm{u}},{\bm{\pi}}\rangle-\Omega({\bm{\pi}}) =⟨u,π⋆⟩−Ω(π⋆)\displaystyle=\langle{\bm{u}},{\bm{\pi}}^{\star}\rangle-\Omega({\bm{\pi}}^{\star}) 其中where π⋆=sparseargmax(u):=arg min⁡π∈△M∥u−π∥22.{\bm{\pi}}^{\star}=\mathrm{sparseargmax}({\bm{u}})\coloneqq\argmin_{{\bm{\pi}}\in\triangle^{M}}\|{\bm{u}}-{\bm{\pi}}\|_{2}^{2}.
证明 13.5.8。Proof 13.5.8.

这源于这样一个事实:Ω(π)\Omega({\bm{\pi}}) 与 12∥π∥22\frac{1}{2}\|{\bm{\pi}}\|^{2}_{2} 至多相差一个常数,再配方即可得证。This follows from the fact that Ω(π)\Omega({\bm{\pi}}) is up to a constant equal to 12∥π∥22\frac{1}{2}\|{\bm{\pi}}\|^{2}_{2} and completing the square.

因此,计算 sparsemax 时可以把 sparseargmax(即向概率单纯形上的欧几里得投影)当作一个基本构件。其具体计算方法将在 13.7 节中更详细地讨论。应用命题 13.5.2 则可得到另一种表述。Therefore, computing the sparsemax can use the sparseargmax (the Euclidean projection onto the probability simplex) as a building block. We discuss how to compute it in more detail in Section 13.7. Applying Proposition 13.5.2 gives an alternative formulation.

命题 13.5.9(以求根形式表示的 sparsemax)。Proposition 13.5.9 (Sparsemax as root finding).
当 Ω(π)=12⟨π,π−1⁡⟩\Omega({\bm{\pi}})=\frac{1}{2}\langle{\bm{\pi}},{\bm{\pi}}-\operatorname{\mathbf{1}}\rangle 时,有When Ω(π)=12⟨π,π−1⁡⟩\Omega({\bm{\pi}})=\frac{1}{2}\langle{\bm{\pi}},{\bm{\pi}}-\operatorname{\mathbf{1}}\rangle, we have sparsemax(u)=maxΩ(u)=min⁡τ∈Rτ+12∑i=1M[ui−τ]+2\mathrm{sparsemax}({\bm{u}})=\text{max}_{\Omega}({\bm{u}})=\min_{\tau\in\mathbb{R}}\tau+\frac{1}{2}\sum_{i=1}^{M}[u_{i}-\tau]_{+}^{2} 且 τ⋆\tau^{\star} 满足and τ⋆\tau^{\star} satisfies ∑i=1M[ui−τ]+=1.\sum_{i=1}^{M}[u_{i}-\tau]_{+}=1.
证明 13.5.10。Proof 13.5.10.

首先计算 δΩ(u)=max⁡v∈R+M⟨u,v⟩−Ω(v)\delta_{\Omega}({\bm{u}})=\max_{{\bm{v}}\in\mathbb{R}_{+}^{M}}\langle{\bm{u}},{\bm{v}}\rangle-\Omega({\bm{v}}) 的表达式。令 v↦⟨u,v⟩−Ω(v){\bm{v}}\mapsto\langle{\bm{u}},{\bm{v}}\rangle-\Omega({\bm{v}}) 的梯度为零并作截断,得到 v⋆=[u]+{\bm{v}}^{\star}=[{\bm{u}}]_{+}。将 v⋆{\bm{v}}^{\star} 代回,得到 δΩ(u)=12∑i=1M[ui]+2\delta_{\Omega}({\bm{u}})=\frac{1}{2}\sum_{i=1}^{M}[u_{i}]_{+}^{2}。第一部分由命题 13.5.2 得证。令关于 τ\tau 的导数为零,即得第二部分。First, we compute the expression of δΩ(u)=max⁡v∈R+M⟨u,v⟩−Ω(v)\delta_{\Omega}({\bm{u}})=\max_{{\bm{v}}\in\mathbb{R}_{+}^{M}}\langle{\bm{u}},{\bm{v}}\rangle-\Omega({\bm{v}}). Setting the gradient of v↦⟨u,v⟩−Ω(v){\bm{v}}\mapsto\langle{\bm{u}},{\bm{v}}\rangle-\Omega({\bm{v}}) to zero and clipping, we obtain v⋆=[u]+{\bm{v}}^{\star}=[{\bm{u}}]_{+}. Plugging v⋆{\bm{v}}^{\star} back, we obtain δΩ(u)=12∑i=1M[ui]+2\delta_{\Omega}({\bm{u}})=\frac{1}{2}\sum_{i=1}^{M}[u_{i}]_{+}^{2}. Using Proposition 13.5.2 proves the proposition’s first part. Setting the derivative w.r.t. τ\tau to zero gives the second part.

可以证明 [59, 48],精确解 τ⋆\tau^{\star} 由下式给出It can be shown [59, 48] that the exact solution τ⋆\tau^{\star} is obtained by

τ⋆=1j⋆(∑i=1j⋆u[i]−1),\tau^{\star}=\frac{1}{j^{\star}}\left(\sum_{i=1}^{j^{\star}}u_{[i]}-1\right), (13.5)

其中 j⋆j^{\star} 是使下式成立的最大 j∈[M]j\in[M]where j⋆j^{\star} is the largest j∈[M]j\in[M] such that

uj−1j(∑i=1ju[i]−1)>0,u_{j}-\frac{1}{j}\left(\sum_{i=1}^{j}u_{[i]}-1\right)>0,

这里我们采用了记号 u[1]≥u[2]≥⋯≥u[M]u_{[1]}\geq u_{[2]}\geq\dots\geq u_{[M]}。作为另一种选择,也可以用二分法或关于 τ\tau 的梯度下降来近似计算 τ⋆\tau^{\star}。and where we used the notation u[1]≥u[2]≥⋯≥u[M]u_{[1]}\geq u_{[2]}\geq\dots\geq u_{[M]}. As an alternative, we can also compute τ⋆\tau^{\star} approximately using a bisection or by gradient descent w.r.t. τ\tau.

对于 π∈△M{\bm{\pi}}\in\triangle^{M},由于 1M≤∥π∥22≤1\tfrac{1}{M}\leq\lVert{\bm{\pi}}\rVert_{2}^{2}\leq 1,我们有 −M−12M≤Ω(π)≤0.-\tfrac{M-1}{2M}\leq\Omega({\bm{\pi}})\leq 0.。因此,根据命题 13.5.1,对所有的 u∈RM{\bm{u}}\in\mathbb{R}^{M},可得For π∈△M{\bm{\pi}}\in\triangle^{M}, since 1M≤∥π∥22≤1\tfrac{1}{M}\leq\lVert{\bm{\pi}}\rVert_{2}^{2}\leq 1, we have −M−12M≤Ω(π)≤0.-\tfrac{M-1}{2M}\leq\Omega({\bm{\pi}})\leq 0. Following Proposition 13.5.1, we therefore get for all u∈RM{\bm{u}}\in\mathbb{R}^{M}

max⁡(u)≤sparsemax(u)≤max⁡(u)+M−12M.\max({\bm{u}})\leq\mathrm{sparsemax}({\bm{u}})\leq\max({\bm{u}})+\frac{M-1}{2M}.
Refer to caption
Refer to caption
Refer to caption
图 13.7:max、softmax 与 sparsemax 函数。max 函数的等高线(即对某个常数 cc,满足 {u∈R3:f(u)=c}\{{\bm{u}}\in\mathbb{R}^{3}:f({\bm{u}})=c\} 的点集,以灰色虚线表示)并不光滑。沿着这些等高线,梯度在折角处发生突变。这表明 max 函数并非处处可微,具体而言,它在点集 {u∈R3:ui=uj for any i≠j}\{{\bm{u}}\in\mathbb{R}^{3}:u_{i}=u_{j}\ \text{for any}\ i\neq j\} 上不可微。相比之下,softmax 与 sparsemax 函数的等高线是光滑的,这说明它们是 max 函数的光滑对应物。Figure 13.7: Max, softmax and sparsemax functions. The max function has non-smooth contour lines (set of points {u∈R3:f(u)=c}\{{\bm{u}}\in\mathbb{R}^{3}:f({\bm{u}})=c\} for some constant cc represented by dashed gray lines). The gradient along these contour lines switches suddenly at the corners of the contour lines switch. This shows that the max function is not differentiable everywhere, namely, non-differentiable on the set of points {u∈R3:ui=uj for any i≠j}\{{\bm{u}}\in\mathbb{R}^{3}:u_{i}=u_{j}\ \text{for any}\ i\neq j\}. The contour lines of the softmax and sparsemax functions on the other hand are smooth illustrating that these functions are smooth counterparts of the max function.

13.5.5 恢复平滑的 ReLU 函数Recovering smoothed ReLU functions

以向量 u=(u,0)∈R2{\bm{u}}=(u,0)\in\mathbb{R}^{2} 为输入,平滑的 max 算子便可恢复出平滑的 ReLU:Using the vector u=(u,0)∈R2{\bm{u}}=(u,0)\in\mathbb{R}^{2} as input, the smoothed max operator recovers the smoothed ReLU:

maxΩ((u,0))=reluΨ(u),\mathrm{max}_{\Omega}((u,0))=\mathrm{relu}_{\Psi}(u),

其中我们定义了 Ψ(π):=Ω((π,1−π))\Psi(\pi)\coloneqq\Omega((\pi,1-\pi))。当 Ω\Omega 为 Shannon 负熵时,便恢复出 Ψ(π)=πlog⁡π+(1−π)log⁡(1−π)\Psi(\pi)=\pi\log\pi+(1-\pi)\log(1-\pi);当 Ω\Omega 为 Gini 负熵时,则恢复出 Ψ(π)=π(π−1)\Psi(\pi)=\pi(\pi-1),我们正是用它来平滑 ReLU 的。where we defined Ψ(π):=Ω((π,1−π))\Psi(\pi)\coloneqq\Omega((\pi,1-\pi)). With Ω\Omega being Shannon’s negentropy, we recover Ψ(π)=πlog⁡π+(1−π)log⁡(1−π)\Psi(\pi)=\pi\log\pi+(1-\pi)\log(1-\pi); with Ω\Omega being Gini’s negentropy, we recover Ψ(π)=π(π−1)\Psi(\pi)=\pi(\pi-1), that we used to smooth the ReLU.

13.6 松弛的阶跃函数(S 形函数)13.6 Relaxed step functions (sigmoids)

下面转向构造阶跃函数的连续松弛。二值阶跃函数又称 Heaviside 阶跃函数,定义为We now turn to creating continuous relaxations of step functions. The binary step function, a.k.a. Heaviside step function, is defined by

step(u):={1 if u≥00 otherwise.\mathrm{step}(u)\coloneqq\begin{cases}1&\text{ if }u\geq 0\\ 0&\text{ otherwise}\end{cases}.

由式 13.4,其变分形式为From Eq. 13.4, its variational form is

step(u)=arg max⁡π∈[0,1]u⋅π.\mathrm{step}(u)=\argmax_{\pi\in[0,1]}u\cdot\pi.

因此,我们可以定义该松弛We can therefore define the relaxation

stepΩ(u):=arg max⁡π∈[0,1]u⋅π−Ω(π).\mathrm{step}_{\Omega}(u)\coloneqq\argmax_{\pi\in[0,1]}u\cdot\pi-\Omega(\pi).

注意,与平滑 ReLU 的情形不同,这里得到的是正则化的 argmax,而非正则化的 max。根据注 13.3.5,强凸正则化项 Ω\Omega 保证了 stepΩ(u)\mathrm{step}_{\Omega}(u) 是 uu 的 Lipschitz 连续函数,因而至少几乎处处可微,这一点与 step(u)\mathrm{step}(u) 不同。Notice that, unlike the case of the smoothed ReLU, it is a regularized argmax, not a regularized max. Following Remark 13.3.5, strongly convex regularization Ω\Omega ensures that stepΩ(u)\mathrm{step}_{\Omega}(u) is a Lipschitz continuous function of uu and is therefore, at least, differentiable almost everywhere, unlike step(u)\mathrm{step}(u).

logistic 函数The logistic function

若采用正则化项 Ω(π)=πlog⁡π+(1−π)log⁡(1−π)\Omega(\pi)=\pi\log\pi+(1-\pi)\log(1-\pi),则得到如下闭式形式If we use the regularizer Ω(π)=πlog⁡π+(1−π)log⁡(1−π)\Omega(\pi)=\pi\log\pi+(1-\pi)\log(1-\pi), we obtain the closed form

stepΩ(u)=logistic(u):=11+e−u=eu1+eu.\mathrm{step}_{\Omega}(u)=\mathrm{logistic}(u)\coloneqq\frac{1}{1+e^{-u}}=\frac{e^{u}}{1+e^{u}}.

该函数处处可微。This function is differentiable everywhere.

稀疏 S 形函数The sparse sigmoid

作为另一种选择,若采用 Ω(π)=π(π−1)\Omega(\pi)=\pi(\pi-1),则得到一个分段线性的 S 形函数,As an alternative, if we use Ω(π)=π(π−1)\Omega(\pi)=\pi(\pi-1), we obtain a piecewise linear sigmoid,

stepΩ(u)=sparsesigmoid(u):={0,u≤−112(u+1),−1<u<11,u≥1.\mathrm{step}_{\Omega}(u)=\mathrm{sparsesigmoid}(u)\coloneqq\begin{cases}0,&u\leq-1\\ \frac{1}{2}(u+1),&-1<u<1\\ 1,&u\geq 1\end{cases}.

与 logistic 函数不同,它可以取到精确值 00 或 11。然而,该函数有两个折角,在这些位置上函数不可微。Unlike the logistic function, it can reach the exact values 00 or 11. However, the function has two kinks, where the function is non-differentiable.

平滑 ReLU 函数与 S 形函数之间的联系Link between smoothed ReLU functions and sigmoids

事实证明,上面介绍的三种 S 形函数(阶跃函数、logistic 函数、稀疏 S 形函数)都等于其对应平滑 ReLU 函数的导数:It turns out that the three sigmoids we presented above (step, logistic, sparsesigmoid) are all equal to the derivative of their corresponding smoothed ReLU function:

step(u)\displaystyle\mathrm{step}(u) =relu′(u)\displaystyle=\mathrm{relu}^{\prime}(u)
logistic(u)\displaystyle\mathrm{logistic}(u) =softplus′(u)\displaystyle=\mathrm{softplus}^{\prime}(u)
sparsesigmoid(u)\displaystyle\mathrm{sparsesigmoid}(u) =sparseplus′(u)\displaystyle=\mathrm{sparseplus}^{\prime}(u)

更一般地,and more generally

reluΩ′(u)=stepΩ(u).\mathrm{relu}_{\Omega}^{\prime}(u)=\mathrm{step}_{\Omega}(u).

这是 Danskin 定理的一个推论;见例 11.2.5。图 13.8 展示了平滑 ReLU 函数与松弛阶跃函数(S 形函数)。This is a consequence of Danskin’s theorem; see Example 11.2.5. We illustrate the smoothed ReLU functions and relaxed step functions (sigmoids) in Fig. 13.8.

图 13.8:平滑 ReLU 函数与松弛阶跃函数(S 形函数)。对左侧函数求导即得到右侧函数。Figure 13.8: Smoothed ReLU functions and relaxed step functions (sigmoids). Differentiating the left functions gives the right functions.

13.7 松弛的 argmax 算子13.7 Relaxed argmax operators

现在我们转向 argmax 算子,它是阶跃函数的推广。略微滥用记号,我们定义We now turn to argmax operators, which are a generalization of step functions. With a slight notation overloading, let us now define

argmax(u):=ϕ(arg max⁡j∈[M]uj),\mathrm{argmax}({\bm{u}})\coloneqq\phi(\argmax_{j\in[M]}u_{j}),

其中 ϕ(j)=onehot(j)=ej\phi(j)=\mathrm{onehot}(j)={\bm{e}}_{j} 用于将任意整数 j∈[M]j\in[M] 嵌入到 RM\mathbb{R}^{M} 中。按照前面的讨论,可得变分形式where ϕ(j)=onehot(j)=ej\phi(j)=\mathrm{onehot}(j)={\bm{e}}_{j} is used to embed any integer j∈[M]j\in[M] into RM\mathbb{R}^{M}. Following the previous discussion, we have the variational form

argmax(u)=arg max⁡π∈△M⟨u,π⟩=arg max⁡π∈{e1,…,eM}⟨u,π⟩,\mathrm{argmax}({\bm{u}})=\argmax_{{\bm{\pi}}\in\triangle^{M}}\langle{\bm{u}},{\bm{\pi}}\rangle=\argmax_{{\bm{\pi}}\in\{{\bm{e}}_{1},\dots,{\bm{e}}_{M}\}}\langle{\bm{u}},{\bm{\pi}}\rangle,

其中第二个等式利用了线性函数在单纯形的某个顶点处取得最大值这一事实。该变分形式提示我们定义如下松弛:where the second equality uses that a linear function is maximized at one of the vertices of the simplex. This variational form suggests to define the relaxation

argmaxΩ(u):=arg max⁡π∈△M⟨u,π⟩−Ω(π).\mathrm{argmax}_{\Omega}({\bm{u}})\coloneqq\argmax_{{\bm{\pi}}\in\triangle^{M}}\langle{\bm{u}},{\bm{\pi}}\rangle-\Omega({\bm{\pi}}).

同样,根据注 13.3.5,若 Ω\Omega 是强凸的,则 argmaxΩ(u)\mathrm{argmax}_{\Omega}({\bm{u}}) 至少是 u{\bm{u}} 的一个几乎处处可微的函数。Again, following Remark 13.3.5, argmaxΩ(u)\mathrm{argmax}_{\Omega}({\bm{u}}) is guaranteed to be, at least, a differentiable almost everywhere function of u{\bm{u}} if Ω\Omega is strongly convex.

与 S 形函数类似,事实证明这些映射等于其对应平滑 max 算子的梯度:Similarly to sigmoids, it turns out that these mappings are equal to the gradient of their corresponding smoothed max operator:

argmaxΩ(u)=∇maxΩ(u).\mathrm{argmax}_{\Omega}({\bm{u}})=\nabla\mathrm{max}_{\Omega}({\bm{u}}).

这同样是 Danskin 定理的一个推论。This is again a consequence of Danskin’s theorem.

softargmaxThe softargmax

当采用 Shannon 负熵 Ω(π)=⟨π,log⁡π⟩\Omega({\bm{\pi}})=\langle{\bm{\pi}},\log{\bm{\pi}}\rangle 时,我们得到When using Shannon’s negative entropy Ω(π)=⟨π,log⁡π⟩\Omega({\bm{\pi}})=\langle{\bm{\pi}},\log{\bm{\pi}}\rangle, we obtain

argmaxΩ(u)=softargmax(u)=exp⁡(u)∑j=1Mexp⁡(uj),\mathrm{argmax}_{\Omega}({\bm{u}})=\mathrm{softargmax}({\bm{u}})=\frac{\exp({\bm{u}})}{\sum_{j=1}^{M}\exp(u_{j})},

该函数处处可微。which is differentiable everywhere.

证明 13.7.1。Proof 13.7.1.

我们知道 max⁡Ω(u)=logsumexp(u)\max_{\Omega}({\bm{u}})=\mathrm{logsumexp}({\bm{u}}) 以及 ∇max⁡Ω(u)=argmaxΩ(u)\nabla\max_{\Omega}({\bm{u}})=\mathrm{argmax}_{\Omega}({\bm{u}})。对 logsumexp(u)\mathrm{logsumexp}({\bm{u}}) 求导得到 softargmax(u)\mathrm{softargmax}({\bm{u}})。We know that max⁡Ω(u)=logsumexp(u)\max_{\Omega}({\bm{u}})=\mathrm{logsumexp}({\bm{u}}) and that ∇max⁡Ω(u)=argmaxΩ(u)\nabla\max_{\Omega}({\bm{u}})=\mathrm{argmax}_{\Omega}({\bm{u}}). Differentiating logsumexp(u)\mathrm{logsumexp}({\bm{u}}) gives softargmax(u)\mathrm{softargmax}({\bm{u}}).

sparseargmaxThe sparseargmax

当采用 Gini 熵 Ω(π)=12⟨π,π−1⁡⟩\Omega({\bm{\pi}})=\frac{1}{2}\langle{\bm{\pi}},{\bm{\pi}}-\operatorname{\mathbf{1}}\rangle(它与 12∥π∥22\frac{1}{2}\|{\bm{\pi}}\|^{2}_{2} 相差一个常数)时,我们得到 sparseargmax [129]When using Gini’s entropy Ω(π)=12⟨π,π−1⁡⟩\Omega({\bm{\pi}})=\frac{1}{2}\langle{\bm{\pi}},{\bm{\pi}}-\operatorname{\mathbf{1}}\rangle, which is up to a constant equal to 12∥π∥22\frac{1}{2}\|{\bm{\pi}}\|^{2}_{2}, we obtain the sparseargmax [129]

argmaxΩ(u)\displaystyle\mathrm{argmax}_{\Omega}({\bm{u}}) =sparseargmax(u)\displaystyle=\mathrm{sparseargmax}({\bm{u}})
:=arg max⁡π∈△M⟨u,π⟩−12⟨π,π−1⁡⟩\displaystyle\coloneqq\argmax_{{\bm{\pi}}\in\triangle^{M}}\langle{\bm{u}},{\bm{\pi}}\rangle-\frac{1}{2}\langle{\bm{\pi}},{\bm{\pi}}-\operatorname{\mathbf{1}}\rangle
=arg max⁡π∈△M⟨u,π⟩−12∥π∥22\displaystyle=\argmax_{{\bm{\pi}}\in\triangle^{M}}\langle{\bm{u}},{\bm{\pi}}\rangle-\frac{1}{2}\|{\bm{\pi}}\|_{2}^{2}
=arg min⁡π∈△M∥u−π∥22,\displaystyle=\argmin_{{\bm{\pi}}\in\triangle^{M}}\|{\bm{u}}-{\bm{\pi}}\|^{2}_{2},

它正是向概率单纯形上的欧几里得投影(另见 16.3 节)。向概率单纯形 △M\triangle^{M} 上的欧几里得投影可以用类似寻找中位数的算法精确计算,其期望时间复杂度为 O(M)O(M),最坏情况时间复杂度为 O(Mlog⁡M)O(M\log M) [38, 135, 59, 48]。计算向概率单纯形上的欧几里得投影归结为计算式 13.5 中给出的 τ⋆\tau^{\star}。一旦算出该值,便有which is nothing but the Euclidean projection onto the probability simplex (see also Section 16.3). The Euclidean projection onto the probability simplex △M\triangle^{M} can be computed exactly using a median-finding-like algorithm. The complexity is O(M)O(M) expected time and O(Mlog⁡M)O(M\log M) worst-case time [38, 135, 59, 48]. Computing the Euclidean projection onto the probability simplex boils down to computing τ⋆\tau^{\star} given in Eq. 13.5. Once we computed it, we have

sparseargmax(u)=[u−τ⋆]+,\mathrm{sparseargmax}({\bm{u}})=[{\bm{u}}-\tau^{\star}]_{+},

正如其名称所示,也如上式所示,sparseargmax 是稀疏的,但它只是几乎处处可微。注意,该算子最初被称为 sparsemax [129],但这是一个误称,因为它实际上是 argmax 的一种近似。因此,类比 softargmax,我们使用 sparseargmax 这一名称。图 13.9 与图 13.10 比较了 argmax、softmax 与 sparseargmax。As its name indicates, and as the above equation shows, sparseargmax is sparse, but it is only differentiable almost everywhere. Note that the operator is originally known as sparsemax [129], but this is a misnomer, as it is really an approximation of the argmax. Therefore, in analogy with the softargmax, we use the name sparseargmax. We compare the argmax, softmax and sparseargmax in Fig. 13.9 and Fig. 13.10.

Refer to caption
Refer to caption
Refer to caption
图 13.9:当 u1u_{1} 与 u2u_{2} 变化时,u=(u1,u2,0){\bm{u}}=(u_{1},u_{2},0) 对应的 argmax(u)\mathrm{argmax}({\bm{u}})、softargmax(u)\mathrm{softargmax}({\bm{u}}) 与 sparseargmax(u)\mathrm{sparseargmax}({\bm{u}}) 的取值。argmax 是分段常值的不连续函数;softargmax 处处连续且可微,但它始终严格为正,因而取值稠密;sparseargmax 是连续函数,其输出可以稀疏,不过它只是几乎处处可微。Figure 13.9: Values of argmax(u)\mathrm{argmax}({\bm{u}}), softargmax(u)\mathrm{softargmax}({\bm{u}}), and sparseargmax(u)\mathrm{sparseargmax}({\bm{u}}) for u=(u1,u2,0){\bm{u}}=(u_{1},u_{2},0), when varying u1u_{1} and u2u_{2}. The argmax is a piecewise constant, discontinuous function. The softargmax is a continuous and differentiable everywhere function, but it is always strictly positive and therefore dense. The sparseargmax is a continuous function and its output can be sparse, but it is only a differentiable almost everywhere function.
Refer to caption
Refer to caption
Refer to caption
图 13.10:与图 13.9 相同,只是改用三维图表示。Figure 13.10: Same as Fig. 13.9 but using a 3D plot.

松弛的 argmin 算子Relaxed argmin operators

argmin 算子可以用 argmax 算子来表示,The argmin operator can be expressed in terms of the argmax operator,

arg min⁡(u)=arg max⁡(−u).\argmin({\bm{u}})=\argmax(-{\bm{u}}).

因此,给定一个松弛的 argmax 算子 argmaxΩ\mathrm{argmax}_{\Omega},我们便可通过下式定义松弛的 argmin,Given a relaxed argmax operator argmaxΩ\mathrm{argmax}_{\Omega}, we can therefore define a relaxed argmin by

argminΩ(u):=argmaxΩ(−u).\mathrm{argmin}_{\Omega}({\bm{u}})\coloneqq\mathrm{argmax}_{\Omega}(-{\bm{u}}).

于是,对任意 u∈RM{\bm{u}}\in\mathbb{R}^{M},都有We then have for all u∈RM{\bm{u}}\in\mathbb{R}^{M}

argminΩ(u)=∇minΩ(u).\mathrm{argmin}_{\Omega}({\bm{u}})=\nabla\text{min}_{\Omega}({\bm{u}}).

13.8 小结13.8 Summary

  • •

    当函数 ff 不可微(甚至不连续)时,一种合理的做法是用它的光滑近似(或连续松弛)来代替它。When a function ff is non-differentiable (or worse, discontinuous), a reasonable approach is to replace it by its smooth approximation (or continuous relaxation).

  • •

    我们回顾的第一种方法,是在 ff 与原始正则化项 RR 之间做下确卷积。Moreau 包络是其中的一个特例,只需取 R=12∥⋅∥22R=\frac{1}{2}\|\cdot\|_{2}^{2} 即可得到。The first approach we reviewed is infimal convolution between ff and primal regularization RR. The Moreau envelope is a special case, obtained by using R=12∥⋅∥22R=\frac{1}{2}\|\cdot\|_{2}^{2}.

  • •

    我们回顾的第二种方法,是用某个对偶正则化项 Ω\Omega 对 ff 的凸共轭 f∗f^{*} 进行正则化。我们看到,当 R=Ω∗R=\Omega^{*} 时,原始方法与对偶方法彼此等价。The second approach we reviewed is regularizing the convex conjugate f∗f^{*} of ff with some dual regularization Ω\Omega. We saw that the primal and dual approaches are equivalent when R=Ω∗R=\Omega^{*}.

  • •

    Legendre-Fenchel 变换(又称凸共轭)可以视为函数的一种对偶表示:与其用 u∈dom⁡(f){\bm{u}}\in\dom(f) 上的图像 (u,f(u))({\bm{u}},f({\bm{u}})) 来表示 ff,不如用 v∈dom⁡(f∗){\bm{v}}\in\dom(f^{*}) 上斜率为 v{\bm{v}}、截距为 −f∗(v)-f^{*}({\bm{v}}) 的一族切线来表示它。正如其名称所示,即便原函数并非凸函数,它也是凸的。The Legendre-Fenchel transformation, a.k.a. convex conjugate, can be seen as a dual representation of a function: instead of representing ff by its graph (u,f(u))({\bm{u}},f({\bm{u}})) for u∈dom⁡(f){\bm{u}}\in\dom(f), we can represent it by the set of tangents with slope v{\bm{v}} and intercept −f∗(v)-f^{*}({\bm{v}}) for v∈dom⁡(f∗){\bm{v}}\in\dom(f^{*}). As its name indicates, it is convex, even if the original function is not.

  • •

    我们展示了如何运用平滑技术来构造平滑的 ReLU 函数与平滑的 max 算子。我们还展示了,对它们求梯度便可得到广义的 S 形函数与 argmax 算子。We showed how to apply smoothing techniques to create smoothed ReLU functions and smoothed max operators. We also showed that taking their gradients allowed us to obtain generalized sigmoid functions and argmax operators.