The Elements of Differentiable Programming
Part IV Smoothing programs

Chapter 13Smoothing by optimization

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 Primal approach

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∪{∞}\R\cup \{\infty\}. For a function f:RM→R∪{∞}f:\RR^M \rightarrow \RR \cup \{\infty\}, we define its domain as dom(f)={u∈RM:f(u)<∞}. \mathrm{dom}(f) = \{\u\in \RR^M: f(\u) < \infty\}.

13.1.1 Infimal convolution

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.

Definition 13.1 (Infimal convolution)

The infimal convolution between two functions f ⁣:RM→R∪{∞}f \colon \RR^M \to \RR \cup \{\infty\} and g ⁣:RM→R∪{∞}g \colon \RR^M \to \RR \cup \{\infty\} is defined by (f□g)(μ)≔inf⁡u∈RMf(u)+g(μ−u)=inf⁡z∈RMf(μ+z)+g(−z)=inf⁡u,z∈RMf(u)+g(−z) s.t. u=μ+z.\begin{align*} (f \square g)(\muv) &\coloneqq \inf_{\u \in \RR^M} f(\u) + g(\muv - \u) \\ &= \inf_{\z \in \RR^M} f(\muv + \z) + g(-\z) \\ &= \inf_{\u, \z \in \RR^M} f(\u) + g(-\z) \text{ s.t. } \u = \muv + \z. \end{align*}

It is easy to check that the three definitions are indeed equivalent, by using the change of variable u≔μ+z\u \coloneqq \muv + \z, which is a location-scale transform; see Section 12.4.1.

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\muv \in \RR^M, we have (f□g)(μ)=(g□f)(μ). (f \square g)(\muv) = (g \square f)(\muv).

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

The infimal convolution (f□g)(μ)(f \square g)(\muv) exists if the infimum inf⁡u∈RMf(u)+g(μ−u)\inf_{\u \in \RR^M} f(\u) + g(\muv - \u) is finite (Bauschke and Combettes, 2017, Proposition 12.6). A sufficient condition to achieve this is that u↦f(u)+g(μ−u)\u \mapsto f(\u) + g(\muv - \u) is convex for all μ∈RM\muv \in \RR^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

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.

Table 13.1: Examples of infimal convolutions. We use ιC\indic_\cC to denote the indicator function of the set C\cC.

f(u)f(\u) g(z)g(\z) (f□g)(μ)(f \square g)(\muv)
f(u)f(\u) 00 inf⁡u∈RMf(u)\inf_{\u \in \RR^M} f(\u)
f(u)f(\u) ι{v}(z)\indic_{\{\v\}}(\z) f(μ−v)f(\muv - \v)
ιC(u)\indic_\cC(\u) ιD(z)\indic_\cD(\z) ιC+D(μ)\indic_{\cC + \cD}(\muv)
ιC(u)\indic_\cC(\u) ∥z∥2\|\z\|_2 dC(μ)=inf⁡u∈C∥μ−u∥2d_\cC(\muv) = \inf_{\u \in \cC} \|\muv - \u\|_2
f(u)f(\u) 12∥z∥22\frac{1}{2}\|\z\|_2^2 envf(μ)=inf⁡u∈RM12∥μ−u∥22+f(u)\env_f(\muv) = \inf_{\u \in \RR^M} \frac{1}{2}\|\muv - \u\|_2^2 + f(\u)

13.1.2 Moreau envelope

When R(z)≔12∥z∥22R(\z) \coloneqq \frac{1}{2} \|\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.

Definition 13.2 (Moreau envelope)

Given a function f ⁣:RM→R∪{∞}f \colon \RR^M \to \RR \cup \{\infty\}, its Moreau envelope is defined as envf(μ)≔(f□12∥⋅∥22)(μ)=inf⁡u∈RMf(u)+12∥μ−u∥22=inf⁡z∈RMf(μ+z)+12∥z∥22.\begin{align*} \env_f(\muv) &\coloneqq \left(f \square \frac{1}{2} \|\cdot\|^2_2\right)(\muv) \\ &= \inf_{\u \in \RR^M} f(\u) + \frac{1}{2} \|\muv - \u\|_2^2 \\ &= \inf_{\z \in \RR^M} f(\muv + \z) + \frac{1}{2} \|\z\|_2^2. \end{align*}

Intuitively, the Moreau envelope is the minimal value over u∈RM\u \in \RR^M of a trade-off between staying close to the input μ\muv according to the proximity term 12∥μ−u∥22\frac{1}{2}\|\muv-\u\|_2^2 and minimizing f(u)f(\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}(\muv) \coloneqq \argmin_{\u \in \RR^M} \frac{1}{2} \|\muv - \u\|_2^2 + f(\u). In other words, we have for proxf(μ)\mathrm{prox}_{f}(\muv) well defined, envf(μ)=f(proxf(μ))+12∥μ−proxf(μ)∥22.(13.1) \env_f(\muv) = f(\mathrm{prox}_f(\muv)) + \frac{1}{2} \|\muv - \mathrm{prox}_f(\muv)\|_2^2. \tag{13.1}

Properties

A crucial property of the Moreau envelope envf\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\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.

Proposition 13.1 (Properties of Moreau envelope)

Let f ⁣:RM→R∪{∞}f \colon \RR^M \to \RR \cup \{\infty\}.

  1. Smoothness: If ff is convex, the function envf\env_f is 11-smooth.

  2. Gradient: Provided that proxf(μ)\mathrm{prox}_f(\muv) is well-defined on μ∈RM\muv \in \RR^M, the gradient of the Moreau envelope can be expressed in terms of the proximal operator as ∇envf(μ)=μ−proxf(μ). \nabla \env_f(\muv) = \muv - \mathrm{prox}_f(\muv).

  3. Moreau decomposition: If ff is convex, then for any μ∈RM\muv \in \RR^M, we have the following identity proxf(μ)+proxf∗(μ)=μ, \mathrm{prox}_f(\muv) + \mathrm{prox}_{f^*}(\muv) = \muv, where f∗f^* is the convex conjugate of ff, detailed in Section 13.2. In particular, we get ∇envf∗(μ)=proxf(μ). \nabla \env_{f^*}(\muv) = \mathrm{prox}_f(\muv).

  4. Convexity: envf\env_f is convex if ff is convex.

  5. Infimums coincide: envf\env_f has the same infimum as the original function ff: min⁡μ∈RMenvf(μ)=min⁡u∈RMf(u). \min_{\muv \in \RR^M} \env_f(\muv) = \min_{\u \in \RR^M} f(\u).

Proof
  1. This is best seen using the dual approach detailed in Section 13.3.

  2. This follows from Danskin’s theorem, reviewed in Section 11.2.

  3. See, e.g., Bauschke and Combettes (2017, Theorem 14.3).

  4. This follows from the fact that the infimum of a jointly convex function is convex.

  5. We have inf⁡μ∈RMenvf(μ)=inf⁡μ∈RMinf⁡u∈RM12∥μ−u∥22+f(u)=inf⁡u∈RMinf⁡μ∈RM12∥μ−u∥22+f(u)=inf⁡u∈RMf(u).\begin{align*} \inf_{\muv \in \RR^M} \env_f(\muv) &= \inf_{\muv \in \RR^M} \inf_{\u \in \RR^M} \frac{1}{2} \|\muv - \u\|^2_2 + f(\u) \\ &= \inf_{\u \in \RR^M} \inf_{\muv \in \RR^M} \frac{1}{2} \|\muv - \u\|^2_2 + f(\u) \\ &= \inf_{\u \in \RR^M} f(\u). \end{align*}

 ◻

Examples

Figure 13.1: The Huber loss is the Moreau envelope of the absolute loss.

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.

Example 13.1 (Smoothing the 11-norm via infimal convolution)

