s2fieldsofstudy:
Computer Science
Mathematics

text:
Introducing the DOME Activation Functions

In this paper, we introduce a novel non-linear activation function that spontaneously induces class-compactness and regularization in the embedding space of neural networks. The function is dubbed DOME for Difference Of Mirrored Exponential terms. The basic form of the function can replace the sigmoid or the hyperbolic tangent functions as an output activation function for binary classification problems. The function can also be extended to the case of multi-class classification, and used as an alternative to the standard softmax function. It can also be further generalized to take more flexible shapes suitable for intermediate layers of a network. We empirically demonstrate the properties of the function. We also show that models using the function exhibit extra robustness against adversarial attacks.

In this paper, we introduce a novel non-linear activation function dubbed DOM E, for Difference Of Mirrored Exponential terms. DOM E is very distinctive in its shape and effect from any other activation function in the literature. DOM E is a continuously differentiable, aperiodic, and non-monotonic activation function. In its simplest form, DOM E is similar to the sigmoid or hyperbolic tangent functions, which are common choices for output activation functions in binary classification problems. However, different from both of these functions, DOM E naturally induces compactness of each class and separation between different classes in the embedding space. DOM E can be parameterized to provide a more general form that can be used in any layer throughout a neural network. It can also be generalized to substitute the softmax function as an output activation for multi-class classification problems. However, unlike softmax, DOM E naturally induces intra-class compactness and inter-class separation in the embedding space without the addition of special losses. DOM E also enjoys a self-regularization property.
We empirically demonstrate the effectiveness of the DOM E function in different classification tasks. DOM E's advantage is most evident in the extra robustness it adds against adversarial examples.
In the rest of this paper, we first give an overview of relevant literature (Section 2). Next, we lay the backdrop with the simple case of binary classification (Section 3). Afterwards, we introduce the DOM E function (Section 4), its generalized version (Section 5), and its multi-class extension (Section 6). Finally, we present our empirical evaluation and analysis (Section 7) before concluding the paper (Section 8).

Related work
In this section, we discuss the most relevant prior research to ours.

Non-linear activation functions
Saturating activation functions, e.g., the logistic sigmoid and the hyperbolic tangent, used to be the dominant non-linearities applied in neural networks. This has changed since the rectified linear units (ReLUs) was found to be more effective in training deep neural networks [34]. Since then, many more non-linear activation functions have been introduced in the literature. The effectiveness of ReLUs was partly believed to be due to the sparseness it induces on network activations. However, this belief was later contradicted by the success of non-sparsity-inducing activation functions. For example, the leaky ReLU function was introduced to facilitate the gradient propagation with ReLUs by introducing a non-zero slope in the negative part of the function's domain [31], which essentially deprived ReLU from it sparseness effect. Leaky ReLUs were further generalized to parametric ReLUs [16], in which the slope of the negative side was turned into a learnable parameter, and randomized ReLUs [59], in which that slope was made randomized. All of these ReLU variants overcame the lack of gradient in the negative part of the domain, which hampered the speed of convergence in the original ReLU.
The exponential linear units (ELUs) [8] was then introduced to maintain the non-zero gradient in the negative part of the domain while making the function saturate in that part. Different from all the preceding functions, the continuously differentiable exponential linear units (CELUs) [3], as its name indicates, is continuously differentiable while still maintaining all the desired properties of ReLUs and ELUs. The Gaussian error linear units (GELUs) [18] and the Swish function [41] were then introduced to add the extra generality of not being monotonic in the negative part of their domains. Another interesting tweak of ELUs was the scaled ELUs (SELUs) [24], which was shown to introduced a self-normalization feature that could eliminate the need to use batch normalization layers [21]. The sinosoid activation function was also shown to be amenable to train deep networks despite the multiple local modes [39]. Our proposed activation function is most similar to the sinosoid, without being periodic. DOM E is also non-monotonic and continuously differentiable.
The aformentioned activation functions are designed with at least one of these goals in mind: breaking the linearity of the model, inducing sparsity, facilitating gradient computation and propagation, being biologically inspired, or inducing compactness. It is worth noting that there is another class of activation functions designed with the goal of flexibility to represent a very broad class of functions, such as the cubic spline activation [46] and the Maxout function [14].

