Frequency Principle: Fourier Analysis Sheds Light on Deep Neural Networks
Zhi-Qin John Xu, Yaoyu Zhang, Tao Luo, Yanyang Xiao, Zheng Ma
Introduction
Understanding the training process of Deep Neural Networks (DNNs) is a fundamental problem in the area of deep learning. We find a common implicit bias in the gradient-based training process of DNNs, that is, a Frequency Principle (F-Principle):
DNNs often fit target functions from low to high frequencies during the training process.
In another word, at the early stage of training, the low-frequencies are fitted and as iteration steps of training increase, the high-frequencies are fitted. For example, when a DNN is trained to fit , its output would be close to at early stage and as training goes on, its output would be close to . F-Principle was observed empirically in synthetic low-dimensional data with MSE loss during DNN training (Xu et al., 2018; Rahaman et al., 2018). However, in deep learning, empirical phenomena vary from one network structure to another, from one dataset to another and often show significant difference between synthetic data and high-dimensional real data. It is still of great challenges to quantitatively study the universality of empirical observed phenomena, e.g., F-Principle, in high-dimensional real problems due to large computational cost, for instance, the high-dimensional Fourier transform is prohibitive in practice. In addition, it is also unclear whether the F-Principle can guide the usage and provide insight of DNNs in real problems.
In this work, we first design two methods to show that the F-Principle exists in the training process of DNNs for different benchmark setups, e.g., MNIST (LeCun, 1998), CIFAR10 (Krizhevsky et al., 2010), and deep networks, such as VGG16 (Simonyan & Zisserman, 2014). The settings we have considered are i) different DNN architectures, e.g., fully-connected network and convolutional neural network (CNN); ii) different activation functions, e.g., tanh and rectified linear unit (ReLU); iii) different loss functions, e.g., cross entropy, mean squared error (MSE), and loss energy functional in variation problems. These results demonstrate the universality of the F-Principle.
To facilitate the designs and applications of DNN-based schemes, we characterize a stark difference between DNNs and conventional numerical schemes on various scientific computing problems, where most of the conventional methods (e.g., Jacobi method) exhibit the opposite convergence behavior — faster convergence for higher frequencies. This difference implicates that DNN can be adopted to accelerate the convergence of low frequencies for computational problems.
We also show how the power decaying spectrum of commonly used activation functions contributes to the F-Principle with a theory under an idealized setting. Note that this mechanism is rigorously demonstrated for DNNs of general settings in a subsequent work (Luo et al., 2019). Finally, we discuss that the F-Principle provides an understanding of good generalization of DNNs in many real datasets (Zhang et al., 2016) and poor generalization in learning the parity function (Shalev-Shwartz et al., 2017; Nye & Saxe, 2018), that is, the F-Principle which implies that DNNs prefer low frequencies, is consistent with the property of low frequencies dominance in many real datasets, e.g., MNIST/CIFAR10, but is different from the parity function whose spectrum concentrates on high frequencies. Compared with previous studies, which only study synthetic data with MSE loss, our main contributions are as follows:
1. By designing both the projection and filtering method, we consistently demonstrate the F-Principle for high-dimensional real datasets of MNIST/CIFAR10 over various architectures such as VGG16.
2. For the application of solving differential equations, we show (i) conventional numerical schemes learn higher frequencies faster whereas DNNs learn lower frequencies faster by the F-Principle, (ii) convergence of low frequencies can be greatly accelerated with DNN-based schemes.
3. We show a simple theory under an idealized setting for an easy understanding of the F-Principle.
4. We discuss in detail the impact of the F-Principle to the generalization of DNNs that DNNs are implicitly biased towards a low frequency function leading to good and poor generalization for low and high frequency dominant target functions respectively.
Frequency Principle
The concept of “frequency” is central to the understanding of F-Principle. In this paper, the “frequency” means response frequency NOT image (or input) frequency as explained in the following.
Frequency Principle: DNNs often fit target functions from low to high (response) frequencies during the training process. In the following, by using high-dimensional real datasets, we experimentally demonstrate F-Principle at the levels of both individual frequencies (projection method) and coarse-grained frequencies (filtering method).
F-Principle in MNIST/CIFAR10 through projection method
Real datasets are very different from synthetic data used in previous studies. In order to utilize the F-Principle to understand and better use DNNs in real datasets, it is important to verify whether the F-Principle also holds in high-dimensional real datasets.
2 MNIST/CIFAR10
In the following, we show empirically that the F-Principle is exhibited in the selected direction during the training process of DNNs when applied to MNIST/CIFAR10 with cross-entropy loss. The network for MNIST is a fully-connected tanh DNN (---) and for CIFAR10 is two ReLU convolutional layers followed by a fully-connected DNN (----). All experimental details of this paper can be found in Appendix B. We consider one of the 10-d outputs in each case using non-uniform Fourier transform, as shown in Fig. 1(a) and 1(c), low frequencies dominate in both real datasets. During the training, the evolution of relative errors of certain selected frequencies (marked by black squares in Fig. 1(a) and 1(c)) is shown in Fig. 1(b) and 1(d). One can easily observe that DNNs capture low frequencies first and gradually capture higher frequencies. Clearly, this behavior is consistent with the F-Principle. For other components of the output vector and other directions of , similar phenomena are also observed.
F-Principle in MNIST/CIFAR10 through filtering method
The projection method in previous section enables us to visualize the F-Principle in one direction for each examination at the level of individual frequency components. However, this demonstration of the F-Principle is insufficient since it is impossible to verify F-Principle at all potentially informative directions for high-dimensional data. To compensate the projection method, in this section, we consider a coarse-grained filtering method which is able to unravel whether, in the radially averaged sense, low frequencies converge faster than high frequencies.
We split the frequency domain into two parts, i.e., a low-frequency part with and a high-frequency part with , where is the length of a vector. The DNN is trained as usual by the original dataset , such as MNIST or CIFAR10. The DNN output is denoted as . During the training, we can examine the convergence of relative errors of low- and high- frequency part, using the two measures below
where indicates convolution operator, and the high frequency part can be derived by
Step One: Training. Train the DNN by the original dataset , such as MNIST or CIFAR10. is an image vector, is a one-hot vector.
Step Two: Filtering. The low frequency part can be derived by
where is a normalization factor and
2 DNNs with various settings
It is important to verify the F-Principle in commonly used large networks. With the filtering method, we show the F-Principle in the DNN training process of real datasets. For MNIST, we use a fully-connected tanh-DNN (no softmax) with MSE loss; for CIFAR10, we use cross-entropy loss and two structures, one is small ReLU-CNN network, i.e., two convolutional layers, followed by a fully-connected multi-layer neural network with a softmax; the other is VGG16 (Simonyan & Zisserman, 2014) equipped with a 1024 fully-connected layer. These three structures are denoted as “DNN”, “CNN” and “VGG” in Fig. 2, respectively. All are trained by SGD from scratch. More details are in Appendix B
F-Principle in solving differential equation
Recently, DNN-based approaches have been actively explored for a variety of scientific computing problems, e.g., solving high-dimensional partial differential equations (E et al., 2017; Khoo et al., 2017; He et al., 2018; Fan et al., 2018) and molecular dynamics (MD) simulations (Han et al., 2017). However, the behaviors of DNNs applied to these problems are not well-understood. To facilitate the designs and applications of DNN-based schemes, it is important to characterize the difference between DNNs and conventional numerical schemes on various scientific computing problems. In this section, focusing on solving Poisson’s equation, which has broad applications in mechanical engineering and theoretical physics (Evans, 2010), we highlight a stark difference of a DNN-based solver and the Jacobi method during the training/iteration, which can be explained by the F-Principle.
This example illustrates a cautionary tale that, although DNNs has clear advantage, using DNNs alone may not be the best option because of its limitation of slow convergence at high frequencies. Taking advantage of both DNNs and conventional methods to design faster schemes could be a promising direction in scientific computing problems.
A preliminary theoretical understanding
A subsequent theoretical work (Luo et al., 2019) provides a rigorous mathematical study of the F-Principle at different frequencies for general DNNs (e.g., multiple hidden layers, different activation functions, high-dimensional inputs). The key insight is that the regularity of DNN converts into the decay rate of a loss function in the frequency domain. For an intuitive understanding of this key insight, we present a simplified theory, which connects the smoothness of the activation function with different gradient priorities in frequency domain. Although this naive theory is in an ideal setting, it is much easier for understanding.
Considering a DNN of one hidden layer with activation function , for any frequencies and such that , , and , there exist positive constants and such that for sufficiently small , we have
Theorem 1 indicates that for any two non-converged frequencies, with small weights, the lower-frequency gradient exponentially dominates over the higher-frequency ones. Due to the Parseval’s theorem, the MSE loss in the spatial domain is equivalent to the L2 loss in the Fourier domain. To intuitively understand the higher decay rate of a lower-frequency loss function, we consider the training in the Fourier domain with loss function of only two non-zero frequencies.
Considering a DNN of one hidden layer with activation function . Suppose the target function has only two non-zero frequencies and , that is, , , , and for . Consider the loss function of with gradient descent training. Denote
that is, decreases faster than . There exist positive constants and such that for sufficiently small , we have
Discussions
Next, we discuss DNN’s generalization ability from the view point of Fourier analysis.
DNNs often generalize well in real problems (Zhang et al., 2016) but badly in fitting the parity function (Shalev-Shwartz et al., 2017; Nye & Saxe, 2018). Understanding the differences between above two types of problems, i.e., good and bad generalization performance of DNN, is critical. Next, we show a qualitative difference between these two types of problems through Fourier analysis and use the F-Principle to provide insight into how different characteristics in Fourier domain result in different generalization performances of DNNs.
The F-Principle implicates that among all the functions that can fit the training data, a DNN is implicitly biased during the training towards a function with more power at low frequencies. If the target function has significant high-frequency components, insufficient training samples will lead to artificial low frequencies in training dataset, such as the parity function as shown in Fig. 4(c), which is the well-known aliasing effect. Based on the F-Principle, as demonstrated in Fig. 4(c), these artificial low frequency components will be first captured to explain the training samples, whereas the high frequency components will be compromised by DNN. For MNIST/CIFAR10, since the power of high frequencies is much smaller than that of low frequencies, artificial low frequencies caused by aliasing can be neglected. To conclude, the distribution of power in Fourier domain of above two types of problems exhibits significant differences, which result in different generalization performances of DNNs according to the F-Principle.
Related work
As widely observed in experiments, DNNs with gradient-based training show different generalization abilities for different problems. On the one hand, there are different approaches attempting to explain why the training process often leads to a DNN of good generalization ability even when the number of parameters is much larger than the number of training data (Zhang et al., 2016). For example, generalization error is related to various complexity measures (Bartlett et al., 1999; Bartlett & Mendelson, 2002; Bartlett et al., 2017a; b; Neyshabur et al., 2017; Golowich et al., 2017; Dziugaite & Roy, 2017; Neyshabur et al., 2018; E et al., 2018), local properties (sharpness/flatness) of loss functions at minima (Hochreiter & Schmidhuber, 1995; Keskar et al., 2016; Dinh et al., 2017; Wu et al., 2017), stability of optimization algorithms (Bousquet & Elisseeff, 2002; Xu & Mannor, 2012; Hardt et al., 2015), and implicit bias of the training process (Neyshabur et al., 2014; Poggio et al., 2018; Soudry et al., 2018; Arpit et al., 2017; Xu et al., 2018). On the other hand, several works focus on the failure of DNNs (Shalev-Shwartz et al., 2017; Nye & Saxe, 2018), e.g., fitting the parity function, in which a well-trained DNN possesses no generalization ability.
In the revised version, Rahaman et al. (2018) also examines the F-Principle in the MNIST dataset. However, they add noise to MNIST, which contaminates the labels. They only examine not very deep (6-layer) fully connected ReLU network with MSE loss, while cross-entropy loss is widely used.
Acknowledgments
The authors want to thank Weinan E (Princeton University) and David W. McLaughlin (New York University) for helpful discussions and thank Yang Yuan (Tsinghua University) and Zhanxing Zhu (Peking University) for critically reading the manuscript. Part of this work was done when ZX, YZ, YX are postdocs at New York University Abu Dhabi and visiting members at Courant Institute supported by the NYU Abu Dhabi Institute G1301. The authors declare no conflict of interest.
References
Appendix A Illustration of F-Principle for 111-d synthetic data
Next, we investigate the F-Principle on real datasets with more general loss functions other than MSE which was the only loss studied in the previous works (Xu et al., 2018; Rahaman et al., 2018). All experimental details can be found in Appendix. B.
Appendix B Experimental settings
In Fig. 5, the parameters of the DNN is initialized by a Gaussian distribution with mean and standard deviation . We use a tanh-DNN with widths -- with full batch training. The learning rate is . The DNN is trained by Adam optimizer (Kingma & Ba, 2014) with the MSE loss function.
In Fig. 1, for MNIST dataset, the training process of a tanh-DNN with widths --- is shown in Fig. 1(a) and 1(b). For CIFAR10 dataset, results are shown in Fig. 1(c) and 1(d) of a ReLU-CNN, which consists of one convolution layer of , a max pooling of , one convolution layer of , a max pooling of , followed by a fully-connected DNN with widths ----. For both cases, the output layer of the network is equipped with a softmax. The network output is a -d vector. The DNNs are trained with cross entropy loss by Adam optimizer (Kingma & Ba, 2014). (a, b) are for MNIST with a tanh-DNN. The learning rate is with batch size . After training, the training accuracy is and test accuracy is . The amplitude of the Fourier coefficient with respect to the fourth output component at each frequency is shown in (a), in which the red dots are computed using the training data. Selected frequencies are marked by black squares. (b) at different training epochs for the selected frequencies. (c, d) are for CIFAR10 dataset. We use a ReLU network of a CNN followed by a fully-connected DNN. The learning rate is with batch size . (c) and (d) are the results with respect to the ninth output component. After training, the training accuracy is and test accuracy is .
In Fig. 2, for MNIST, we use a fully-connected tanh-DNN with widths --- and MSE loss; for CIFAR10, we use cross-entropy loss and a ReLU-CNN, which consists of one convolution layer of , a max pooling of , one convolution layer of , a max pooling of , followed by a fully-connected DNN with widths - and the output layer of the network is equipped with a softmax. The learning rate for MNIST and CIFAR10 is and , respectively. The networks are trained by Adam optimizer (Kingma & Ba, 2014) with batch size . For VGG16, the learning rate is . The network is trained by Adam optimizer (Kingma & Ba, 2014) with batch size .
In Fig. 3, the samples are evenly spaced in $1001. We use a DNN with widths 1-4000-500-400-1 and full batch training by Adam optimizer (Kingma & Ba, 2014). The learning rate is0.0005\beta100.02$.
In Fig. 4, the settings of (a) and (b) are the same as the ones in Fig. 1. For (c), we use a tanh-DNN with widths 10-500-100-1, learning rate under full batch-size training by Adam optimizer (Kingma & Ba, 2014). The parameters of the DNN are initialized by a Gaussian distribution with mean and standard deviation .
Appendix C Central difference scheme and Jacobi method
Consider a one-dimensional (1-d) Poisson’s equation:
$n+1h=2/n$. The Poisson’s equation in Eq. (9) can be solved by the central difference scheme,
A class of methods to solve this linear system is iterative schemes, for example, the Jacobi method. Let , where is the diagonal of , and and are the strictly lower and upper triangular parts of , respectively. Then, we obtain
We perform the standard error analysis of the above iteration process. Denote as the true value obtained by directly performing inverse of in Eq. (11). The error at step is . Then, , where . The converging speed of is determined by the eigenvalues of , that is,
and the corresponding eigenvector ’s entry is
where can be understood as the magnitude of in the direction of . Then,
Therefore, the converging rate of in the direction of is controlled by . Since
the frequencies and are closely related and converge with the same rate. Consider the frequency , is larger for lower frequency. Therefore, lower frequency converges slower in the Jacobi method.
Appendix D Proof of theorems
The activation function we consider is .
For a DNN of one hidden layer with nodes, 1-d input and 1-d output:
We define the amplitude deviation between DNN output and the target function at frequency as
The descent increment at any direction, say, with respect to parameter , is
The absolute contribution from frequency to this total amount at is
where , , is a function with respect to and , which can be found in one of Eqs. (24, 25, 26).
When the component at frequency where is not close enough to , would dominate for a small . Through the above framework of analysis, we have the following theorem. Define
Consider a one hidden layer DNN with activation function . For any frequencies and such that , , and , there exist positive constants and such that for sufficiently small , we have
We remark that and depend on , , , , , , and .
To prove the statement, it is sufficient to show that for each , where
We prove this for , that is, . The proofs for and are similar. Without loss of generality, we assume that , , and , . According to Eq. (24), the inequality is equivalent to
Note that for . Thus
For with sufficiently small , and . Also note that and that for sufficiently small ,
where and . Define where
Since and , we have . Then Eq. (40) only holds for some large , more precisely, . Thus we obtain the estimate for the (one-dimensional) Lebesgue measure of
Considering a DNN of one hidden layer with activation function . Suppose the target function has only two non-zero frequencies and , that is, , , and , and for . Consider the loss function of with gradient descent training. Denote
that is, decreases faster than . There exist positive constants and such that for sufficiently small , we have
Therefore, Eq. (45) is a sufficient condition for . Based on the theorem 1, we have proved the theorem 2. ∎
Appendix E Memorizing 222-d image
We train a DNN to fit a natural image (See Fig. 6(a)), a mapping from coordinate to gray scale strength, where the latter is subtracted by its mean and then normalized by the maximal absolute value. First, we initialize DNN parameters by a Gaussian distribution with mean and standard deviation (initialization with small parameters). From the snapshots during the training process, we can see that the DNN captures the image from coarse-grained low frequencies to detailed high frequencies (Fig. 6(b)). As an illustration of the F-Principle, we study the Fourier transform of the image with respect to for a fixed (red dashed line in Fig. 6(a), denoted as the target function in the spatial domain). The DNN can well capture this 1-d slice after training as shown in Fig. 6(c). Fig. 6(d) displays the amplitudes of the first frequency components. Due to the small initial parameters, as an example in Fig. 6(d), when the DNN is fitting low-frequency components, high frequencies stay relatively small. As the relative error shown in Fig. 6(e), the first five frequency peaks converge from low to high in order.
Next, we initialize DNN parameters by a Gaussian distribution with mean and standard deviation (initialization with large parameters). After training, the DNN can well capture the training data, as shown in the left in Fig. 6(f). However, the DNN output at the test pixels are very noisy, as shown in the right in Fig. 6(f). For the pixels at the red dashed lines in Fig. 6(a), as shown in Fig. 6(g), the DNN output fluctuates a lot. Compared with the case of small initial parameters, as shown in Fig. 6(h), the convergence order of the first five frequency peaks do not have a clear order.
Appendix F Another viewpoint of examining F-Principle in MNIST/CIFAR10 through filtering method
The section we present another viewpoint of examining F-Principle in MNIST/CIFAR10 through filtering method. For readers’ convenience, we describe the filtering method again in this section.
We train the DNN with original dataset . The Gaussian-filtered dataset used to examine the DNN at each training epoch can be obtained by
where . For fixed , clearly, preserves the low frequency part while losing the high frequency part of . When , , i.e., keeping all frequencies. When , , i.e., keeping only the lowest (zero) frequency. As increases, preserves less low-frequency components. The turning epoch, , would then decrease with . Therefore, the F-Principle predicts that during the training of original dataset :
First, for a fixed , the distance between the DNN output and a low-frequency part of , , would first decrease and then increase.
Second, monotonically decreases with .
Note that if an algorithm captures the target function from high to low frequency, these two predictions fail. Ideal experiments are shown in Appendix G to illustrate this point.
F.2 DNNs with various settings
With the filtering method, we show the F-Principle in the DNN training process of real datasets. For MNIST, we use a fully-connected tanh-DNN (no softmax) with MSE loss; for CIFAR10, we use cross-entropy loss and a ReLU-CNN, followed by a fully-connected DNN with a softmax.
As an example, results of each dataset for one are shown in Fig. 8(a). In both cases, first decreases and then increases, which meet the first prediction.
As shown in Fig. 8(b), monotonically decreases with , which meets the second prediction. We also remark that, based on above results on cross-entropy loss, the F-Principle is not limited to MSE loss, which possesses a natural Fourier domain interpretation by the Parseval’s theorem as illustrated in (Xu et al., 2018) and (Rahaman et al., 2018). Note that the above results holds for optimization methods of both gradient descent and stochastic gradient descent.
F.3 F-Principle in VGG16
It is important to verify the F-Principle in a commonly used and large DNNs. Therefore, we use the filtering method to show the F-Principle in the VGG16 (Simonyan & Zisserman, 2014) equipped with a 1024 fully-connected layer. We train the network with CIFAR10 from scratch. As shown in Fig. 9 (a) and (b), the phenomena are consistent with the first and second prediction in Section F.1.
Appendix G Behavior of anti-F-Principle in Synthetic data through filtering method
In this section, we refer to F-Principle (anti-F-Principle) if monotonically decreases (increases) as , i.e., low (high) frequency has higher priority when converges to as . Fig. 10 shows that F-Principle and anti-F-Principle have different behavior in the filtering method. In any case, the F-Principle meets the two predictions in the main text, that is, during the training of original dataset :
First, for a fixed , the distance between the DNN output and a low-frequency part of , , would first decrease and then increase.
Second, monotonically decreases with .
An intuitive understanding of the anti-F-Principle is in the next sub-section.
G.2 Understanding of the phenomenon of anti-F-Principle
If an algorithm captures the target function from high to low frequency, the two F-Principle predictions fail. Here show ideal experiments in Fig. 11 to illustrate this claim.
Firstly, consider that the target function decays in Fourier domain. In Fig. 11a, the target function has three frequencies, marked by black dots; the filtered data , marked by red dots and dashed line, preserves all of the first frequency, most of the second frequency, and non the third frequency. The initial value is zero at all three frequencies (Note that the initial DNN output is often close to zero). As high frequency converges faster, the third frequency converges while other two frequencies do not, denoted by the yellow curve. Despite the fitting curve deviates from the filtered data at the third frequency, due to the large amplitude of first two frequencies, the combined contribution from the first two frequencies leads the fitting curve closer to the filtered data, i.e., decreases. As the fitting curve evolves from the magenta one to the cyan one, the fitting curve deviates from the filtered data at the second frequency, however, it gets much closer to the filtered data at the first frequency, leading to decrement of . Therefore, decreases during the training (Fig. 11b), i.e., contradicting to the F-Principle’s predictions fail.
Secondly, consider that the target function keeps constant in Fourier domain. At a early stage, the fitting curve evolves from the blue solid one to the blue dashed one, the summation of the first two frequencies, which makes the fitting curve closer to the filtered one (red dashed), is large than the change of the third frequency, then, decreases. At the second stage, the fitting curve evolves from the magenta solid one to the magenta dashed one, the summation of the second and the third frequencies, which makes the fitting curve deviate from the filtered one (red dashed), is large than the change of the first frequency, then, increases. At final stage, only the first frequency, which is shared with the filtered data, does not converge yet. Then, converging the first frequency makes decreases. Therefore, first decreases, then increases, and finally decreases during the training (Fig. 11d), i.e., contradicting to the F-Principle’s predictions fail.
Thirdly, consider that the target function increases in Fourier domain. Before the final stage, the third frequency dominates the evolution (Fig. 11e), thus, increases. At final stage, increases slowly due to the converging of the first frequency, which is small-amplitude. Therefore, almost always increases during the training (Fig. 11f), i.e., contradicting to the F-Principle’s predictions fail.