We wish to smooth f(u)≔∥u∥1=∑j=1M∣uj∣f(\u) \coloneqq \|\u\|_1 = \sum_{j=1}^M |u_j|. The corresponding proximal operator is the soft-thresholding operator (see Section 16.4), proxf(μ)=arg min⁡u∈RM12∥μ−u∥22+∥u∥1=sign(μ)⋅max⁡(∣μ∣−1,0).\begin{align*} \mathrm{prox}_{f}(\muv) &= \argmin_{\u \in \RR^M} \frac{1}{2} \|\muv - \u\|^2_2 + \|\u\|_1 \\ &= \mathrm{sign}(\muv) \cdot \max(|\muv| - 1, 0). \end{align*} Using Eq. (13.1) and after some algebraic manipulations, we obtain envf(μ)=∑j=1Mhuber(μj)≈∑j=1M∣μj∣, \env_f(\muv) = \sum_{j=1}^M \mathrm{huber}(\mu_j) \approx \sum_{j=1}^M |\mu_j|, 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} &\mbox{ if } |\mu_j| \le 1 \\ |\mu_j| - \frac{1}{2} &\mbox{ if } |\mu_j| > 1 \end{cases}. This is illustrated in Fig. 13.1 with M=1M=1.

We also illustrate in Fig. 13.2 that the Moreau envelope of nonconvex functions can be approximately computed numerically.

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 \RR in Definition 13.2 by restricting the search on a finite grid, in a closed interval.

13.1.3 Vector-valued functions

The Moreau envelope is defined by envf(μ)≔inf⁡u∈RMf(u)+12∥μ−u∥22\env_f(\muv) \coloneqq \inf_{\u \in \RR^M} f(\u) + \frac{1}{2} \|\muv - \u\|_2^2. As such, it is limited to scalar-valued functions f ⁣:RM→Rf \colon \RR^M \to \RR. To extend the Moreau envelope to vector-valued functions f ⁣:RM→RTf \colon \RR^M \to \RR^T, where f(u)=(f1(u),…,fT(u))f(\u) = (f_1(\u), \dots, f_T(\u)) and fi ⁣:RM→Rf_i \colon \RR^M \to \RR for i∈[T]i \in [T], we may choose to smooth each fjf_j separately to define envf(μ)≔(envf1(μ),…,envfT(μ)), \envv_f(\muv) \coloneqq (\env_{f_1}(\muv), \dots, \env_{f_T}(\muv)), where envfi(μ)=inf⁡ui∈RMfi(ui)+12∥μ−ui∥22. \env_{f_i}(\muv) = \inf_{\u_i \in \RR^M} f_i(\u_i) + \frac{1}{2} \|\muv - \u_i\|_2^2. This approach requires solving TT separate minimization problems and performs the smoothing of each output coordinate i∈[T]i \in [T] independently. From Proposition 2.9, we then have that the VJP of envf(μ)\envv_f(\muv) with any direction d=(d1,…,dT)∈RT\d = (d_1, \dots, d_T) \in \RR^T is ∂envf(μ)∗[d]=∑i=1T∂envfi(μ)∗[di]=∑i=1Tdi∇envfi(μ).\begin{align*} \partial \envv_f(\muv)^*[\d] &= \sum_{i=1}^T \partial \env_{f_i}(\muv)^*[d_i] \\ &= \sum_{i=1}^T d_i \nabla \env_{f_i}(\muv). \end{align*} In the particular case f(u)=(f1(u1),…,fT(uT))f(\u) = (f_1(u_1), \dots, f_T(u_T)), we obtain ∂envf(μ)∗[d]=∑i=1Tdi∇envfi(μi). \partial \envv_f(\muv)^*[\d] = \sum_{i=1}^T d_i \nabla \env_{f_i}(\mu_i).

An alternative was proposed by Roulet and Harchaoui (2022). For a differentiable function f ⁣:RM→RTf \colon \RR^M \to \RR^T, we recall that the VJP of ff with a direction d∈RT\d \in \RR^T reads ∂f(u)∗[d]=∇⟨f,d⟩(u), \partial f(\u)^*[\d] = \nabla \langle f, \d \rangle(\u), where we defined the scalar-valued function ⟨f,d⟩(u)≔⟨f(u),d⟩\langle f, \d \rangle(\u) \coloneqq \langle f(\u), \d \rangle. As a result, if ff is non-differentiable, a natural idea is to approximate its VJP ∂f(u)∗[d]\partial f(\u)^*[\d] (had it existed) by the gradient ∇env⟨f,d⟩(μ)\nabla \env_{\langle f, \d \rangle}(\muv) of the Moreau envelope env⟨f,d⟩(μ)=inf⁡u∈RM⟨f(u),d⟩+12∥μ−u∥22.(13.2) \env_{\langle f, \d \rangle}(\muv) = \inf_{\u \in \RR^M} \langle f(\u), \d \rangle + \frac{1}{2} \|\muv - \u\|^2_2. \tag{13.2} This requires solving a single optimization problem, independently of the number of outputs TT. Moreover, for d=ei\d = \e_i, this recovers envfi(μ)\env_{f_i}(\muv) as a special case.

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, the approximate VJP of ff with a direction d\d is given by ∂f(μ)∗[d]≈∇env⟨f,d⟩(μ)=μ−u⋆, \partial f(\muv)^*[\d] \approx \nabla \env_{\langle f, \d \rangle}(\muv) = \muv - \u^\star, where u⋆\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\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\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(\u) = (f_1(u_1), \dots, f_T(u_T)), one easily checks that for d=(d1,…,dT)\d = (d_1, \dots, d_T), we get env⟨f,d⟩(μ)=∑i=1Tenvdifi(μi). \env_{\langle f, \d \rangle}(\muv) = \sum_{i=1}^T \env_{d_i f_i}(\mu_i). 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 transforms, convex conjugates

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. \u \mapsto \langle \u, \v \rangle - b. These functions are parametrized by their slope v∈RM\v \in \RR^M and their intercept −b∈R-b \in \RR. Now, suppose we fix v\v. Given a function f(u)f(\u), affine lower bounds of f(u)f(\u) are all the functions of u\u such that bb satisfies for all u∈RM\u \in \RR^M, ⟨u,v⟩−b≤f(u)  ⟺  ⟨u,v⟩−f(u)≤b. \langle \u, \v \rangle - b \le f(\u) \iff \langle \u, \v \rangle - f(\u) \le b. The tightest lower bound is then defined by bb such that b≔sup⁡u∈dom⁡(f)⟨u,v⟩−f(u), b \coloneqq \sup_{\u \in \dom(f)} \langle \u, \v \rangle - f(\u), where we recall that the domain of ff is defined by dom⁡(f)≔{u∈RM ⁣:f(u)<∞}. \dom(f) \coloneqq \{\u \in \RR^M \colon f(\u) < \infty\}. This leads to the definition of Legendre-Fenchel transform, a.k.a. convex conjugate.

Definition 13.3 (Legendre-Fenchel transform, convex conjugate)

Given a function f ⁣:RM→R∪{∞}f \colon \RR^M \to \RR \cup \{\infty\}, its convex conjugate is defined by f∗(v)≔sup⁡u∈dom⁡(f)⟨u,v⟩−f(u). f^*(\v) \coloneqq \sup_{\u \in \dom(f)} \langle \u, \v \rangle - f(\u).

We use a sup⁡\sup rather than a max⁡\max to indicate that f∗(v)f^*(\v) is potentially ∞\infty. Following the previous discussion, −f∗(v)-f^*(\v) is the intercept of the tightest affine lower bound with slope v\v of f(u)f(\u). This is illustrated in Fig. 13.3.

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.

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))(\u, f(\u)) for u∈dom⁡(f)\u \in \dom(f), we can represent it by the set of tangents with slope v\v and intercept −f∗(v)-f^*(\v) for v∈dom⁡(f∗)\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.