Priors on embedding spaces
The arrangement of points in the embedding space of a neural network has a significant effect on its performance on different tasks. There is a sizeable body of research that enforces different priors on that space to encourage a certain behavior.
[28] applied hyperspherical energy regularization to minimize redundancy between features of the same layer. In the output layer, this approach resulted in encouraging class centers to be as spread as possible. [44] applied a similarly formulated regularization that was inspired by maximizing the differential entropy. The notion of enforcing class-compactness in the embedding space has attracted much attention in the face recognition community. Typically, such proposed methods were posed either as an added loss function, such as the center loss [54,55]; as an added constraint, such as the ring loss [63] and crystal loss [42,43]; or a reformulation of the cross entropy loss, such as in Gaussian-mixture loss [51], angular softmax [29], NormFace [52], CosFace [53], ArcFace [10]. It is worth noting that the aforementioned reformulations of the cross entropy loss, despite being posed as such, can be seen as reformulations of the penultimate layer's function without introducing changes to the softmax function or the cross entropy loss.

Defenses against adversarial attacks
Since the discovery of adversarial attacks against machine learning models, many attempts have been introduced to defend against them. The most successful defense so far is adversarial training and its variants [32,61]. Similar to the DOM E function as a defense, there were other attempts to induce compactness in the embedding space as a defense mechanism [36,37]. However, as many other defenses that did not involve adversarial training [2,38,57], such approaches were soon defeated via adaptive attacks [48] or automatically adjustable attack recipes [9]. We are not proposing the DOM E function as a standalone defense. The DOM E function constitutes a defense when combined with adversarial training. Figure 1a shows the structure of a generic neural network model. The network consists of two main parts, the encoder and the classifier. The last layer of the encoder is the penultimate layer, whose output constitutes the input's embedding. The classifier relies on the embedding to produce the classification outputs. The classification stage can be split into two sub-stages, one that produces real valued logits, and the other maps the logits into a probability distribution over the possible output classes through a non-linear activation function.

Binary classification output activation
Let's first have a look at the effect of output activation functions on the embedding space in the simple case of binary classification. Binary classification neural network models use one or two output units with a non-linear activation function. Figures 1b, 2a and 2b display three classic activation functions commonly used in this case. If the model has a single output unit, the activation function is typically either the tanh function ( Fig. 1b) or the sigmoid function (Fig. 2a), whose values are always in the intervals (−1, 1) or (0, 1), respectively, for any finite input. If the model has two output units, the softmax function is the natural choice. The softmax function, in this case, has two outputs, each of which is in (0, 1) and their sum is 1. Figure 2b shows one of the two outputs in the special case of having the two inputs equal in value and opposite in sign. This special case of softmax is used here for illustration only. However, the phenomenon we are about to discuss applies to the general case as well. Note that if one of the inputs to the softmax function is zero, the function reduces to a sigmoid function of the other input.    The common characteristic among the three activation functions is that their outputs are almost saturated, at either side of their limits, for infinitely wide ranges of their domains. For example, the tanh function is almost saturated at its maximum value of 1 in the interval (3, ∞). Since the objective of a binary classification model's training is to make the model's output reach one extreme value for one class and the other extreme value  for the other class, optimizing a model for this objective does not impede the logits from growing indefinitely. Consequently, the indefinite growth of the logits has the effect of indefinitely expanding the embedding space.
To examine the expansion of the embedding space, suppose that the logits are the outputs of a linear layer, and, for simplicity, suppose that the linear layer has no bias. In mathematical notation, the i th logit z i (in binary classification, i ∈ {0, 1}) can be expressed as where x is the transpose of the vector from the origin to the input embeddingx, w i is a vector representing the i th column of the linear layer's weight matrix, and θ is the angle between the two vectors x and w i . In this case, which is illustrated with a simple 2D embedding space in Fig. 1c, the logit value represents the scaled distance betweenx and a hyperplane (φ in Fig. 1c) represented by its normal vector w i . The scaling factor of such a distance is w i . Therefore, the logits can grow in absolute values in one of three ways: (1) increasing x , which is equivalent to increasing the distance betweenx and the hyperplane (d in Fig. 1c), (2) increasing w i , which is equivalent to increasing the scaling factor of the distance, or (3) increasing cos θ, which is equivalent to making x and w i more parallel or anti-parallel. At a fixed value for the weight vector w i , there are only two degrees of freedom to increase |z i |. If the output activation function is any of the ones shown in Figs. 1b and 2a, once the |z i | grows beyond a certain value, there will be no noticeable change in the value of the output activation function, and hence there will be no noticeable change in the value of the loss function. In other words, there are hugely different combinations of the values of x and θ that result in a negligible change in the loss value. As a result, unless proper regularization is deployed, it is typical to have the cloud of points of each class in the embedding space span a large portion of the space. This effect is illustrated in Figs. 3a and 3b for the sigmoid and softmax activation functions for the binary classification problem of classifying even versus odd digits in the MNIST dataset. In addition to the unneeded expansion of the embedding space, we can also observe that the inter-class distances can be smaller than the intra-class distances. This phenomenon is depicted in the overlap between the inter-class and intra-class distance distributions in Figs. 4a and 4b. We postulate that such lack of compactness in the embedding space makes it easier for an attacker to fabricate an adversarial example due to the small margin separating the two classes.

