在本章中,我们回顾基于卷积的平滑技术。In this chapter, we review smoothing techniques based on convolution.
两个函数 与 之间的卷积会生成另一个函数,记为 。其定义为The convolution between two functions and produces another function, denoted . It is defined by
| (14.1) |
这里假设积分是良定义的。因此,它是将 与 的乘积,在将 关于 轴作反射并平移之后进行积分所得的结果。这一运算可以视为滑动平均的推广。利用变量替换 ,我们也可以将其写成assuming that the integral is well-defined. It is therefore the integral of the product of and after is reflected about the -axis and shifted. It can be seen as a generalization of the moving average. Using the change of variable , we can also write
| (14.2) | ||
因此,卷积算子是可交换的。The convolution operator is therefore commutative.
卷积经常与核函数 一起使用,以构造 的光滑近似 。最常用的核函数是宽度为 的高斯核,其定义为The convolution is frequently used together with a kernel to create a smooth approximation of . The most frequently used kernel is the Gaussian kernel with width , defined by
这是均值为零、方差为 的正态分布的概率密度函数(PDF)。项 是归一化常数,它确保该核函数关于 的求和(积分)为 。因此,我们说 是归一化核。This is the probability density function (PDF) of the normal distribution with zero mean and variance . The term is a normalization constant, ensuring that the kernel sums to for all . We therefore say that is a normalized kernel.
应用式 14.1 中卷积的定义,我们得到Applying the definition of the convolution in Eq. 14.1, we obtain
其中where
是均值为 、方差为 的高斯分布的 PDF。因此,我们可以把 视为 在以 为中心的高斯分布上的期望。这一性质对所有平移不变的核都成立,它们对应于位置—尺度族分布(例如 Laplace 分布)。因此,卷积是对所有点进行平均,其中 附近的点被该分布赋予更大的权重。参数 控制我们希望给予更远点多大的重要性。我们称这一视角为平均视角,因为我们用 替换了 。is the PDF of the Gaussian distribution with mean and variance . Therefore, we can see as the expectation of over a Gaussian centered around . This property is true for all translation-invariant kernels, that correspond to a location-scale family distribution (e.g., the Laplace distribution). The convolution therefore performs an averaging with all points, with points nearby given more weight by the distribution. The parameter controls the importance we want to give to farther points. We call this viewpoint averaging, as we replace by .
反之,利用式 14.2 中卷积算子的另一种定义(它源于卷积的交换性),我们有Conversely, using the alternative definition of the convolution operator in Eq. 14.2, which stems from the commutativity of the convolution, we have
其中,第二行用到了高斯核 的符号不变性,即 。这一视角表明,用高斯核进行卷积平滑也可以看作是对函数的输入注入高斯噪声或扰动。where, in the second line, we used that the Gaussian kernel is sign invariant, i.e., . This viewpoint shows that smoothing by convolution with a Gaussian kernel can also be seen as injecting Gaussian noise or perturbations to the function’s input.
当 时,核函数 收敛到 Dirac delta 函数,When , the kernel converges to a Dirac delta function,
由于 Dirac delta 是卷积代数的乘法单位元(这也称为筛选性质),当 时, 收敛到 ,即Since the Dirac delta is the multiplicative identity of the convolution algebra (this is also known as the sifting property), when , converges to , i.e.,
很多时候,我们所处理的函数,其卷积并无解析形式。此时,可以在数值网格上采用离散卷积。对于定义在 上的两个函数 与 ,离散卷积定义为Many times, we work with functions whose convolution does not have an analytical form. In these cases, we can use a discrete convolution on a grid of values. For two functions and defined over , the discrete convolution is defined by
与连续情形相同,离散卷积也是可交换的,即As for its continuous counterpart, the discrete convolution is commutative, namely,
当 在集合 上具有有限支撑集,即对任意 都有 时,便可将求和限制在有限范围内,即When has finite support over the set , meaning that for all , a finite summation may be used instead, i.e.,
在实践中,离散信号 与连续核函数 之间的卷积,是通过对核函数做离散化来实现的。最简单的做法之一,是在一段区间上取采样点,在这些点上对核函数求值,再将所得的值重新归一化,使采样后的核函数之和为 。图 14.1 以高斯核为例展示了这一做法。由于高斯核按指数速度衰减,我们可以围绕 选取一个较窄的区间。关于高斯核其他可能离散化方式的综述,见 [75]。In practice, convolution between a discrete signal and a continuous kernel is implemented by discretizing the kernel. One of the simplest approaches consists in sampling points on an interval, evaluating the kernel at these points and renormalizing the obtained values, so that the sampled kernel sums to . This is illustrated with the Gaussian kernel in Fig. 14.1. Since the Gaussian kernel decays exponentially fast, we can choose a small interval around . For a survey of other possible discretizations of the Gaussian kernel, see [75].
值得注意的是,只要这两个函数及其导数均可积,卷积的导数便满足Remarkably, provided that the two functions are integrable with integrable derivatives, the derivative of the convolution satisfies
这一等式只需在卷积的定义中交换求导与积分的次序即可得到。此外,还有如下命题。which simply stems from switching derivative and integral in the definition of the convolution. Moreover, we have the following proposition.
至此,我们讨论的都是两个一元函数的卷积。该定义可以自然地推广到多元函数 与 ,即So far, we studied the convolution of one-dimensional functions. The definition can be naturally extended to multidimensional functions and as
这里同样假设积分存在。通常情况下,所用的高斯核其协方差矩阵为对角矩阵assuming again that the integral exists. Typically, a Gaussian kernel with diagonal covariance matrix is used
| (14.3) |
其中第二个等式中假定了 。在图像处理的语境下(此时 ),该积分借助离散卷积来近似,所得结果称为高斯模糊。where, in the second equality, we assumed . In an image processing context, where , it is approximated using a discrete convolution and it is called a Gaussian blur.
我们在 13.1 节中研究过的下确卷积,其形式为The infimal convolution we studied in Section 13.1 takes the form
作为对照,经典的卷积则取如下形式In comparison, the classical convolution takes the form
这两种卷积显然相互关联。下确卷积取的是下确界,并把 与 相加:它采用的是最小—加代数。经典卷积则执行积分,并将 与 相乘:它采用的是和—积代数。The two forms of convolution are clearly related. Infimal convolution performs an infimum and uses the sum of and : it uses a min-plus algebra. Classical convolution performs an integral and uses the product of and : it uses a sum-product algebra.
若在下确卷积的定义中以下确界换成软最小值,下确卷积与经典卷积之间的联系便会更加清晰。The link between the infimal convolution and the classical convolution can be further elucidated if we replace the infimum with a soft minimum in the definition of the infimal convolution.
我们便得到下确卷积,即 。We recover the infimal convolution as .
下面说明,软下确卷积可以用经典卷积改写。事实上,借助指数变量替换(在偏微分方程语境中有时称为 Cole-Hopf 变换),We now show that we can rewrite the soft infimal convolution using a classical convolution. Indeed, by using the exponential change of variable (sometimes referred to as Cole-Hopf transformation in a partial differential equation context)
我们可在指数域中定义每一个函数,we can define each function in the exponential domain,
容易验证,此时有It is easy to check that we then have
回到对数域,便得到Back to log domain, we obtain
将该变换与其逆变换结合起来,可写成Combining the transformation and its inverse, we can write
以上结果表明,经过指数变量替换后,软下确卷积可化归为一次卷积的计算。这很有用,因为大小为 的网格上的离散卷积可在 内算完。What we have shown is that, after an exponential change of variable, the soft infimal convolution can be reduced to the computation of a convolution. This is useful as a discrete convolution on a grid of size can be computed in .
我们在 13.1.2 节中看到, 与 之间的下确卷积即为 Moreau 包络,We saw in Section 13.1.2 that the infimal convolution between and is the Moreau envelope,
将下确卷积替换为软下确卷积,便可定义“软”Moreau 包络,Replacing the infimal convolution with a soft infimal convolution, we can define the “soft” Moreau envelope,
需要强调,这一运算与 同高斯核函数的卷积并不相同。事实上,有We emphasize that this operation is not the same as the convolution of with a Gaussian kernel. Indeed, we have
而while
其中 例如由式 14.3 定义。where is for instance defined in Eq. 14.3.
我们已看到,Moreau 包络是光滑函数。那么,使用软 Moreau 包络究竟能带来什么好处?好处可能在于计算:软 Moreau 包络可用离散卷积来近似。We saw that the Moreau envelope is a smooth function. One may therefore ask what do we gain from using a soft Moreau envelope. The benefit can be computational, as the latter can be approximated using a discrete convolution.
我们定义 的 Fourier 变换为Let us define the Fourier transform of by
注意, 是一种函数变换:它将 变为另一个函数 。Note that is a function transformation: it transforms into another function .
现在考虑卷积Now, consider the convolution
若定义如下三个变换If we define the three transformations
卷积定理指出the convolution theorem states that
换一种写法,即有Written differently, we have
用文字来说,在 Fourier 域中,卷积运算变为乘法。反过来,In words, in the Fourier domain, the convolution operation becomes a multiplication. Conversely,
若将 Fourier 变换替换为 Laplace 变换或双侧(双边)Laplace 变换,卷积定理同样成立。The convolution theorem also holds if we replace the Fourier transform with the Laplace transform or with the two-sided (bilateral) Laplace transform.
在 13.2 节中,我们研究了另一种函数变换:凸共轭,又称 Legendre-Fenchel 变换。我们在表 14.1 中回顾了这些变换之间的类比关系。特别地,……的对应项In Section 13.2, we studied another function transformation: the convex conjugate, also known as Legendre-Fenchel transform. We recap the analogies between these transforms in Table 14.1. In particular, the counterpart of
对于下确卷积,与之对应的则是for the infimal convolution is
用文字来说,Legendre-Fenchel 变换之于下确卷积,恰如 Fourier 变换之于卷积。In words, the Legendre-Fenchel transform is to the infimal convolution what the Fourier transform is to the convolution.
| Fourier Fourier | Legendre Legendre | |
|---|---|---|
| 半环Semiring | ||
| 缩放 Scaling | ||
| 平移Translation | ||
| 卷积Convolution | ||
| 高斯/二次函数Gaussian / quadratic | ||
| 平滑Smoothing |
我们在 13.2 节中看到,函数 的 Legendre-Fenchel 变换(凸共轭)为We saw in Section 13.2 that the Legendre-Fenchel transform (convex conjugate) of a function is
必要时,我们可以在 的定义中加入一个指示函数来支持约束。该共轭可以通过 log-sum-exp 平滑化,后者起着软最大值的作用(13.5 节)。If necessary, we can support constraints by including an indicator function in the definition of . The conjugate can be smoothed out using a log-sum-exp, which plays the role of a soft maximum (Section 13.5).
在极限 下,我们恢复凸共轭。In the limit , we recover the convex conjugate.
下面说明:若对 施加双射变换,则该平滑后的共轭可以用卷积重写。We now show that this smoothed conjugate can be rewritten using a convolution if we apply a bijective transformation to .
这一洞见由 Gabriel Peyré 于 2020 年 4 月发布在推特上。This insight was tweeted by Gabriel Peyré in April 2020.
从这个视角我们能得到什么?凸共轭通常难以求得闭式形式。若把 替换为离散集 (即网格),我们便可以用离散卷积在 中近似平滑凸共轭,其中 ,What did we gain from this viewpoint? The convex conjugate can often be difficult to compute in closed form. If we replace with a discrete set (i.e., a grid), we can then approximate the smoothed convex conjugate in , where , using a discrete convolution,
其中 是 高斯核矩阵,其元素对应 ,其中 ;而 是 维向量,其元素对应 ,其中 。这为 13.2 节所讨论的快速 Legendre 变换算法提供了一种对 GPU 友好的替代方案。当然,由于维数灾难,该技术仅限于定义在低维集合上的函数。图 14.2 展示了将该技术用于计算函数的近似双共轭(凸包络)的情形。where is the Gaussian kernel matrix whose entries correspond to for and is the -dimensional vector whose entries correspond to for . This provides a GPU-friendly alternative to the fast Legendre transform algorithm, discussed in Section 13.2. Of course, due to the curse of dimensionality, the technique is limited to functions defined on low-dimensional sets. We illustrate in Fig. 14.2 the application of the technique to computing an approximate biconjugate (convex envelope) of a function.
本节回顾若干与高斯核的卷积具有解析解的实际例子。In this section, we review practical examples for which the convolution with a Gaussian kernel enjoys an analytical solution.
为说明卷积的求导,我们展示如何对平滑的 ReLU 求导。To illustrate differentiation of the convolution, we show how to differentiate the smoothed ReLU.
本节回顾如何利用蒙特卡洛估计近似计算与核函数的卷积及其梯度。In this section, we review how to approximately compute a convolution with a kernel and its gradient using Monte-Carlo estimation.
平滑函数 的一个相当直观的做法,是让输入 受到服从某个噪声分布 的加性噪声 的扰动,再对其取值取平均。由此定义替代函数A rather intuitive approach to smooth a function is to average its values on an input , perturbed by some additive noise , for some noise distribution . This defines the surrogate
参数 控制扰动强度:当 时,我们自然回到 。若定义变换(变量替换),则可得到等价的视角The parameter controls the perturbation strength: as , we naturally recover . An equivalent viewpoint is obtained by defining the transformation (change of variables)
于是有We then have
其中 是由噪声分布 生成的位置族分布,即 经该变换得到的前推分布(见 12.4.4 节)。在此记号下,初始噪声分布 就简单地是 。由此,扰动后的函数可从这两个视角表示为where is the location-family distribution generated by the noise distribution . It is the pushforward distribution of through the transformation (see Section 12.4.4). In this notation, the initial noise distribution is then simply . The perturbed function can then be expressed from these two perspectives as
| (14.4) |
将期望写成概率密度函数的积分,便自然得到前文所述通过卷积实现的平滑Writing the expectation as the integral of a p.d.f, we naturally recover the smoothing by convolution presented earlier,
其中我们定义了核函数where we defined the kernel
在下文中,我们假设噪声分布可分解为In the sequel, we assume that the noise distribution decomposes as
其中 是噪声分布的对数密度, 是归一化常数。例如,取 、,即得到具有对角协方差矩阵的高斯分布及相应的高斯核。where is the log-density of the noise distribution and is a normalization constant. For instance, the Gaussian distribution with diagonal covariance matrix and the corresponding Gaussian kernel are obtained with and .
14.1.3 节的做法是在网格上用离散卷积近似上述积分(连续卷积);与之不同,期望视角提示我们可用蒙特卡洛估计来估计 :只需从该分布中抽取样本,在这些样本处对函数求值,再取平均。除单纯的蒙特卡洛估计外,[42] 还研究了更精细的近似方案。Instead of approximating the integral above (continuous convolution) with a discrete convolution on a grid, as we did in Section 14.1.3, the expectation perspective suggests that we can estimate by Monte-Carlo estimation: we simply draw samples from the distribution, evaluate the function at these samples and average. Beyond mere Monte-Carlo estimation, more elaborate approximation schemes are studied in [42].
只要交换求导与积分次序的条件成立(见 12.1 节),就有Provided that the conditions for swapping differentiation and integration hold (see Section 12.1), we have
| (14.5) |
注意,若 只是几乎处处可微,该公式仍可能成立。例如,当 为 ReLU 时, 为 Heaviside 阶跃函数,用上述公式即可得到 的正确梯度;见例 14.3.1。然而,若 并非绝对连续,该公式可能不成立。例如,当 为 Heaviside 函数时,(14.5) 的右端为 0,与 的梯度不符;仍见例 14.3.1。Note that if is only differentiable almost everywhere, the formula may still hold. For example, if is the ReLU, then is the Heaviside step function, and we obtain the correct gradient of using the formula above; see Example 14.3.1. However, if is not absolutely continuous, the formula may not hold. For example, if is the Heaviside function, the right-hand side of (14.5) is 0 which does not match the gradient of ; see again Example 14.3.1.
从 (14.4) 中 的第二个表达式可以看出,(14.5) 中的梯度公式可视为一种重参数化技巧 ;见 12.4 节。也就是说,有From the second expression of in (14.4), we can see the formula of the gradient in (14.5) as a reparametrization trick ; see Section 12.4. Namely, we have
| (14.6) |
某些情况下,我们可能无法获得 ,或者 未必绝对连续,因而 (14.5) 中的公式无法适用。遇到这类情形,可以改用 12.3 节介绍的得分函数估计量(SFE)。此处,对于 ,我们得到In some cases, we may not have access to or may not be absolutely continuous and therefore the formula in (14.5) cannot apply. For these cases, we can use the score function estimator (SFE) from Section 12.3. Here, for , we obtain
由于 PDF 可以写成Since the PDF can be written as
其中where
于是得到we obtain
综上,我们已证明To summarize, we have shown that
| (14.7) |
其中使用了变量替换 。这一技巧同样适用于估计关于 的梯度,或估计向量值函数之期望的雅可比矩阵。where we used the change of variable . The same technique can also be used if we want to estimate the gradient w.r.t. or if we want to estimate the Jacobian of the expectation of a vector-valued function.
在高斯噪声这一特殊情形下,由于 ,可得In the particular case of Gaussian noise, since , we obtain
这被称为 Stein 引理。需要指出,上式是平滑后函数 的梯度的无偏估计量;但对于原始函数 的梯度(假设该梯度存在),它却是有偏估计量。不过,平滑通常有益,因为它能加速基于梯度的算法的收敛。关于扰动后的一般程序的梯度计算,[111] 已有详细研究。This is known as Stein’s lemma. It should be noted that the above is an unbiased estimator of the gradient of the smoothed function , but a biased estimator of the gradient of the original function (assuming that it exists). However, smoothing is usually a good thing, as it can accelerate the convergence of gradient-based algorithms. Computing the gradient of perturbed general programs is studied in detail in [111].
利用对数导数恒等式,对任意具有可微密度 的分布,有Using the log-derivative identity, we have for any distribution with differentiable density
利用分部积分,并假设当 时 趋于零,可得Using integration by parts and assuming that goes to zero when , we have
由此得到恒等式We have therefore the identity
重要的是,与 12.3 节的 SFE 估计量不同,该恒等式使用的是关于 的梯度,而非关于分布参数的梯度。不过,借助重参数化 ,有 ,从而Importantly, contrary to the SFE estimator from Section 12.3, this identity uses gradients with respect to , not with respect to the parameters of the distribution. Nevertheless, using the reparametrization , we have so that
本质上,分部积分使我们能够把重参数化技巧估计量转化为 SFE 估计量。关于分部积分在机器学习中的更多应用,参见 Francis Bach 的精彩博客文章。Essentially, integration by parts allowed us to convert the reparametrization trick estimator into the SFE estimator. For more applications of integration by parts in machine learning, see Francis Bach’s excellent blog post.
如第 12 章所述,SFE 的方差偏大。现在我们对其应用方差缩减技术。为此,假设对于 , 的均值为零。例如,这一假设对高斯噪声成立。该假设意味着As discussed in Chapter 12, the SFE suffers from high variance. We now apply variance reduction techniques to it. To do so, we assume that has zero mean for . This assumption for example holds for Gaussian noise. This assumption implies that
因而and therefore
| (14.8) |
这是 12.3 节所述控制变量的一个例子。它可以理解为:用有限差分来计算沿随机方向 的方向导数(见下文“极限情形”)。受中心有限差分的启发,我们还可以使用This is an example of control variate discussed in Section 12.3. This can be interpreted as using a finite difference for computing a directional derivative in the random direction (see “limit case” below). Inspired by a central finite difference, we can also use
| (14.9) |
这些估计量已被用于黑箱(零阶)优化算法,例如进化策略 [173] 或随机无梯度优化 [147]。对于二次函数,容易证明第二个估计量的方差更低 [167]。同时采样 与 的思想被称为对偶采样(antithetic)[76] 或镜像采样(mirrored sampling)[36]。进化策略也被用于获得部分展开计算图的无偏梯度估计量 [202]。在图 14.4 中,我们实验比较了带方差缩减与不带方差缩减的 SFE 在黑箱梯度估计上的表现。These estimators have been used as part of blackbox (zero-order) optimization algorithms, such as evolution strategies [173] or random gradient-free optimization [147]. For quadratic functions, it is easy to show that the second estimator achieves lower variance [167]. The idea of sampling both and simultaneously is called antithetic [76] or mirrored sampling [36]. Evolution strategies have also been used to obtain unbiased gradient estimators of partially unrolled computational graphs [202]. We empirically compare the SFE with or without variance reduction for blackbox gradient estimation in Fig. 14.4.
现在讨论极限情形 。也就是说,我们假设不希望进行平滑,并且 存在。回顾可知, 在 处沿方向 的方向导数为We now discuss the limit case . That is, we assume that we do not want to perform smoothing and that exists. We recall that the directional derivative of at in the direction is
当 且 服从标准高斯分布,即 时,式 14.8 因而变为When and follows the standard Gaussian distribution, meaning that , Eq. 14.8 therefore becomes
这并不应太令人意外,因为从卷积的视角我们已经知道,当 时 。这重新得到了 8.7 节中已经给出的随机化前向模式估计量。This should not be too surprising, as we already know from the convolution perspective that when . This recovers the randomized forward-mode estimator already presented in Section 8.7.
Gumbel 分布是极值理论中经常使用的一种分布。如图 14.5 所示,我们考虑平移后的标准 Gumbel 分布,其 PDF 定义为The Gumbel distribution is a distribution frequently used in extreme value theory. As illustrated in Fig. 14.5, we consider the shifted standard Gumbel distribution, whose PDF is defined by
其中where
并且其中 是欧拉常数。注意,在某些表述中,该分布不做平移,即不加上 。若 服从平移后的标准 Gumbel 分布,我们记作 。and where is Euler’s constant. Note that in some formulations, the distribution is not shifted, i.e., is not added. If is distributed according to the shifted standard Gumbel distribution, we write .
为得到带有位置—尺度参数 与 的多元推广,我们取 个独立随机变量 ,并施加位置—尺度变换(12.4.1 节)。即,To obtain a multivariate extension with location-scale parameters and , we take independent random variables and apply the location-scale transform (Section 12.4.1). That is,
由于我们采用的是平移后的标准 Gumbel 分布,自然得到 与 。我们可以用 Gumbel 噪声替代 14.4 节中所用的高斯噪声。所幸,在特定情形下,我们能够以闭式形式计算扰动函数的期望。As we used shifted standard Gumbel distributions, we naturally get that and . We can use Gumbel noise as an alternative to the Gaussian noise used in Section 14.4. Thankfully, in particular cases, we can compute closed-form expressions of the expectation of perturbed functions.
首先,Gumbel 分布可用于平滑二值比较,例如大于或等于运算符。回顾后者,对任意 ,其定义为To start with, the Gumbel distribution can be used to smooth a binary comparison like the greater than or equal operators. Recall that the latter is defined for any as
其中 是 Heaviside 函数。如下文所示,用 Gumbel 噪声扰动每个变量,我们便能重新得到 ,作为 的近似。where is the Heaviside function. As shown below, by perturbing each variable with Gumbel noise, we recover as an approximation of .
我们首先推导 的 CDF,如下:We first derive the CDF of as
根据注 14.5.1,有 ,对 同理。此时容易证明,若 相互独立,则 。因此,我们得到By Remark 14.5.1, , and similarly for . Now one easily shows that if independent, then . Hence, we get
我们认出,这正是均值为 、尺度为 的 logistic 分布的 CDF,记作 。至于最后一个论断,我们只需有We recognize the CDF of the logistic distribution with mean and scale , denoted . For the last claim, we simply have that
假设我们想要平滑Suppose we want to smooth
其中where
其中 是 的 one-hot 编码。结果表明,用 Gumbel 噪声扰动后的函数 具有闭式期望,而它正是 softargmax。where is the one-hot encoding of . It turns out that the function perturbed using Gumbel noise enjoys a closed form expectation, which is nothing else than the softargmax.
对于 ,我们有For , we have that
由注 14.5.1 可知,。作为练习,读者不难验证:对于参数为 的 个独立指数随机变量,有 。由此得到By Remark 14.5.1, we have that . One easily verifies as an exercise, that, for independent exponential variables with parameters , we have . Hence, we get
即that is,
最后一个论断可由 的分布以及 的定义推出。The last claim follows from the distribution of and the definition of .
若我们此时扰动的是 max 而非 argmax,也有类似的结果。A similar result holds if we now wish to perturb the max instead of the argmax.
我们按如下方式推导 的累积分布函数:We derive the CDF of as
我们有 ;而参数为 的 个独立指数随机变量满足 。因此,We have and for independent exponential random variables with parameters , we have . Hence,
我们认出,这正是位置—尺度参数为 与 的平移 Gumbel 分布的累积分布函数。We recognize the CDF of the shifted Gumbel distribution with location-scale parameters and .
关于 Gumbel 技巧的延伸阅读,可参见 Tim Vieira 的精彩博客。For further reading on the Gumbel trick, see Tim Vieira’s great blog.
Gumbel 技巧本身也可用于采样,且无需计算 softargmax 的归一化常数。事实上,命题 14.5.5 保证:若 为 Gumbel 噪声,则 服从 分布。计算 所需的 arg-max 运算可一趟完成。因此,我们得到一种一趟算法,可直接从 logits 中采样,而无需显式计算概率 。The Gumbel trick is also useful in its own right for sampling without computing the normalization constant of the softargmax. Indeed, Proposition 14.5.5 ensures that if is Gumbel noise, then is distributed according to . Computing the arg-maximum, as required to compute , can be done in one pass. Therefore, we obtain a one-pass algorithm to sample directly from the logits , without explicitly computing the probabilities .
人们或许会问,这种技巧是否也能用于正态分布。遗憾的是,此时并不存在闭式形式,因为这需要对 个高斯分布的最大值的累积分布函数进行积分。不过,还可以定义其他技巧,例如使用 Weibull 分布,参见 [10]。One may wonder whether such trick could also be used with the normal distribution. Unfortunately, there is no closed form in this case because it would require integrating the CDF of the maximum of Gaussian distributions. However, other tricks can be defined such as using Weibull distributions, see [10].
此前,我们在分类设定下讨论了 Gumbel 技巧,其中 。在结构化预测设定中,输出通常嵌入于 之中,但输出空间极为庞大。也就是说,,但 。随后,结构化输出借助最大后验(MAP)oracle 进行解码Previously, we discussed the Gumbel trick in the classification setting, where . In the structured prediction setting, outputs are typically embedded in but the output space is very large. That is, but . Structured outputs are then decoded using a maximum a-posteriori (MAP) oracle
在这一设定下, 与 的扰动版本,For this setting, the perturbed versions of and ,
一般不再具有闭式形式。不过,我们可以借助蒙特卡洛估计对它们作近似。对于 的梯度,存在两种估计量 [2, 23]。no longer enjoy a closed form in general. However, we can approximate them using Monte-carlo estimation. For the gradient of , two estimators exist [2, 23].
第一个估计量不过是式 14.6 中重参数化技巧与 的直接推论,而后者可由 Danskin 定理得到(见 11.2 节)。第二个估计量正是式 14.7 中的 SFE。第一个估计量的方差通常更低,因为它利用了更多信息,即 。The first estimator is simply a consequence of the reparametrization trick seen in Eq. 14.6 and of , which follows from Danskin’s theorem (see Section 11.2). The second estimator is just SFE seen in Eq. 14.7. The first estimator usually has lower variance, as it uses more information, namely that .
第一个估计量使用 SFE。第二个估计量则通过对……求导得到The first estimator uses SFE. The second estimator is obtained by differentiating through
第一个估计量的方差通常更低。注意,此处无法使用重参数化技巧,因为 是不连续的,这与 不同。The first estimator usually has lower variance. Note that we cannot use the reparametrization trick this time, since is discontinuous, contrary to .
如 [23, 命题 2.2] 所示,假设 是一个内部非空的凸多胞形,且 具有严格正的概率密度,则函数As shown in [23, Proposition 2.2], assuming is a convex polytope with non-empty interior and has a strictly positive density, the function
是严格凸的,其凸共轭 属于 Legendre 型。因此,我们可以从正则化的角度将 改写为is strictly convex and its convex conjugate is Legendre-type. We can therefore rewrite from the regularization perspective as
而 是一个镜像映射,即从 到 内部的一一映射。遗憾的是, 一般而言并不具有闭式形式。反过来,是否任意正则化都有对应的噪声分布呢?答案是否定的。and is a mirror map, a one-to-one mapping from to the interior of . Unfortunately, does not enjoy a closed form in general. Conversely, does any regularization have a corresponding noise distribution? The reciprocal is not true.
假设我们希望平滑掉某个函数 与 argmax 之间的组合 Suppose we want to smooth out the composition between some function and the argmax
我们可以通过以下方式做到这一点We can do so by
例如,这对于计算损失的期望(而非期望的损失)很有用。为计算 的梯度,我们可以直接使用 SFE;然而我们已经看到,它受高方差之苦。遗憾的是,此处无法交换求导与积分(期望)的次序,因为 是一个不连续函数。关于积分号下求导的更多细节,见 12.1 节。This is useful for instance to compute the expectation of a loss (instead of the loss of an expectation). To compute the gradient of , we can readily use the SFE. However, we saw that it suffers from high variance. Unfortunately, we cannot swap differentiation and integration (expectation) here, since is a discontinuous function. See Section 12.1 for more details regarding differentiation under the integral sign.
Gumbel-softargmax [101, 125] 的核心思想是把 替换为一个 softargmax(带有温度参数 ),从而定义The key idea of the Gumbel-softargmax [101, 125] is to replace with a softargmax (with temperature parameter ) to define
由于 softargmax 是一个正则化的 argmax,我们可以把 Gumbel-softargmax 方法视为同时使用了正则化与扰动。注意,该方法也被称为 Gumbel-softmax;为与本书术语保持一致,我们使用 Gumbel-softargmax 这一名称。Since the softargmax is a regularized argmax, we can see the Gumbel-softargmax approach as using both regularization and perturbation. Note that the approach is also known as Gumbel-softmax. We use the name Gumbel-softargmax for consistency with the terminology of this book.
关键好处在于,我们现在可以交换求导与积分(期望)的次序,从而得到 的无偏估计量。不过,这将是 的有偏估计量,其偏差大小由温度 控制。特别地,在极限情形 下,有 。但有一点需要留意:函数 必须在 上有良定义,而不是在 上。The key benefit is that we can now swap differentiation and integration (expectation) to get an unbiased estimator of . However, this will be a biased estimator of , the amount of bias being controlled by the temperature . In particular, in the limit case , we have . One caveat, however, is that the function needs to be well defined on , instead of .
使用 softargmax 变换定义了连续分布 [101, 125],下面我们用 加以说明。The use of the softargmax transformation defines a continuous distribution [101, 125], that we now explain with .
我们可以把 Gumbel softargmax 推广到结构化设定,只需将We can extend the Gumbel softargmax to the structured setting by replacing
替换为其正则化变体 [152]。与之前类似,有一点需要注意: 必须在 上有良定义,而不是在 上。此外,对 做正则化在计算上并不总是容易的。with its regularized variant [152]. Similarly as before, one caveat is that needs to be well defined on instead of . Moreover, regularizing is not always easy computationally.
我们研究了基于函数与核函数卷积的平滑技术。由于卷积具有可交换性,只要该核函数对应某个噪声分布的概率密度函数,我们也可以把这些技术视为对受噪声扰动的函数取期望。We studied smoothing techniques based on function convolution with a kernel. Due to the commutativity of the convolution, we can alternatively see these as the expectation of the function, perturbed with noise, assuming the kernel corresponds to the PDF of some noise distribution.
它们的梯度可以用路径梯度估计量(PGE)或得分函数估计量(SFE)来估计,具体取决于原函数的梯度是否可得。Their gradients can be estimated using the path gradient estimator (PGE) or score function estimator (SFE), depending on whether the gradient of the original function is available or not.
我们看到,Stein 引理是与高斯噪声结合使用的 SFE 的一个特例。所谓的“进化策略”不过是它加上方差缩减后的一个变体,可解释为随机化的有限差分。We saw that Stein’s lemma is a special case of SFE used with Gaussian noise. The so-called “evolution strategies” are just a variant of that with variance reduction and can be interpreted as randomized finite difference.
当使用 Gumbel 噪声时,我们能够在特定情形下为期望推导出闭式表达式:扰动的比较、扰动的 argmax 与扰动的 max。When using Gumbel noise, we were able to derive closed-form expressions for the expectation in specific cases: perturbed comparison, perturbed argmax and perturbed max.
我们还研究了通过优化进行平滑与通过积分进行平滑之间的联系。下确卷积是卷积的对应物,Legendre-Fenchel 变换则是 Fourier 变换与 Laplace 变换的对应物。下确卷积在对数域中使用最小—加代数,而卷积在指数域中使用和—积代数。We also studied the connections between smoothing by optimization and smoothing by integration. Infimal convolution is the counterpart of convolution, and the Legendre-Fenchel transform is the counterpart of Fourier and Laplace’s transforms. Infimal convolution uses a min-plus algebra in the log domain, while the convolution uses a sum-product algebra in the exponential domain.