Figure 13.4: Left: instead of representing a convex function ff by its graph (u,f(u))(\u, f(\u)) for u∈dom⁡(f)\u \in \dom(f), we can represent it by the set of tangents with slope v\v and intercept −f∗(v)-f^*(\v) for v∈dom⁡(f∗)\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

Computing f∗(v)f^*(\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.

Example 13.2 (Analytical conjugate examples)

When f(u)=12∥u∥22f(\u) = \frac{1}{2} \|\u\|_2^2, with dom⁡(f)=RM\dom(f) = \RR^M, the conjugate is f∗(v)=max⁡u∈RM⟨u,v⟩−12∥u∥22. f^*(\v) = \max_{\u \in \RR^M} \langle \u, \v \rangle - \frac{1}{2} \|\u\|^2_2. Setting the gradient u↦⟨u,v⟩−12∥u∥22\u \mapsto \langle \u, \v \rangle - \frac{1}{2} \|\u\|^2_2 to zero, we obtain u⋆=v\u^\star = \v. Plugging u⋆\u^\star back, we therefore obtain f∗(v)=⟨u⋆,v⟩−12∥u⋆∥22=12∥v∥22. f^*(\v) = \langle \u^\star, \v \rangle - \frac{1}{2} \|\u^\star\|^2_2 = \frac{1}{2} \|\v\|^2_2. Therefore, f=f∗f = f^* in this case.

When f(u)=⟨u,log⁡u⟩f(\u) = \langle \u, \log \u \rangle, with dom⁡(f)=R+M\dom(f) = \RR_+^M, the minimizer of u↦⟨u,v⟩−⟨u,log⁡u⟩\u \mapsto \langle \u, \v \rangle - \langle \u, \log \u \rangle is u⋆=exp⁡(v−1⁡)\u^\star = \exp(\v-\ones) and the conjugate is f∗(v)=∑j=1Mexp⁡(vj−1). f^*(\v) = \sum_{j=1}^M \exp(v_j - 1).

See for instance Boyd and Vandenberghe (2004) or Beck (2017) for many more examples.

Constraining the domain

We can incorporate constraints using an indicator function with values in the extended real line R∪{∞}\RR \cup \{\infty\}, ιC(u)≔{0 if u∈C+∞ otherwise . \indic_\cC(\u) \coloneqq \begin{cases} 0 &\mbox{ if } \u \in \cC \\ +\infty &\mbox{ otherwise } \end{cases}.

Example 13.3 (Incorporating constraints)

If f(u)=ιC(u)f(\u) = \indic_\cC(\u), where C\cC is a convex set, then f∗(v)=sup⁡u∈dom⁡(f) ⟨u,v⟩−f(u)=sup⁡u∈C ⟨u,v⟩≔σC(v), f^*(\v) = \sup_{\u \in \dom(f)} ~ \langle \u, \v \rangle - f(\u) = \sup_{\u \in \cC} ~ \langle \u, \v \rangle \coloneqq \sigma_{\cC}(\v), which is known as the support function of C\cC. The corresponding argmax (assuming that it exists), v↦arg max⁡u∈C⟨u,v⟩, \v \mapsto \argmax_{\u \in \cC} \langle \u, \v \rangle, is known as the linear maximization oracle (LMO) of C\cC. As another example, if f(u)=⟨u,log⁡u⟩+ι△M(u)f(\u) = \langle \u, \log \u \rangle + \indic_{\triangle^M}(\u) then f∗(v)=logsumexp(v)=log⁡∑i=1Mexp⁡(vi). f^*(\v) = \lse(\v) = \log \sum_{i=1}^M \exp(v_i). We postpone a proof to Proposition 13.9.

13.2.3 Properties

The conjugate enjoys several useful properties, that we now summarize.

Proposition 13.2 (Convex conjugate properties)

 

  1. Convexity: f∗(v)f^*(\v) is a convex function for all f ⁣:RM→R∪{∞}f \colon \RR^M \to \RR \cup \{\infty\} (even if ff is nonconvex).

  2. Fenchel-Young inequality: for all u,v∈RM\u, \v \in \RR^M f(u)+f∗(v)−⟨u,v⟩≥0. f(\u) + f^*(\v) - \langle \u, \v \rangle \ge 0.

  3. Gradient: if the supremum in Definition 13.3 is uniquely achieved, then f∗(v)f^*(\v) is differentiable at v\v and its gradient is ∇f∗(v)=arg max⁡u∈dom⁡(f)⟨u,v⟩−f(u). \nabla f^*(\v) = \argmax_{\u \in \dom(f)} \langle \u, \v \rangle - f(\u). Otherwise, f∗(v)f^*(\v) is sub-differentiable at v\v and we get a sub-gradient instead.

  4. Maps: If ff and f∗f^* are differentiable, then v=∇f(u)  ⟺  u=∇f∗(v)  ⟺  f∗(v)+f(u)−⟨u,v⟩=0. \v = \nabla f(\u) \iff \u = \nabla f^*(\v) \iff f^*(\v) + f(\u) - \langle \u, \v \rangle = 0.

  5. 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^{**} \le f.

Proof
  1. This follows from the fact that v↦sup⁡u∈Cg(u,v)\v \mapsto \sup_{\u \in \cC} g(\u, \v) is convex if gg is convex in v\v. Note that this is true even if gg is nonconvex in u\u. Here, g(u,v)=⟨u,v⟩−f(u)g(\u, \v) = \langle \u, \v \rangle - f(\u), which is affine in v\v and therefore convex in v\v.

  2. This follows immediately from Definition 13.3.

  3. This follows from Danskin’s theorem, reviewed in Section 11.2. Another way to see this is by observing that f∗(v)=⟨g,v⟩−f(g)f∗(v′)≥⟨g,v′⟩−f(g),\begin{align*} f^*(\v) &= \langle \g, \v \rangle - f(\g) \\ f^*(\v') &\ge \langle \g, \v' \rangle - f(\g), \end{align*} where g≔arg max⁡u∈dom⁡(f)⟨u,v⟩−f(u)\g \coloneqq \displaystyle{\argmax_{\u \in \dom(f)}} \langle \u, \v \rangle - f(\u). Subtracting the two, we obtain f∗(v′)≥f∗(v)+⟨g,v′−v⟩. f^*(\v') \ge f^*(\v) + \langle \g, \v' - \v \rangle. Now, using that f∗f^* is convex and Definition 15.6, we obtain that g=∇f∗(v)\g = \nabla f^*(\v).

  4. See, e.g., Bauschke and Combettes (2017, Proposition 16.10).

  5. See Boyd and Vandenberghe (2004, 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.

Proposition 13.3 (Conjugate calculus rules)

 

  1. Separable sum of functions: if f(u)=∑j=1Mfj(uj)f(\u) = \sum_{j=1}^M f_j(u_j), then f∗(v)=∑j=1Mfj∗(vj). f^*(\v) = \sum_{j=1}^M f^*_j(v_j).

  2. Scalar multiplication: if f(u)=c⋅g(u)f(\u) = c \cdot g(\u), for c>0c > 0, then f∗(v)=c⋅g∗(v/c). f^*(\v) = c \cdot g^*(\v / c).

  3. Addition to an affine function and translation: if f(u)=g(u)+⟨α,u⟩+βf(\u) = g(\u) + \langle \alphav, \u \rangle + \beta, then f∗(v)=g∗(v−α)−β. f^*(\v) = g^*(\v - \alphav) - \beta.

  4. Composition with an invertible linear map: if f(u)=g(Mu)f(\u) = g(M\u), where x↦Mxx\mapsto M\x is an invertible linear map, then f∗(v)=g∗(M−Tv). f^*(\v) = g^*(M^{-T} \v).

  5. 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 Fast Legendre transform

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.3 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 (Jaggi, 2013). Without convexity assumption on ff, f∗(v)f^*(\v) can be approximated by f∗(v)≈sup⁡u∈U⟨u,v⟩−f(u), f^*(\v) \approx \sup_{\u \in \cU} \langle \u, \v \rangle - f(\u), where U⊆dom⁡(f)\cU \subseteq \dom(f) is a discrete grid of values. We can then compute f∗(v)f^*(\v) for several inputs v∈V\v \in \cV using the linear-time Legendre transform algorithm (Lucet, 1997), where V⊆dom⁡(f∗)\cV \subseteq \dom(f^*) is another discrete grid. The complexity is O(∣U∣⋅∣V∣)O(|\cU| \cdot |\cV|), which is linear in the grid sizes. However, the grid sizes are typically ∣U∣=∣V∣=O(NM)|\cU| = |\cV| = 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 Dual approach

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

We begin by stating a well-known result that will underpin this whole section: smoothness and strong convexity are dual to each other (Beck, 2017; Hiriart-Urruty and Lemaréchal, 1993; Kakade et al., 2009; Zhou, 2018).

Proposition 13.4 (Duality between strong convexity and smoothness)

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^*).

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.

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} \|\u\|_2^2 ∥⋅∥2\|\cdot\|_2 RM\RR^M 12∥v∥22\frac{1}{2} \|\v\|_2^2 ∥⋅∥2\|\cdot\|_2 RM\RR^M
⟨u,log⁡u⟩\langle \u, \log \u \rangle ∥⋅∥1\|\cdot\|_1 △M\triangle^M logsumexp(v)\mathrm{logsumexp}(\v) ∥⋅∥∞\|\cdot\|_\infty RM\RR^M

13.3.2 Smoothing by dual regularization

The duality between smoothness and strong convexity suggests a generic approach in order to smooth a function f ⁣:RM→Rf \colon \RR^M \to \RR, by going through the dual space.

  1. Compute the conjugate f∗f^*: f∗(v)≔sup⁡u∈dom⁡(f)⟨u,v⟩−f(u). f^*(\v) \coloneqq \sup_{\u \in \dom(f)} \langle \u, \v \rangle - f(\u).

  2. Add strongly-convex regularization Ω\Omega to the conjugate: fΩ∗(v)≔f∗(v)+Ω(v).(13.3) f_\Omega^*(\v) \coloneqq f^*(\v) + \Omega(\v). \tag{13.3}

  3. 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(\u) \coloneqq f^{**}_\Omega(\u) = \max_{\v \in \RR^M} \langle \u, \v \rangle - f_\Omega^*(\v).

Note that u\u and v\v belong to different spaces, i.e., u∈dom⁡(f)\u \in \dom(f) and v∈dom⁡(f∗)\v \in \dom(f^*). Following Proposition 13.4, if Ω\Omega is μ\mu-strongly convex, then fΩ(u)f_\Omega(\u) is 1μ\frac{1}{\mu}-smooth. Furthermore, following Proposition 13.2, fΩ(u)f_\Omega(\u) is convex, even if ff is nonconvex. Therefore, fΩ(u)f_\Omega(\u) is a smooth and convex relaxation of f(u)f(\u).

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.

Example 13.4 (Smoothing the 11-norm via dual regularization)

We revisit Example 13.1, this time from the dual perspective. We wish to smooth out the 11-norm f(u)≔∥u∥1=∑j=1M∣uj∣f(\u) \coloneqq \|\u\|_1 = \sum_{j=1}^M |u_j|.

  1. Compute the conjugate. The conjugate of any norm ∥⋅∥\|\cdot\| is the indicator function of the dual norm’s unit ball {v∈RM ⁣:∥v∥∗≤1}\{\v \in \RR^M \colon \|\v\|_* \le 1\} (see e.g. Boyd and Vandenberghe (2004, Example 3.26)). The dual norm of ∥u∥1\|\u\|_1 is ∥v∥∞\|\v\|_\infty. Moreover, {v∈RM ⁣:∥v∥∞≤1}=[−1,1]M. \{ \v \in \RR^M \colon \|\v\|_\infty \le 1\} = [-1, 1]^M. Recalling that ιC\indic_\cC is the indicator function of C\cC, we obtain f∗(v)=ι[−1,1]M(v). f^*(\v) = \indic_{[-1,1]^M}(\v).

  2. Adding strongly-convex regularization. We add quadratic regularization Ω(v)≔12∥v∥22\Omega(\v) \coloneqq \frac{1}{2} \|\v\|_2^2 to define fΩ∗(v)≔ι[−1,1]M(v)+Ω(v). f^*_\Omega(\v) \coloneqq \indic_{[-1,1]^M}(\v) + \Omega(\v).

  3. Going back to the primal. fΩ(u)=fΩ∗∗(u)=⟨u,v⋆⟩−Ω(v⋆)=∑i=1Mhuber(ui), f_\Omega(\u) = f_\Omega^{**}(\u) = \langle \u, \v^\star \rangle - \Omega(\v^\star) = \sum_{i=1}^M \mathrm{huber}(u_i), where v⋆=clip(u)≔max⁡(min⁡(u,1),−1) \v^\star = \mathrm{clip}\left(\u\right) \coloneqq \max\left(\min\left(\u, 1\right), -1\right) .

We therefore indeed recover the Huber loss from Example 13.1.

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.

Proposition 13.5 (Bounding the smoothed function)

Let ff be a closed convex function. Let Ω\Omega be a convex function. If Ω\Omega is such that LΩ≤Ω(v)≤UΩ\cL_\Omega \le \Omega(\v) \le \cU_\Omega for all v∈dom⁡(Ω)\v \in \dom(\Omega), then for all u∈RM\u \in \RR^M, f(u)−UΩ≤fΩ(u)≤f(u)−LΩ. f(\u) - \cU_\Omega \le f_\Omega(\u) \le f(\u) - \cL_\Omega.

Proof

Let us define v⋆≔arg max⁡v∈RM⟨u,v⟩−f∗(v)vΩ⋆≔arg max⁡v∈RM⟨u,v⟩−fΩ∗(v),\begin{align*} \v^\star &\coloneqq \argmax_{\v \in \RR^M} \langle \u, \v \rangle - f^*(\v)\\ \v^\star_\Omega &\coloneqq \argmax_{\v \in \RR^M} \langle \u, \v \rangle - f^*_\Omega(\v), \end{align*} where we recall that fΩ∗≔f∗+Ωf^*_\Omega \coloneqq f^* + \Omega. We then have for all u∈RM\u \in \RR^M fΩ(u)=⟨u,vΩ⋆⟩−fΩ∗(vΩ⋆)≥⟨u,v⋆⟩−fΩ∗(v⋆)=⟨u,v⋆⟩−f∗(v⋆)−Ω(v⋆)=f∗∗(u)−Ω(v⋆)=f(u)−Ω(v⋆),\begin{align*} f_\Omega(\u) &= \langle \u, \v^\star_\Omega \rangle - f_\Omega^*(\v^\star_\Omega) \\ &\ge \langle \u, \v^\star \rangle - f_\Omega^*(\v^\star) \\ &= \langle \u, \v^\star \rangle - f^*(\v^\star) - \Omega(\v^\star) \\ &= f^{**}(\u) - \Omega(\v^\star) \\ &= f(\u) - \Omega(\v^\star), \end{align*} Similarly, f(u)−Ω(vΩ⋆)=⟨u,v⋆⟩−f∗(v⋆)−Ω(vΩ⋆)≥⟨u,vΩ⋆⟩−fΩ∗(vΩ⋆)=fΩ∗∗(u)=fΩ(u).\begin{align*} f(\u) - \Omega(\v^\star_\Omega) &= \langle \u, \v^\star \rangle - f^*(\v^\star) - \Omega(\v^\star_\Omega) \\ &\ge \langle \u, \v^\star_\Omega \rangle - f_\Omega^*(\v^\star_\Omega) \\ &= f_\Omega^{**}(\u) \\ &= f_\Omega(\u). \end{align*} Combining the two with LΩ≤Ω(v)≤UΩ\cL_\Omega \le \Omega(\v) \le \cU_\Omega for all v∈dom⁡(Ω)\v \in \dom(\Omega), we obtain f(u)−UΩ≤f(u)−Ω(v⋆)≤fΩ(u)≤f(u)−Ω(vΩ⋆)≤f(u)−LΩ.\begin{align*} f(\u) - \cU_\Omega &\le f(\u) - \Omega(\v^\star) \\ &\le f_\Omega(\u) \\ &\le f(\u) - \Omega(\v^\star_\Omega) \\ &\le f(\u) - \cL_\Omega. \end{align*} ◻

Remark 13.1 (The gradient is differentiable almost everywhere)

From Proposition 13.2, the gradient of fΩ(u)f_\Omega(\u) equals ∇fΩ(u)=arg max⁡v∈RM⟨u,v⟩−fΩ∗(v). \nabla f_\Omega(\u) = \argmax_{\v \in \RR^M} \langle \u, \v \rangle - f_\Omega^*(\v). 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

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 \RR 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.

Proposition 13.6 (Equivalence between primal and dual regularizations)

Let f ⁣:RM→R∪{∞}f \colon \RR^M \to \RR \cup \{\infty\} and R ⁣:RM→R∪{∞}R \colon \RR^M \to \RR \cup \{\infty\}, both convex and closed. Then, fΩ=(f∗+Ω)∗=f□Rf_\Omega = (f^* + \Omega)^* = f \square R with Ω=R∗\Omega = R^*.

Proof

We have fΩ(u)=(f∗+Ω)∗(u)=sup⁡v∈dom⁡(f∗)⟨u,v⟩−f∗(v)−Ω(v). f_\Omega(\u) = (f^* + \Omega)^*(\u) = \sup_{\v \in \dom(f^*)} \langle \u, \v \rangle - f^*(\v) - \Omega(\v). If h1h_1 and h2h_2 are convex, we have (h1+h2)∗=h1∗□h2∗(h_1 + h_2)^* = h_1^* \square h_2^* (Beck, 2017, 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). ◻

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Ω∗. \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.

In this book, we focus on applications of smoothing techniques to differentiable programming. For applications to non-smooth optimization, see (Beck and Teboulle, 2012; Nesterov; 2005).

13.3.4 Regularization scaling

Dual approach

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}(\u) \coloneqq (f^* + \varepsilon \Omega)^*(\u) = \sup_{\v \in \dom(f^*)} \langle \u, \v \rangle - f^*(\v) - \varepsilon \Omega(\v). Consequently, the gradient is given by ∇fεΩ(u)=arg max⁡v∈dom⁡(f∗)⟨u,v⟩−f∗(v)−εΩ(v). \nabla f_{\varepsilon \Omega}(\u) = \argmax_{\v \in \dom(f^*)} \langle \u, \v \rangle - f^*(\v) - \varepsilon \Omega(\v). This formulation works for any closed convex ff. The approximation error induced by the smoothing can be quantified using Proposition 13.5. Provided that LΩ≤Ω(v)≤UΩ\cL_\Omega \le \Omega(\v) \le \cU_\Omega for all v∈dom⁡(Ω)\v \in \dom(\Omega), we have f(u)−εUΩ≤fεΩ(u)≤f(u)−εLΩ. f(\u) - \varepsilon \cU_\Omega \le f_{\varepsilon \Omega}(\u) \le f(\u) - \varepsilon \cL_\Omega.

Remark 13.2 (Homogeneous case)

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)=εfΩ(u/ε)∇fεΩ(u)=∇fΩ(u/ε).\begin{align*} f_{\varepsilon \Omega}(\u) &= \varepsilon f_\Omega(\u/\varepsilon) \\ \nabla f_{\varepsilon \Omega}(\u) &= \nabla f_\Omega(\u/\varepsilon). \end{align*}

Primal approach

Following Definition 13.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). In the particular case Ω(v)=12∥v∥22\Omega(\v) = \frac{1}{2} \|\v\|^2_2, we have R(u)=ε2∥u/ε∥22=12ε∥u∥22=1εΩ(u). R(\u) = \frac{\varepsilon}{2} \|\u / \varepsilon\|^2_2 = \frac{1}{2 \varepsilon} \|\u\|^2_2 = \frac{1}{\varepsilon} \Omega(\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} \env_{\varepsilon f}.