Difference of mirrored exponential terms
To alleviate the problems of output activation functions as outlined in Section 3, we propose a novel activation function. One objective of our activation function is to have saturated output values only in narrow and finitely bounded ranges of its domain. In this way, the logit values of each class, and hence the corresponding points in the embedding space, will be compactly clustered, and hence the embedding space does not expand indefinitely. We achieve this objective with the activation function in Eq. (2). We name our function DOM E for Difference Of Mirrored Exponential terms because the shape of the function originates from the subtraction of the two exponential terms, which are identical except for the sign in the exponent, i.e. each of them is a vertical mirroring of the other. Figure 2c shows the shape of DOM E when µ = σ = 1. Figure 3c illustrates the embedding space induced by the function for the same binary classification task used to generate the plots in Fig. 3 for the sigmoid and softmax functions. From the figure, it is clear that the embedding space induced by DOM E is much more bounded, class-compact, and the intra-class distances are much smaller than the inter-class distances, which is depicted clearly in the inter-class vs intra-class distributions in Fig. 4c. Indeed, DOM E achieves the desired properties it is designed for.
Let's now have a closer look at the behavior of the function. First, because the two exponential terms are bounded within the interval (0, 1], the difference between them is bounded by the interval (−1, 1). After shifting the difference between the two exponential terms by 1 and scaling by 0.5, the function becomes bounded within (0, 1). Note that the function's output cannot reach its limits due to the subtraction between the two exponential terms. The relationship between the two parameters µ and σ controls how close or faraway the function's output from its limits. The µ parameter represents the location of the modes of the two mirrored exponential terms. The σ parameter represents the breadth of each of these terms. Figure 5 illustrates how the shape of the DOM E function changes as the relationship between its two parameters, µ and σ, changes. The smaller the σ value with respect to µ, the relatively narrower the saturation range of the function and the closer the extreme values of its output to the saturation limits. The opposite happens the larger σ is with respect to µ. Therefore, if we choose to optimize the two parameters of the function along with other model parameters using binary loss function, such as the binary cross entropy loss, we can expect σ to be as small as possible with respect to µ.