13.3.5 Generalized entropies

A natural choice of dual regularization Ω(π)\Omega(\piv), when π∈△M\piv \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

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\}).

Given an information content function, we can then define the entropy H(Y)H(Y) of a random variable Y∈YY \in \cY as the expected information content, H(Y)≔E[I(Y)]. H(Y) \coloneqq \EE[I(Y)]. Different definitions of information content lead to different definitions of entropy.

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). 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 (Shannon, 1948) H(Y)=E[I(Y)]=−∑y∈Yp(y)log⁡p(y). H(Y) = \EE[I(Y)] = -\sum_{y \in \cY} p(y) \log p(y). We can therefore define the Shannon entropy of a discrete probability distribution π∈△M\piv \in \triangle^M as H(π)=−∑i=1Mπilog⁡πi=−⟨π,log⁡π⟩ H(\piv) = -\sum_{i=1}^M \pi_i \log \pi_i = -\langle \piv, \log \piv \rangle and use the corresponding negentropy as regularization Ω(π)=−H(π)=⟨π,log⁡π⟩. \Omega(\piv) = -H(\piv) = \langle \piv, \log \piv \rangle. The function is strongly convex w.r.t. ∥⋅∥1\|\cdot\|_1 over △M\triangle^M. However, it is not strongly convex over R+M\RR_+^M, since this is not a bounded set; see for instance (Blondel, 2019, 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’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)). 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 (Gini, 1912) H(Y)=E[I(Y)]=12∑y∈Yp(y)(1−p(y)). H(Y) = \EE[I(Y)] = \frac{1}{2} \sum_{y \in \cY} p(y) (1 - p(y)). We can use Gini’s negative entropy to define for all π∈△M\piv \in \triangle^M Ω(π)=12⟨π,π−1⁡⟩=12(∥π∥22−1). \Omega(\piv) = \frac{1}{2} \langle \piv, \piv - \ones \rangle = \frac{1}{2} (\|\piv\|^2_2 - 1). The function is strongly convex w.r.t. ∥⋅∥2\|\cdot\|_2 over RM\RR^M. We can therefore use this choice of Ω\Omega to smooth out a function ff if dom⁡(f∗)⊆RM\dom(f^*) \subseteq \RR^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.

Figure 13.5: Tsallis entropies of the distribution π=(π,1−π)∈△2\piv = (\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 entropies

Given α≥1\alpha \ge 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}). Using this definition leads to the Tsallis entropy (Tsallis, 1988) H(Y)=E[I(Y)]=1α(α−1)∑y∈Yp(y)(1−pα−1(y)). H(Y) = \EE[I(Y)] = \frac{1}{\alpha(\alpha-1)} \sum_{y \in \cY} p(y) (1 - p^{\alpha-1}(y)). 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\piv \in \triangle^M Ω(π)=1α(α−1)⟨π,πα−1−1⁡⟩=1α(α−1)(∥π∥αα−1), \Omega(\piv) = \frac{1}{\alpha(\alpha-1)}\langle \piv, \piv^{\alpha-1} - \ones \rangle = \frac{1}{\alpha(\alpha-1)} (\|\piv\|^\alpha_\alpha - 1), where ∥v∥p\|\v\|_p is the pp-norm for (p≥1p \ge 1) ∥v∥p≔(∑i=1Mvip)1p, \|\v\|_p \coloneqq \left(\sum_{i=1}^M v_i^p\right)^{\frac{1}{p}}, so that ∥v∥pp=∑i=1Mvip. \|\v\|_p^p = \sum_{i=1}^M v_i^p. 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.