Penalized DOM E
The DOM E activation function can be a proper replacement for sigmoid as an output activation function for binary classification problems. However, the lack of negative output makes it unsuitable for intermediate layers' activation functions where the mix between positive and negative output values is important. Also, it is typical for the intermediate layer activation functions that there is an imbalance between the positive and negative sides. Therefore, we introduce a generalization of DOM E, that we call Penalized DOM E (P DOM E), which offers both properties of having positive and negative outputs, and also having a learnable imbalance between the negative and positive sides. Equation (13) shows the form of the P DOM E function, in which π is learnable penalty multiplier for the negative side of the function. This makes P DOM E(x) ∈ (−pi, 1)∀x ∈ R. When π = 1, P DOM E becomes bounded within (−1, 1), in which case it becomes similar to the hyperbolic tangent activation function. Figure 6 shows how the shapes of P DOM E changes with changing µ and π when σ = 1.
We hypothesize that the narrow range of saturated activation values in P DOM E results in regularizing the weights of the network without adding explicit regularization or normalization layers, e.g. batch normalization. Figure 7 illustrates the embedding space, the shape of the learned P DOM E function, and the distance distributions when the experiment in Figs the final layer (Fig. 7b), which is the logits layer. It is also apparent that the points corresponding to each class are closer to one another compared to points belonging to different classes (Fig. 7c).

Multi-class generalization of DOM E
We showed in Section 4 how the DOM E function achieves our objectives of class-compactness and regularization to the embedding space in the case of binary classification. We now turn to generalizing DOM E's formulation to the multi-class case. First, let's consider a slight variation to the DOM E function for the binary classification case, in which instead of producing one output, the function produces two outputs, one for each class, as shown in Eq. (4) and Eq. (5), where e 1 = 1, e 2 = −1, and is illustrated in Fig. 8. This formulation can be interpreted as that each of the two classes has a point of reference µe i for i ∈ 1, 2. The two points of reference are at the same distance µ from the origin. The activation value represents the closeness of the input logit x to the reference point of one class compared to the other. Note that the following properties hold DOM E 1 (x) ∈ (0, 1), DOM E 2 (x) ∈ (0, 1), and To extend the DOM E's formulation to the multi-class case, we need to draw parallels to the concepts high-lighted above. First, we need to have a reference point for each class. Second, we need each reference point to be at the same distance from all others. This last requirement is not applicable in the binary classification case because we only have two reference points. However, one important feature of DOM E is that the distance between the two centers is controlled by one parameter, which is µ, such that increasing µ, when the other parameter σ is fixed, pushes the reference points away and allows the function's extreme values to become closer to their limits. Another advantage of this requirement is that it makes the formulation of the function symmetric, and hence facilitates its analysis. When we have more than two reference points, we want the same property to hold for all of them at the same time. To achieve this, we need the reference points to occupy the vertices of a regular n-simplex for an n-class problem. However, an n-simplex can only exist in at least an n − 1 dimensional space. That means, the reference points have to be in an n − 1 dimensional space or higher. Not only the reference points have to be multi-dimensional, the input to the function has to be mapped to the same multi-dimensional space for the computations to be valid. We assume here that the input to the function has the same multi-dimensional space as the reference points. If this is not the case, the model can be augmented with a projection function, such as a fully connected layer, to perform the mapping from the embedding space to the space of the reference points. All of the above is put together in Eq. (8) and Eq. (9). We refer to this version of DOM E as M DOM E, for multi-class DOM E.
It is easy to see that the 2-class case shown in Eq. (4) and Eq. (5) is a special case of the n-class case in Eq. (8) and Eq. (9) when n = 2. Given the symmetry of the function, it is also straight forward to prove the following properties of the n-class M DOM E, which are generalizations of the properties of the 2-class case in Eq. (6) and Eq. (7).

i∈[n]
DOM E n i (x) = 1 (11) In contrast to the binary case, the lower bound of the M DOM E function can be negative. The lower bound in Eq. (10) approach −1 as n approaches infinity. However, this lower bound is loose and in practice the function never approaches it. In practice, we normalize the function's values to be all non-negative as shown in Eq. (12) and Eq. (13).D

OM E
We repeated the same experiments used in Figs. 3, 4 and 7 on the MNIST data using the LeNet architecture [27] with a 2D embedding space, but with 3 classes instead of 2, where the class is the digit mod 3. The resulting embedding spaces and inter-class/intra-class distance distributions for the softmax and M DOM E activation functions are shown in Fig. 9. The plots underscores the significant difference between the M DOM E and softmax in terms of class compactness and regularization of the embedding space.