Figure 13.6: Contours of Tsallis entropies on the probability simplex.

Definition and properties of generalized entropies

So far, we saw how to define an entropy as the expected information content. However, generalized entropies (DeGroot, 1962; Grünwald and Dawid, 2004) do not necessarily need to take this form. We follow the definition of Blondel et al. (2020).

Definition 13.4 (Entropy function)

A function H ⁣:△M→R+H \colon \triangle^M \to \RR_+ is an entropy if

  1. H(π)=0H(\piv) = 0 if π∈{e1,…,eM}\piv \in \{\e_1,\dots,\e_M\},

  2. HH is strictly concave,

  3. H(Pπ)=H(π)H(P \piv) = H(\piv) for any permutation matrix PP.

This definition implies that HH is non-negative and is uniquely maximized by the uniform distribution (Blondel et al., 2020, Proposition 4). This is indeed what we expect from an entropy function. An example is the squared pp-norm entropy (Blondel et al., 2020) H(π)=12−12∥π∥p2. H(\piv) = \frac{1}{2} - \frac{1}{2} \|\piv\|_p^2. Since the squared pp-norm is strongly convex for p∈(1,2]p \in (1,2] (Ball et al., 2002), this entropy is strongly concave for p∈(1,2]p \in (1,2] and can therefore be used to smooth out functions.

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 Smoothed ReLU functions

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 &\mbox{ if } u \ge 0 \\ 0 &\mbox{ otherwise } \end{cases} = \max(u, 0). 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^{**}.

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) = \indic_{[0,1]}(\pi) = \begin{cases} 0 &\mbox{ if } \pi \in [0,1] \\ \infty &\mbox{ 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.(13.4) \mathrm{relu}(u) = \max_{\pi \in [0,1]} u \cdot \pi = \max_{\pi \in \{0,1\}} u \cdot \pi = \begin{cases} u &\mbox{ if } u \ge 0 \\ 0 &\mbox{ otherwise} \end{cases}. \tag{13.4} 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) and for some choice of Ω\Omega, we need to be able to compute reluΩ(u)=max⁡π∈Ru⋅π−(ι[0,1](π)+Ω(π))=max⁡π∈[0,1]u⋅π−Ω(π).\begin{align*} \mathrm{relu}_\Omega(u) &= \max_{\pi \in \RR} u \cdot \pi - (\iota_{[0,1]}(\pi) + \Omega(\pi)) \\ &= \max_{\pi \in [0,1]} u \cdot \pi - \Omega(\pi). \end{align*}

The softplus

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 \piv, \log \piv \rangle with π=(π,1−π)\piv = (\pi, 1 - \pi), we obtain reluΩ(u)=softplus(u)=log⁡(1+exp⁡(u)). \mathrm{relu}_\Omega(u) = \mathrm{softplus}(u) = \log(1 + \exp(u)). This result is a special case of Proposition 13.9.

The sparseplus

If we use the regularizer Ω(π)=π(π−1)\Omega(\piv) = \pi(\pi - 1), which comes from using Gini’s negentropy with 12⟨π,π−1⁡⟩\frac{1}{2} \langle \piv, \piv - \ones \rangle with π=(π,1−π)\piv = (\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}. See Fig. 13.8 (left figure) for a comparison of softplus and sparseplus.

13.5 Smoothed max operators

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

With a slight notation overloading, given a vector u=(u1,…,uM)∈RM\u = (u_1, \dots, u_M) \in \RR^M, we define its maximum as max(u)≔max⁡j∈[M]uj. \mathrm{max}(\u) \coloneqq \max_{j \in [M]} u_j. 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}^*(\piv) = \indic_{\triangle^M}(\piv). To notice why, we observe that the vertices of the probability simplex △M\triangle^M are the standard basis vectors e1,…,eM\e_1, \dots, \e_M. Since the objective is linear, we then have max⁡(u)=max⁡π∈△M⟨u,π⟩=max⁡π∈{e1,…,eM}⟨u,π⟩. \max(\u) = \max_{\piv \in \triangle^M} \langle \u, \piv \rangle = \max_{\piv \in \{\e_1, \dots, \e_M\}} \langle \u, \piv \rangle. 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}^* = \indic_{\triangle^M}. We can therefore write maxΩ∗(π)=max∗(π)+Ω(π)=Ω(π)+ι△M(π) \text{max}_\Omega^*(\piv) = \text{max}^*(\piv) + \Omega(\piv) = \Omega(\piv) + \iota_{\triangle^M}(\piv) and maxΩ(u)=(Ω+ι△M)∗(u)=max⁡π∈RM⟨u,π⟩−(Ω(π)+ι△M(π))=max⁡π∈△M⟨u,π⟩−Ω(π).\begin{align*} \mathrm{max}_\Omega(\u) &= (\Omega + \iota_{\triangle^M})^*(\u) \\ &= \max_{\piv \in \RR^M} \langle \u, \piv \rangle - (\Omega(\piv) + \iota_{\triangle^M}(\piv)) \\ &= \max_{\piv \in \triangle^M} \langle \u, \piv \rangle - \Omega(\piv). \end{align*} 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 (Mensch and Blondel, 2018, Lemma 1), as we recall here for convenience.

Proposition 13.7 (Properties of max⁡Ω\max_\Omega)

The following properties hold.

  1. Bounds: if LΩ≤Ω(π)≤UΩ\cL_\Omega \le \Omega(\piv) \le \cU_\Omega for all π∈△M\piv \in \triangle^M, then max⁡(u)−UΩ≤maxΩ(u)≤max⁡(u)−LΩ\max(\u) - \cU_\Omega \le \text{max}_\Omega(\u) \le \max(\u) - \cL_\Omega for all u∈RM\u \in \RR^M.

  2. Monotonicity: if u≤v\u \le \v (element-wise), then maxΩ(u)≤maxΩ(v)\text{max}_\Omega(\u) \le \text{max}_\Omega(\v).

  3. Commutativity: if Ω(Pπ)=Ω(π)\Omega(P \piv) = \Omega(\piv) for any permutation matrix PP and any π∈△M\piv \in \triangle^M, then maxΩ(Pu)=maxΩ(u)\text{max}_\Omega(P\u) = \text{max}_\Omega(\u) for any permutation matrix PP.

  4. Distributivity of ++: maxΩ(u+c1⁡)=maxΩ(u)+c\text{max}_\Omega(\u + c \ones) = \text{max}_\Omega(\u) + c for all u∈RM\u \in \RR^M and all c∈Rc \in \RR.

These properties are leveraged in (Mensch and Blondel, 2018) 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.

Smoothed min operators

The minimum operator can be expressed in terms of the maximum operator, since for all u∈RM\u \in \RR^M, min⁡(u)=−max⁡(−u). \min(\u) = -\max(-\u). Given a smoothed max operator maxΩ\mathrm{max}_\Omega, we can therefore easily define a smoothed min operator as minΩ(u)≔−maxΩ(−u).\begin{align*} \mathrm{min}_\Omega(\u) &\coloneqq -\mathrm{max}_\Omega(-\u). \end{align*}

13.5.2 Reduction to root finding

Computing max⁡Ω(u)\max_\Omega(\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(\u) \coloneqq (\Omega + \iota_{\RR_+^M})^*(\u) = \max_{\v \in \RR^M_+} \langle \u, \v \rangle - \Omega(\v). The following proposition shows that we can reduce computing max⁡Ω\max_\Omega to solving a root equation involving δΩ\delta_\Omega.

Proposition 13.8 (Computing max⁡Ω\max_\Omega as root finding)

Suppose Ω\Omega is strongly convex. For all u∈RM\u \in \RR^M, maxΩ(u)=min⁡τ∈Rτ+δΩ(u−τ1⁡)=τ⋆+δΩ(u−τ⋆1⁡)\begin{align*} \text{max}_\Omega(\u) &= \min_{\tau \in \RR} \tau + \delta_\Omega(\u - \tau \ones) \\ &= \tau^\star + \delta_\Omega(\u - \tau^\star \ones) \end{align*} and ∇maxΩ(u)=∇δΩ(u−τ⋆1⁡), \nabla \text{max}_\Omega(\u) = \nabla \delta_\Omega(\u - \tau^\star \ones), 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(\u - \tau^\star \ones), \ones \rangle = 1.

Proof

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)=max⁡v∈△M⟨u,v⟩−Ω(v)=max⁡v∈R+Mmin⁡τ∈R⟨u,v⟩−Ω(v)−τ(⟨v,1⁡⟩−1)=min⁡τ∈Rτ+max⁡v∈R+M⟨u−τ1⁡,v⟩−Ω(v)=min⁡τ∈Rτ+δΩ(u−τ1⁡),\begin{align*} \text{max}_\Omega(\u) &= \max_{\v \in \triangle^M} \langle \u, \v \rangle - \Omega(\v) \\ &= \max_{\v \in \RR_+^M} \min_{\tau \in \RR} \langle \u, \v \rangle - \Omega(\v) - \tau(\langle \v, \ones \rangle - 1) \\ &= \min_{\tau \in \RR} \tau + \max_{\v \in \RR_+^M} \langle \u - \tau \ones, \v \rangle - \Omega(\v) \\ &= \min_{\tau \in \RR} \tau + \delta_\Omega(\u - \tau \ones), \end{align*} where we used that we can swap the min⁡\min and the max⁡\max, since (u,v)↦⟨u,v⟩−Ω(v)(\u,\v) \mapsto \langle \u, \v \rangle - \Omega(\v) is convex-concave and v∈△M\v \in \triangle^M is an affine constraint. The gradient ∇δΩ(u)\nabla \delta_\Omega(\u) follows from Danskin’s theorem. The root equation follows from computing the derivative of τ↦τ+δΩ(u−τ1⁡)\tau \mapsto \tau + \delta_\Omega(\u - \tau \ones) and setting it to zero. ◻

13.5.3 The softmax

When Ω\Omega is Shannon’s negentropy, we obtain that max⁡Ω\max_\Omega is the softmax, already briefly discussed in Section 4.4.2.

Proposition 13.9 (Analytical expression of the softmax)

When Ω(π)=⟨π,log⁡π⟩\Omega(\piv) = \langle \piv, \log \piv \rangle, we get softmax(u)≔maxΩ(u)=max⁡π∈△M⟨u,π⟩−Ω(π)=logsumexp(u)=log⁡∑j=1Meuj.\begin{align*} \mathrm{softmax}(\u) &\coloneqq \mathrm{max}_\Omega(\u) \\ &= \max_{\piv \in \triangle^M} \langle \u, \piv \rangle - \Omega(\piv) \\ &= \mathrm{logsumexp}(\u) \\ &= \log \sum_{j=1}^M e^{u_j}. \end{align*}

Proof

Since dom⁡(Ω)=R+M\dom(\Omega) = \RR_+^M, we have δΩ=Ω∗\delta_\Omega = \Omega^* (i.e., the non-negativity constraint is redundant). From Example 13.2, we therefore have δΩ(u)=∑j=1Mexp⁡(uj−1)\delta_\Omega(\u) = \sum_{j=1}^M \exp(u_j - 1). From Proposition 13.8, max⁡Ω(u)=τ⋆+δΩ(u−τ⋆1⁡)\max_\Omega(\u) = \tau^\star + \delta_\Omega(\u - \tau^\star \ones) where τ⋆\tau^\star satisfies ⟨∇δΩ(u−τ⋆1⁡),1⁡⟩=1.\langle \nabla \delta_\Omega(\u - \tau^\star \ones), \ones \rangle = 1. Since ∇δΩ(u)=exp⁡(u−1⁡)\nabla \delta_\Omega(\u) = \exp(\u - \ones), 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 = \lse(\u) and therefore max⁡Ω(u)=logsumexp(u)−1+∑j=1Mexp⁡(uj−logsumexp(u))=logsumexp(u)\max_\Omega(\u) = \lse(\u) - 1 + \sum_{j=1}^M\exp(u_j - \lse(\u)) = \lse(\u). ◻

Since −log⁡M≤Ω(π)≤0-\log M \le \Omega(\piv) \le 0 for all π∈△M\piv \in \triangle^M, following Proposition 13.7, we get for all u∈RM\u \in \RR^M max⁡(u)≤softmax(u)≤max⁡(u)+log⁡M. \max(\u) \le \mathrm{softmax}(\u) \le \max(\u) + \log M. A unique property of the softmax, which is not the case of all max⁡Ω\max_\Omega operators, is that it supports associativity.

Proposition 13.10 (Associativity of the softmax)

For all a,b,c∈Ra, b, c \in \RR, 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 The sparsemax

Alternatively, choosing Ω\Omega to be Gini’s negentropy leads to the sparsemax (Martins and Astudillo, 2016; Mensch and Blondel, 2018).

Proposition 13.11 (Variational formulation of sparsemax)

When Ω(π)=12⟨π,π−1⁡⟩\Omega(\piv) = \frac{1}{2} \langle \piv, \piv - \ones \rangle, we have sparsemax(u)≔maxΩ(u)=max⁡π∈△M⟨u,π⟩−Ω(π)=⟨u,π⋆⟩−Ω(π⋆)\begin{align*} \mathrm{sparsemax}(\u) &\coloneqq \text{max}_\Omega(\u) \\ &= \max_{\piv \in \triangle^M} \langle \u, \piv \rangle - \Omega(\piv) \\ &= \langle \u, \piv^\star \rangle - \Omega(\piv^\star) \end{align*} where π⋆=sparseargmax(u)≔arg min⁡π∈△M∥u−π∥22. \piv^\star = \mathrm{sparseargmax}(\u) \coloneqq \argmin_{\piv \in \triangle^M} \|\u - \piv\|_2^2.

Proof

This follows from the fact that Ω(π)\Omega(\piv) is up to a constant equal to 12∥π∥22\frac{1}{2}\|\piv\|^2_2 and completing the square. ◻

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.8 gives an alternative formulation.

Proposition 13.12 (Sparsemax as root finding)

When Ω(π)=12⟨π,π−1⁡⟩\Omega(\piv) = \frac{1}{2} \langle \piv, \piv - \ones \rangle, we have sparsemax(u)=maxΩ(u)=min⁡τ∈Rτ+12∑i=1M[ui−τ]+2 \mathrm{sparsemax}(\u) = \text{max}_\Omega(\u) = \min_{\tau \in \RR} \tau + \frac{1}{2} \sum_{i=1}^M [u_i - \tau]_+^2 and τ⋆\tau^\star satisfies ∑i=1M[ui−τ]+=1. \sum_{i=1}^M [u_i - \tau]_+ = 1.

Proof