Experimental evaluation
We evaluate the P DOM E and M DOM E functions on three datasets, which are MNIST [27], Fashion-MNIST [58], and CIFAR-10 [25]. For each dataset, we trained a ResNet-18 network using the fast adversarial training (FAT) framework [56]. We used the default optimizer (SGD) with momentum of 0.9 and learning rate scheduler (linear cyclic learning rate scheduler), and default parameters = 8 255 and α = 10 255 . We set the number of epochs to 30. We used grid search to tune the learning rate, weight decay, and whether Nesterov momentum is used or not, for each model and dataset. We empirically found that the mean-square-error loss works best with M DOM E. Therefore, it is used in all our M DOM E experiments. The initial µ for the DOM E functions was always set to 1. For P DOM E, the initial σ and π were set to 1 and 0.1, respectively. For M DOM E, the initial σ was set to 5. Table 1 shows the final hyper parameters used to produce the results in this paper.   Table 2 shows the benign and adversarial accuracy values for the three datasets comparing the baseline model, which uses ReLU as the layer-wise non-linear activation function and softmax as the output activation function, and two other models, one replaces the ReLU in the baseline with P DOM E, and the other replaces the softmax with M DOM E. The adversarial accuracy is based on two white-box attacks. The first is the PGD attack [32] with 50 iterations and 10 random restarts. The other is the Auto-Attack [9]. For the latter, we use the implementation in the adversarial-robustness-toolbox (ART) [35], which applies a bundle of four attacks: two variants of PGD, DeepFool [33] and SquareAttack [1]. We used the default setting of ART except for setting the random restart for SquareAttack to 1 instead of 5 to keep the running time in a reasonable range. The epsilon and epsilon step, for all attacks, were set to 8 255 and 2 255 , respectively. Experimenting with PGD alone might seem redundant since it is already included in the Auto-Attack's bundle. However, the standalone PGD in our experiments is different because it uses the loss function used to train the model, which is the MSE loss in the case of M DOM E. However, the PGD in Auto-Attack's bundle uses other two custom loss functions. These loss functions expect the logits to be the output of the model. Since M DOM E outputs probabilities, we experimented with three different variants of M DOM E and reported the results based on the union of the found adversarial examples with the three variants. The first variant uses M DOM E's probabilities as logits. The second two variants use the two functions in Eqs. (14) and (15). Therefore, Auto-Attack in our case is considered an adaptive attack [48], which is designed based on the knowledge about the defense.
where · is the dot product operator.
The results show the consistent advantage of the M DOM E compared to the baseline in terms of adversarial accuracy for the three datasets and the two attacks. In all the cases, M DOM E supersedes the baseline except for one case in which it comes as a close second. For the Fashion-MNIST dataset, the P DOM E emerges as the most robust under the two attacks with M DOM E as a close second. The extra robustness comes at the expense of degraded benign accuracy, which is mostly minor except for the case of the CIFAR-10 dataset.

Conclusion
We introduced a novel activation function dubbed DOM E, for Difference of Mirrored Exponential terms. DOM E has a couple of interesting properties. First, it naturally induces intra-class compactness and inter-class divergence to the embedding space without using any special loss. Second, it has a self-regularization property, which means that, training a network with DOM E without any other regularization mechanism, the embedding space does not excessively grow, which is typically the case with traditional output activation functions. DOM E can be extended to the multi-class case, which we call M DOM E. It can also be generalized to take more arbitrary shapes amenable to non-linear activation for internal layers, which we call P DOM E, for Penalized DOM E. Our experiments show that the DOM E variant enhances the robustness against white-box evasion attacks.    e (x 1) 2 e (x + 1) 2 DOME 1 (x) DOME 2 (x)   : Embedding spaces and inter-class vs intra-class distance distributions over the testing data for an experiment similar to the one in Fig. 3, but with three classes, with different output activation functions.