First, we compute the expression of δΩ(u)=max⁡v∈R+M⟨u,v⟩−Ω(v)\delta_\Omega(\u) = \max_{\v \in \RR_+^M} \langle \u, \v \rangle - \Omega(\v). Setting the gradient of v↦⟨u,v⟩−Ω(v)\v \mapsto \langle \u, \v \rangle - \Omega(\v) to zero and clipping, we obtain v⋆=[u]+\v^\star = [\u]_+. Plugging v⋆\v^\star back, we obtain δΩ(u)=12∑i=1M[ui]+2\delta_\Omega(\u) = \frac{1}{2} \sum_{i=1}^M [u_i]_+^2. Using Proposition 13.8 proves the proposition’s first part. Setting the derivative w.r.t. τ\tau to zero gives the second part. ◻

It can be shown (Condat, 2016; Duchi et al., 2008) that the exact solution τ⋆\tau^\star is obtained by τ⋆=1j⋆(∑i=1j⋆u[i]−1),(13.5) \tau^\star = \frac{1}{j^\star} \left(\sum_{i=1}^{j^\star} u_{[i]} - 1\right), \tag{13.5} 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, and where we used the notation u[1]≥u[2]≥⋯≥u[M]u_{[1]} \ge u_{[2]} \ge \dots \ge u_{[M]}. As an alternative, we can also compute τ⋆\tau^\star approximately using a bisection or by gradient descent w.r.t. τ\tau.

For π∈△M\piv \in \triangle^M, since 1M≤∥π∥22≤1\tfrac{1}{M} \leq \lVert \piv \rVert_2^2 \leq 1, we have −M−12M≤Ω(π)≤0.-\tfrac{M-1}{2M} \leq \Omega(\piv) \leq 0. Following Proposition 13.7, we therefore get for all u∈RM\u \in \RR^M max⁡(u)≤sparsemax(u)≤max⁡(u)+M−12M. \max(\u) \le \mathrm{sparsemax}(\u) \le \max(\u) + \frac{M-1}{2M}.

Figure 13.7: Max, softmax and sparsemax functions. The max function has non-smooth contour lines (set of points {u∈R3:f(u)=c}\{\u \in \RR^3: f(\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}\{\u \in \RR^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 Recovering smoothed ReLU functions

Using the vector u=(u,0)∈R2\u = (u, 0) \in \RR^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), 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 Relaxed step functions (sigmoids)

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 &\mbox{ if } u \ge 0 \\ 0 &\mbox{ otherwise} \end{cases}. 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). Notice that, unlike the case of the smoothed ReLU, it is a regularized argmax, not a regularized max. Following Remark 13.1, 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).

The logistic function

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.

The sparse sigmoid

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 \le -1\\ \frac{1}{2}(u+1), & -1 < u < 1 \\ 1, & u \ge 1 \end{cases}. 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.

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)=relu′(u)logistic(u)=softplus′(u)sparsesigmoid(u)=sparseplus′(u)\begin{align*} \mathrm{step}(u) &= \mathrm{relu}'(u) \\ \mathrm{logistic}(u) &= \mathrm{softplus}'(u) \\ \mathrm{sparsesigmoid}(u) &= \mathrm{sparseplus}'(u) \end{align*} and more generally reluΩ′(u)=stepΩ(u). \mathrm{relu}_\Omega'(u) = \mathrm{step}_\Omega(u). This is a consequence of Danskin’s theorem; see Example 11.2. We illustrate the smoothed ReLU functions and relaxed step functions (sigmoids) in Fig. 13.8.

Figure 13.8: Smoothed ReLU functions and relaxed step functions (sigmoids). Differentiating the left functions gives the right functions.

13.7 Relaxed argmax operators

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}(\u) \coloneqq \phi(\argmax_{j \in [M]} u_j), where ϕ(j)=onehot(j)=ej\phi(j) = \mathrm{onehot}(j) = \e_j is used to embed any integer j∈[M]j \in [M] into RM\RR^M. Following the previous discussion, we have the variational form argmax(u)=arg max⁡π∈△M⟨u,π⟩=arg max⁡π∈{e1,…,eM}⟨u,π⟩, \mathrm{argmax}(\u) = \argmax_{\piv \in \triangle^M} \langle \u, \piv \rangle = \argmax_{\piv \in \{\e_1, \dots, \e_M\}} \langle \u, \piv \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(\u) \coloneqq \argmax_{\piv \in \triangle^M} \langle \u, \piv \rangle - \Omega(\piv). Again, following Remark 13.1, argmaxΩ(u)\mathrm{argmax}_\Omega(\u) is guaranteed to be, at least, a differentiable almost everywhere function of u\u if Ω\Omega is strongly convex.

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(\u) = \nabla \mathrm{max}_\Omega(\u). This is again a consequence of Danskin’s theorem.

The softargmax

When using Shannon’s negative entropy Ω(π)=⟨π,log⁡π⟩\Omega(\piv) = \langle \piv, \log \piv \rangle, we obtain argmaxΩ(u)=softargmax(u)=exp⁡(u)∑j=1Mexp⁡(uj), \mathrm{argmax}_\Omega(\u) = \mathrm{softargmax}(\u) = \frac{\exp(\u)}{\sum_{j=1}^M \exp(u_j)}, which is differentiable everywhere.

Proof

We know that max⁡Ω(u)=logsumexp(u)\max_\Omega(\u) = \lse(\u) and that ∇max⁡Ω(u)=argmaxΩ(u)\nabla \max_\Omega(\u) = \mathrm{argmax}_\Omega(\u). Differentiating logsumexp(u)\lse(\u) gives softargmax(u)\mathrm{softargmax}(\u). ◻

The sparseargmax

When using Gini’s entropy Ω(π)=12⟨π,π−1⁡⟩\Omega(\piv) = \frac{1}{2} \langle \piv, \piv - \ones \rangle, which is up to a constant equal to 12∥π∥22\frac{1}{2} \|\piv\|^2_2, we obtain the sparseargmax (Martins and Astudillo, 2016) argmaxΩ(u)=sparseargmax(u)≔arg max⁡π∈△M⟨u,π⟩−12⟨π,π−1⁡⟩=arg max⁡π∈△M⟨u,π⟩−12∥π∥22=arg min⁡π∈△M∥u−π∥22,\begin{align*} \mathrm{argmax}_\Omega(\u) &= \mathrm{sparseargmax}(\u) \\ &\coloneqq \argmax_{\piv \in \triangle^M} \langle \u, \piv \rangle - \frac{1}{2} \langle \piv, \piv - \ones \rangle \\ &= \argmax_{\piv \in \triangle^M} \langle \u, \piv \rangle - \frac{1}{2} \|\piv\|_2^2 \\ &=\argmin_{\piv \in \triangle^M} \|\u - \piv\|^2_2, \end{align*} 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 (Brucker, 1984; Condat, 2016; Duchi et al., 2008; Michelot, 1986). 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}(\u) = [\u - \tau^\star]_+, 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 (Martins and Astudillo, 2016), 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.

Figure 13.9: Values of argmax(u)\mathrm{argmax}(\u), softargmax(u)\mathrm{softargmax}(\u), and sparseargmax(u)\mathrm{sparseargmax}(\u) for u=(u1,u2,0)\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.

Figure 13.10: Same as Fig. 13.9 but using a 3D plot.

Relaxed argmin operators

The argmin operator can be expressed in terms of the argmax operator, arg min⁡(u)=arg max⁡(−u). \argmin(\u) = \argmax(-\u). Given a relaxed argmax operator argmaxΩ\mathrm{argmax}_\Omega, we can therefore define a relaxed argmin by argminΩ(u)≔argmaxΩ(−u). \mathrm{argmin}_\Omega(\u) \coloneqq \mathrm{argmax}_\Omega(-\u). We then have for all u∈RM\u \in \RR^M argminΩ(u)=∇minΩ(u). \mathrm{argmin}_\Omega(\u) = \nabla \text{min}_\Omega(\u).

13.8 Summary