An Effective Gram Matrix Characterizes Generalization
in Deep Networks
Abstract
We derive a differential equation that governs the evolution of the generalization gap when a deep network is trained by gradient descent. This differential equation is controlled by two quantities, a contraction factor that brings together trajectories corresponding to slightly different datasets, and a perturbation factor that accounts for them training on different datasets. We analyze this differential equation to compute an “effective Gram matrix” that characterizes the generalization gap after training in terms of the alignment between this Gram matrix and a certain initial “residual”. Empirical evaluations 111Code at https://github.com/grasp-lyrl/effective-gram-matrix.git on image classification datasets indicate that this analysis can predict the test loss accurately. Further, at any point during training, the residual predominantly lies in the subspace of the effective Gram matrix with the smallest eigenvalues. This indicates that the training process is benign, i.e., it does not lead to significant deterioration of the generalization gap (which is zero at initialization). The alignment between the effective Gram matrix and the residual is different for different datasets and architectures. The match/mismatch of the data and the architecture is primarily responsible for good/bad generalization.
1 Introduction
Generalization is the ability of a model to apply patterns learned from training data to new, unseen data. Deep neural networks are interesting in this regard because, despite having many parameters and a complex loss landscape, they can still generalize well. This challenges the traditional statistical wisdom, e.g., the bias-variance trade-off, which suggests that highly flexible models should overfit and perform poorly on test data. Deep networks however consistently perform well on unseen data, raising fundamental questions about the principles that govern their generalization. A large body of work has sought to tackle this question and there are numerous perspectives on the relationship between training data, test data, and the model class for deep networks in the literature today. While this work provides valuable insights, each of the existing lines of attack have their limitations.
Probably-approximately correct (PAC) frameworks
The PAC learning framework (Valiant, 1984) provides generalization bounds for models trained on independently and identically distributed (i.i.d.) data, using measures such as Vapnik-Chervonenkis (VC) dimension or Rademacher complexity to characterize the hypothesis space. The PAC-Bayes framework (McAllester, 1999) extends these ideas by deriving generalization error bounds for randomized estimators. However, both frameworks are limited in their ability to explain the generalization behavior of modern deep neural networks. Despite their rich hypothesis class and extremely large VC dimensions, deep neural networks consistently achieve remarkable generalization, a phenomenon that defies the worst-case assumptions inherent in these classical frameworks.
Simplified models of deep networks
To move beyond worst-case analyses, a direct examination of the exact solutions of deep neural networks is an appealing approach. However, due to the inherent complexity of these networks, such analyses are often intractable. Instead, various solvable models from statistics and physics have been employed to partially characterize deep neural network behavior, offering valuable theoretical insights. Linear regression, for instance, has been widely used to explore phenomena like benign over-fitting (Bartlett et al., 2020) and double descent (Hastie et al., 2022; Belkin et al., 2020). To investigate the effects of depth, deep linear networks have served as a useful abstraction for studying multi-layer dynamics (Laurent and von Brecht, 2018). One of the most prominent frameworks in this area is the Neural Tangent Kernel (NTK) approach (Jacot et al., 2018), which models the training dynamics of deep neural networks in the infinite-width regime under a kernel-based approximation. Mallinar et al. (2022); Belkin et al. (2018) characterized different regimes of kernel regression and analyzed its resemblance with deep learning. The NTK method has enabled significant results on convergence (Du et al., 2019; Li and Liang, 2018) and generalization (Arora et al., 2019; Jacot et al., 2020). Bowman and Montúfar (2022) analyzed the divergence of finite-width neural networks with NTK regime in different eigenspaces. Similarly, mean-field analysis (Chizat and Bach, 2018; Mei et al., 2019) has been used to study the evolution of neuron distribution in the infinite-width limit. These models often rely on assumptions such as convexity in the loss landscape and constraining the dynamics to a region around initialization. This precludes feature learning—a critical aspect of modern deep neural networks.
Non-worst-case generalization bounds
Infinite-width assumptions are impractical for real-world scenarios, prompting research into deriving bounds for general neural networks by making mild assumptions about the training process and data. For example, Bartlett et al. (2017); Neyshabur et al. (2018) analyzed the complexity of the reachable hypothesis class and proposed weight-dependent generalization bounds that restrict the hypothesis space based on the weights’ distance to a reference point. Dziugaite and Roy (2017); Yang et al. (2022) established generalization bounds for stochastic algorithms using properties of the trained minima, however, these bounds are derived in a post-hoc manner, based on the trained solution. Algorithm-specific approaches, such as sensitivity analyses on the effects of perturbations of the dataset, provide insights into algorithmic stability and its impact on generalization (Bousquet and Elisseeff, 2002; Hardt et al., 2016; Xu and Mannor, 2012; Chu and Raginsky, 2023). Kawaguchi et al. (2022) gives a generalization bound from data-dependent robustness analysis. Xu and Raginsky (2017); Mou et al. (2018) explored the stability of stochastic algorithms using information-theoretic approaches, which has led to further discussions (Negrea et al., 2019; Neu et al., 2021; Lugosi and Neu, 2022) that offer generalization bounds that depend on the training trajectory. By exploring the conditional mutual information (Hafez-Kolahi et al., 2020; Steinke and Zakynthinou, 2020), one can get tighter generalization bounds. Additionally, by assuming specific properties of the training loss landscape, studies such as (Kozachkov et al., 2023) and (Lugosi and Neu, 2022) provided generalization guarantees. These methods often rely on assumptions that are uniformly applied across the entire hypothesis space, which can be problematic. Task-specific analysis of neural network training are provided by (Ramesh et al., 2024; Mao et al., 2024). Chuang et al. (2021) gives margin-based generalization bound normalized by optimal transport cost, deploying the properties of data while ignoring the training process.
1.1 Contributions
We analyze how the generalization gap accumulates along the training trajectory. We derive a differential equation describing the evolution of the averaged loss difference, controlled by the contraction factor and the perturbation factor. This equation tells us how perturbation of dataset affects the output of the predictor during training. We define an “effective Gram matrix” for neural network training, that characterizes the accumulation of generalization gap in different subspaces. Using this effective Gram matrix, we derive a complexity measure that faithfully characterizes the generalization gap in general networks. This analysis allows us to get a data-dependent estimate of the generalization gap. Time-varying contraction and perturbation factors along the training trajectory allow us to avoid making uniform assumptions about the loss function. We next describe the contributions of the paper.
-
•
In Section 3.2, we derive the differential equation for the evolution of the averaged loss difference . This equation depends upon a certain “contraction factor” and a “perturbation factor” .
-
•
In Section 3.3 and Section 3.4, we derive the effective Gram matrix , and give a complexity measure in terms of the quadratic form , that faithfully characterize the generalization ability of neural networks. This analysis holds for arbitrary networks and loss functions.
-
•
In Section 4, we calculate numerical approximations of and projections of the residuals onto different eigenspaces of . We show that simpler tasks and better model architectures benefit the training process due to an effective Gram matrix with smaller eigenvalues and better alignment with the initial residual, resulting in better generalization at the end of training.
2 Preliminaries
Let denote the set of integers . We use the notation to denote the inner product of vectors , . For a function , we write and, sometimes, . We use for the absolute value of a scalar, -norm of a vector or a matrix, and the Frobenius norm of a matrix, respectively. We use the notation when there exists constants such that for . We omit the subscript indicating the size of dataset, and indicating the time, for all quantities defined in this paper when no ambiguity arises.
Dataset
Let be the sample space where and are input and output spaces, respectively. Consider a dataset of size (each drawn i.i.d. from a distribution . Let denote the distribution of the dataset, i.e., . Let denote a modified dataset obtained by removing the -th datum, i.e., .
Predictor and the loss function
We consider the predictor where is the weight space. Consider a loss function . As an example, for the cross-entropy loss on a -class classification problem, , and the loss , where with and denoting the -th element of and , respectively. We use the notation as a shorthand. Let be the average loss over the dataset .
Gradient flow
Let and denote solutions corresponding to the gradient flows
| (1) |
respectively. Unless otherwise specified, we assume that and are initialized at the same point for all . As a precursor, in Section 3, we will chose and to be initializations of neural networks. In Section 4, we will also sometimes initialize and to be the weights of neural networks that are not fully trained, in this case, and are not necessarily the same.
Generalization gap
We will consider a few different measures of performance of a predictor trained with gradient flow. Given a predictor , a loss function , and an initialization , the generalization loss and the train loss of gradient flow trained on at time are
Our main quantity of interest is the generalization gap, defined as their difference
The expected values of these quantities will be useful to us in Section 3. They are the expected generalization loss , expected train loss and the expected generalization gap . The notations and denote expectations with respect to the random draw of dataset and the sample , from distributions and , respectively. We sometimes omit the subscript and in the following sections.
2.1 Contraction theory
This section introduces some preliminary material on contraction theory (Lohmiller and Slotine, 1998, 2000), which provides a way to analyze solutions of slightly different dynamical systems. Contraction theory rewrites Lyapunov theory (Isidori, 1995; Marino and Tomei, 1995) using a quadratic Lyapunov function, defined by a Riemannian contraction metric and its uniform positive definite matrix, characterizing the necessary and sufficient conditions for exponential convergence of the multiple trajectories to each other and the stability of these trajectories to perturbations of the dynamics. Consider a nonlinear dynamical system
| (2) |
The following theorem gives guarantees of the exponential convergence of trajectories with different initializations.
Theorem 1 (Theorem 2.1 from Tsukamoto et al. (2021)).
If there exists a uniformly positive definite matrix for all , such that the following condition holds for some ,
| (3) |
then all trajectories of Eq. 2 converge to a single trajectory under the metric induced by exponentially fast regardless of their initial conditions, i.e. for all trajectories , of Eq. 2, , where denotes the distance under the metric induced by . Dynamical system Eq. 2 satisfying Eq. 3 is said to be “contracting”, under the “contraction metric” induced by . The factor is defined to be the “contraction factor”.
Using Theorem 1, we can also analyze trajectories of a perturbed dynamical system
| (4) |
Let , be solutions of Eq. 2 and Eq. 4, respectively. The next theorem shows that for a contracting system, the solution of the perturbed system does not differ too much from that of the original system, under certain conditions.
Theorem 2 (Theorem 2.3 from Tsukamoto et al. (2021)).
Assume that the dynamical system Eq. 2 is contracting under with factor . If and there exist constants such that for all , then we have
where , denote the distance under Euclidean metric and metric induced by respectively.
In short, for contracting systems, for large times , the bound of the distance between the solution of the original dynamic and the perturbed dynamic is determined by the perturbation of the system, the contraction factor, and the eigenvalues of the metric. In this paper, we will be interested in using these ideas to understand the difference between two trajectories evaluated on certain loss functions that are fitted using slightly different datasets.
Kozachkov et al. (2023) gave a bound on generalization gap using Theorem 2 by analyzing the difference of gradient flow trajectories trained on datasets with one replaced sample under the assumption that the dynamic is contracting uniformly on the state space with factor . In Lemma 4, we will define another notion of contraction that does not require a uniform , or the uniform boundedness of . This will enable a more refined analysis of the generalization gap.
3 Methods
We first show that the generalization gap can be approximated by the “averaged loss difference” defined in Section 3.1. We will compute in Section 3.2 how evolves over time, and show that its dynamics arises from a contraction factor and a perturbation factor . In Section 3.3, we show that a certain “residual” (precisely, the derivative of the loss with respect to the predictor for each datum) largely controls the perturbation factor. Through the evolution of and , we can define an “effective Gram matrix” and a complexity measure in terms of a quadratic form that characterizes the generalization gap at the end of training (Section 3.4). Proofs of all theorems and lemmas are deferred to Appendix A.
3.1 Approximation of the generalization gap
We first define two quantities pertaining to the difference between perturbed trajectories. Define the pointwise loss difference to be the difference of trajectories and evaluated in terms of the loss ,
and the averaged loss difference is defined to be
| (5) |
Note that in the averaged loss difference, we use the Leave-One-Out-Cross-Validation (LOOCV) loss as an estimate of the generalization loss. The following lemma shows how the expected generalization gap can be approximated by .
Lemma 3.
Assume that the expected generalization loss is non-increasing in , the expected training loss is non-decreasing in and the expected generalization gap is non-negative for all . Then
If we also have as , then,
The concentration of to can also be guaranteed if algorithm stability is assumed (see Lemma 22). Hence, the expected generalization gap can be well approximated by the averaged loss difference under certain conditions. See Section 3.1, Table S.1 for numerical results of generalization gap and averaged loss difference. We will next study the evolution of .
3.2 Evolution of the averaged loss difference
The pointwise loss difference describes the difference of two trajectories with slightly perturbed drifts. By deriving differential equations for the evolution of and , we analyze the contraction and perturbation of the trajectories in a way that is non-uniform in both time and space, distinguishing it from classical contraction theory. We first give the following lemma for .
Lemma 4.
For loss functions that is differentiable in for all ,
where the pointwise contraction factor is given by
and the pointwise perturbation factor is given by
We should note that the lemma can be extended to any piecewise differentiable loss if we define the the gradient at the non-differentiable point to be any constant vector with bounded norm. This covers all of the commonly used architectures and activation functions. To give some intuition of the lemma, the contraction factor represents a force that pulls two trajectories with the same drift but different values at time closer together under the loss function , while the perturbation factor quantifies the differences between the two trajectories at time induced by the gradient divergence .
Remark 5 (Deviations from classical contraction theory).
In classical contraction theory, and provide a uniform contraction rate and perturbation magnitude over time and trajectories (Theorems 1 and 2). In comparison, and in Lemma 4 are derived directly from the evolution of , which describes only the contraction and perturbation of and , and vary with time. This non-uniformity allows for a more refined analysis of gradient flow for neural networks. Indeed, the energy landscape may not be uniformly good in the entire weight space, but it could be benign along most of the training trajectory. Our development in this paper from here on will therefore diverge significantly from the generalization bounds derived under uniform assumptions on the energy landscape (Kozachkov et al., 2023; Charles and Papailiopoulos, 2018).
By taking the average over the numerator and denominator of , and averaging over in Lemma 4, we obtain the following equation for the averaged loss difference :
| (6) |
The solution of this differential equation can be written in the integral form as
| (7) |
with the assumption that for all . Here is defined to be the averaged contraction factor
| (8) |
and is the averaged perturbation factor
| (9) |
where represents the covariance matrix of for sampled uniformly from the dataset . We should note that is a statistic that depends only on the training samples, while depends on both training samples and the held-out test samples. Note that by taking the expectation over , and the numerator and denominator of , we get the evolution of , which represents the generalization gap better. See Section A.3 for details.
Remark 6 (Classical contraction theory with uniform bounds on contraction and perturbation).
Remark 7 (Comparing trajectories in terms of their loss vs. weight space difference).
Richards and Kuzborskij (2021); Akbari et al. (2021) analyze the difference of algorithm in the weight space when one sample is replaced, and derive generalization bound using the Lipchitz assumption of the loss function. However, in most cases, a uniform Lipchitz constant is far from good for most part of the weight space for deep networks. In such cases, the difference in the weights does not provide a tight estimate of the difference of the predictions—and this is the key reason for loose generalization bounds from this kind of analysis. By comparing the difference of and directly in terms of the loss in Lemma 4, instead of the weight space (with or without a modified Euclidean metric) as used in Theorem 1, in this paper, we can achieve a tighter estimate of the evolution of the generalization gap.
Remark 8 (Relationship to information theoretic generalization bounds).
In Negrea et al. (2019); Neu et al. (2021); Banerjee et al. (2022), the authors derive generalization bounds controlled by the sum of trace of the gradient covariance along the training trajectory, . Intuitively, this summation tells us about the size of the tube of trajectories in loss space that arises from training on different datasets. The worse the estimate of this tube, the worse the generalization bound. Our expression in Eq. 7 provides a more general and tighter formulation, where the damping factor corrects for the size of this tube. A positive contraction factor leads to quicker shrinking of the two trajectories that are being trained on slightly different datasets. Furthermore, our analysis applies to deterministic algorithms, unlike previous works on information-theoretic bounds (Xu and Raginsky, 2017; Mou et al., 2018; Futami and Fujisawa, 2023), which holds only for randomized algorithms because the proof relies on the non-expansiveness of the Kullback-Leibler divergence of non-singular distributions.
Remark 9 (Some intuition on the contraction factor).
If we expand the contraction factor in Lemma 4 using the first-order Taylor expansion in both its numerator and denominator, and by approximating and by the loss on the full dataset , we see that
| (10) |
This is a general version of Rayleigh quotient , where , , and . Intuitively, positive contraction implies that the Hessian does not change the cosine angle of the gradient and the averaged difference of trajectories. Fig. 1 compares the true contraction factor and the full-gradient approximation Eq. 10. We can see the approximated contraction factor is positive (which indicates contractive dynamics) and that it is also close to the true contraction factor. This suggests that the Hessian of the training loss is positive definite along the directions of gradient and the averaged difference of trajectories, for most of the training time. See Section 4 for the batch version of the contraction factor , and Section A.8 for the detailed calculations of Eq. 10.
3.3 Evolution of the residual and perturbation
In Section 3.2, we have shown that the evolution of is controlled by the averaged perturbation and the averaged contraction , and that is closely related to the trace of the covariance of gradients. We will now introduce the notion of a “residual”. We further show how it relates to the perturbation factor, from which we derive the evolution of .
Let denote the gradient of the loss function with respect to the predictor . Let denote predictor gradient on , evaluated on weight . We define the residual on dataset at time to be
| (11) |
The residual is the collection of loss-predictor gradients on the dataset . It effectively describes the quality of the weights at time and indicates the direction of the training progresses in the predictor space. Intuitively, it represents the part of the “task” that remains to be fitted at time . As a special case, if we consider the squared loss for , the residual is the normalized displacement vector from the predictor to the target, i.e., , where , and . If we initialize the predictor such that for all , then the -norm of the residual is the largest at initialization and vanishes at interpolation following the gradient flow Eq. 1. The definition of residual generalizes the displacement vector in the squared loss case, and can be applied to any loss function with global minimum 0. The factor will be justified in Remark 20.
The evolution of is governed by the following equation derived from gradient flow in Eq. 1.
| (12) | ||||
This is a linear time-varying ordinary differential equation. In general, its solution can be written as
| (13) |
where is called the propagator. The numerical approximation of will be discussed in Section B.4.
Our next goal will be to show that the averaged perturbation factor is controlled by the residual. We will do so using the following lemma.
Lemma 10.
The trace of the gradient covariance can be decomposed in terms of two matrices as
| (14) |
| (15) | ||||
Remark 11.
Let us emphasize that all three quantities, , and are elements of . For regression problems, we might have in which case they are simply matrices in . For classification problems with categories, , and therefore these three quantities are four-dimensional tensors. But we can interpret them as elements of . This amounts to vectorizing the tensor as a matrix. Just like a matrix may be reshaped into a vector, we have reshaped a tensor into a matrix.
Equation Eq. 13 and the above lemma together give
| (16) |
where we denote as for short. In Eq. 14, the term pertains to the covariance of the predictor on the training dataset . We can see that the residual controls the magnitude of gradients for hence that of the covariance. For networks that train quickly, the residual norm vanishes quickly, leading to a smaller accumulation of the perturbation term above, and hence a smaller generalization gap — this explains the folklore theorem “networks that generalize well also train quickly”.
Remark 12 (Relationship to weight norm based bound).
Arora et al. (2019) also study the residual dynamics to obtain an estimate of the norm of eventual weights that can be reached by gradient descent. The authors derive a weight-norm-based bound that uses the results of Bartlett et al. (2017) on Rademacher complexity. Similar ideas are adpoted in Allen-Zhu et al. (2019); Cao and Gu (2019), analyzing SGD and online learning of fully connected neural nets respectively. Liu et al. (2022) derives weight norm bound under uniform-LGI conditions for general optimization problems. In contrast, we use the evolution of the residual in Eq. 12 to calculate the trace of the gradient covariance. This is directly related to the difference of the loss of networks trained on perturbed datasets—as opposed to the difference in their weights. Our analysis is conducted directly in the prediction space and provides a more direct and refined characterization of generalization for general neural networks.
3.4 Effective Gram matrix for neural networks
We next derive an expression of averaged loss difference in terms of a certain quadratic form of the initial residual and an “effective Gram matrix”, by analyzing the evolution of and during training. The following theorem combines the solution of in Eq. 7 and in Eq. 13, along with the decomposition of in Eq. 14.
Theorem 13.
Assume that the evolution of and follows Eq. 1 and the loss function is smooth in for every . We have
| (17) |
where
| (18) |
is positive semi-definite. Let
when the limit exists, then we have
We call the effective Gram matrix of a neural network.
We call the “effective Gram matrix” because it is a weighted average of Gram matrices 222In linear algebra, the Gram matrix of a set of vectors is given by , where are columns of matrix . of the form , where . We next show the conditions that guarantee the existence of .
Lemma 14.
Let and . Let and be the largest and smallest eigenvalues of respectively. If
-
(i)
exists,
-
(ii)
there exists a constant such that for all , and
-
(iii)
the contraction factor for all ,
then exists in -norm.
Remark 15.
Sometimes the effective Gram matrix calculated from the propagator derived from does not converge. But in this case, we can create a perturbed version of with a controlled such that the conditions of Lemma 14 are satisfied. This guarantees the convergence of while preserving the trajectory of given . For example, in Section 3.5 we construct as a perturbed version of .
We should note that to analyze generalization gap via the relation between the residual and the effective Gram matrix meaningfully, should corresponding to a trajectory that fits the data by time . This is true only when , which by Eq. 12 also implies that for all . Hence we only consider in the interpolating regime where , instead of a finite time . This idea is also reflected in Arora et al. (2019), where the authors consider the NTK regime for infinite time, in which case, the training data is fitted perfectly.
Remark 16 (Data and architecture dependent generalization bound).
The quadratic form in Theorem 13 gives a data and architecture dependent measure of complexity that characterizes the generalization gap of general deep neural networks. We will also see in the experimental section this faithfully captures the true generalization gap. Eigenvalues of represent the relative contribution to the generalization gap accumulated in the different subspaces during training. If the initial residual (roughly, the distance to the target) predominantly projects onto the subspace of with small eigenvalues, the training process is benign, resulting in a small eventual generalization gap (as showed in Section 4.2). This is therefore one of the key quantities that we will track in numerical experiments on different architectures and datasets in Section 4.
Remark 17 (Generalization gap of kernel machines).
The generalization loss in kernel ridge regression (Rakhlin and Liang, 2020; Mallinar et al., 2022) can be expressed in terms of quantities that resemble ours, namely, the alignment of the residuals with the Gram matrix (Arora et al., 2019; Jacot et al., 2020). Our effective Gram matrix generalizes this type of complexity measure to arbitrary deep neural networks and loss functions, going beyond two-layer neural networks with infinite neurons and squared loss. However, unlike kernel ridge regression, where the Gram matrix is derived from a fixed kernel that directly recovers the target function, the effective Gram matrix in our setting varies for different datasets and training regimes and does not necessarily coincide with any fixed kernel.
3.5 An example calculation of the (effective) Gram matrix for linear regression
Assume that the sample space is supported on two points with orthonormal inputs, i.e., , with orthogonal inputs each with unit norm, . We choose the predictor to be , and the loss function to be . We therefore have . Consider the dataset with even, where when and when . Assume that for all which ensures that the initial residual is simply the vector of ground-truth targets . The averaged contraction factor in Eq. 8 is
and we have from Eq. 12 and Eq. 15 that
with . Note that is not full rank when . By Lemma 14, the convergence of is largely controlled by the smallest eigenvalue of , which cannot be too small. Hence, to ensure convergence, we define a modified version of with small perturbation on its singular subspace, i.e., , with , , where
In this case, when , we have . The dynamics gives the same trajectory of as Eq. 12, since . By setting with , the effective Gram matrix can be calculated from Eq. 18 as
where , and
indicating that the initial residual lies in the subspace of with zero eigenvalue.
Note that since is supported on only two points, gradient flow trained on a dataset containing both these samples generalizes and achieves zero loss for any data distribution supported on . This coincides with the calculation above, where the averaged loss difference as predicted by the quadratic form in Theorem 13, approaches zero as . The calculation holds regardless of what fraction of data in comes from either of the two points (so long as both are present). Our theorem correctly predicts that the generalization gap goes to zero. Now if we take an expectation, we have
because the dataset is supported on only one of the samples with probability . Theorem 13 is therefore providing a tight prediction of the generalization gap.
The solution lies in . When trained on the dataset , the progress on the direction is slightly less than the other direction, which introduces the non-zero averaged loss difference during training. We should also note that the calculation of the contraction and perturbation factors depends heavily on the sample-wise loss gradient being supported on . The clustering of per-sample gradients happens also in the training of neural networks, as shown in Fort and Ganguli (2019). See Section A.7 for details of the above calculation.
Remark 18 (Comparison with Arora et al. (2019)).
Let us use the technique of Arora et al. (2019) for our example. We can bound the generalization gap in terms of the norm of the eventual weights. The Gram matrix of the linear regression described above is with for some constant (we choose this perturbed version to guarantee the positive definiteness while not affecting the evolution of the residual). The norm of weights can be bounded by , which gives a generalization bound for 1-Lipschitz loss,
This is far looser than the actual generalization error, which is for 1-Lipschitz loss from the calculation above. The key point to emphasize here is that by characterizing the evolution of the point-wise loss difference using the contraction factor, we can work directly in the prediction space instead of working in the weight space. This is the reason why our estimate of the generalization gap is more accurate.
4 Experimental Validation
Datasets
For experimental validation of our theoretical development, we use a number of different datasets and experimental settings.
- •
-
•
Synthetic datasets labeled Syn- are created by modifying the labeling function of the MNIST dataset as follows. We first project MNIST images onto the subspace of the empirical second moment matrix corresponding to the -th to -th eigenvalue, sorted from the largest to the smallest. We then relabel the MNIST inputs using a fully-connected teacher with random weights, applied to the projected images.
-
•
Synthetic datasets labeled Gaussian- are created using Gaussian data from different covariance matrices. Inputs data in Gaussian- are sampled from the multivariate Gaussian distributions with covariance matrix , where the -th eigenvalue is . We then project these inputs onto the subspace of the covariance matrix corresponding to the 10 largest eigenvalues and label the original inputs using a fully connected teacher with random weights, applied to the projected inputs.
The rationale for creating these synthetic datasets will become clear as we discuss the experiments, but in short, we seek to create datasets where the signal-to-noise ratio can be controlled. The smaller the value of and the larger the value of , the larger the signal-to-noise ratio in these synthetic data.
Architectures
We will train FC (fully connected neural networks), LeNet-5 (LeCun et al., 1998) (a network with two convolutional layers and one fully connected layer), and WRN-4-4 (Zagoruyko and Komodakis, 2016) (wide residual network with 4 layers and a widening factor of 4) using (non-stochastic) gradient descent with different numbers of samples drawn from the datasets described above. We use gradient descent as the Euler approximation of gradient flow in our theory. See Appendix B for more details.
Constructing perturbed datasets
The theory in this paper was written when the modified dataset with samples is created by omitting the -th sample. For numerical stability and efficiency of the approximation, in the experiments, we create datasets by omitting a batch of samples. Let denote a subset of with size . Let . We will conduct experiments using modified datasets obtained by removing from . We therefore consider the weight trajectory of the differential equation . The averaged loss difference is modified in the usual fashion with the batch-wise loss difference
Note that denotes the expectation taken over the uniform distribution on all possible choices of in . The formulae for the averaged contraction and perturbation factors and in this setting are shown in Section B.1.
Calculating quantities that pertain to the generalization gap
We are interested in calculating the effective Gram matrix for different configurations of neural network training. To do this, we approximate the gradient flow Eq. 1 by gradient descent with different learning rate. We calculate the averaged contraction factor , averaged perturbation factor , decomposition of the trace of the gradient covariance and using Eq. 8, Eq. 9 and Eq. 15 (or its alternatives for omitting samples setting as in Appendix B) respectively. The propagator is approximated by product methods as described in Section B.4, where we compared it with the Magnus expansion approximation. The integrals for in Eq. 6 and in Eq. 18 are approximated by the trapezoidal method. We will use the statistics in Table 1 to characterize the relation of the initial residual and the effective Gram matrix . The rationale for defining these quantities comes from Theorem 13 which shows that the eventual generalization gap after training is a quadratic form that depends upon the effective Gram matrix and the initial residual. We are interested in understanding how different subspaces of the effective Gram matrix contribute to this quadratic form.
| Notation | Definition |
| The eigenspace and eigenspectrum of a symmetric matrix with eigenvalue decomposition | |
| where , is the vector of eigenspectrum in ascending order. | |
| The mean of the eigenspectrum of a symmetric matrix , . | |
| The -th column of , and the first columns of . | |
| Normalized projection of a vector onto the space (with orthonormal columns). | |
| the -th element . | |
| “Explained magnitude” of a vector in the space (with orthonormal columns) | |
| the -th element . | |
| “Explained magnitude” of a symmetric matrix in its eigenspace | |
| the -th element for . | |
| “Relative index” of the index vector , where . |
4.1 Theorem 13 leads to a good approximation of the generalization gap
Consider Fig. 2. Observe that the true generalization gap , averaged loss difference , and the gap (denoted by in the plot) are all close to each other throughout training. This indicates that the generalization gap can be well approximated by .


We calculate two numerical approximations of : the quantity computed with the true perturbation factor from Eq. 9, and with an approximate perturbation factor derived from Eq. 16 with the propagator given by the product approximation Eq. 21. First note that is close to , which indicates that the gradient descent approximation of Eq. 1 and the trapezoidal approximation of Eq. 7 are good. Second, the similarity of and indicates that the product approximation in Eq. 21 is working well. The results on CIFAR-10 using a convolutional network are largely similar, with slightly less accurate estimates of the generalization gap.
Note that for numerically approximated effective Gram matrix . Hence, the good approximation of the generalization gap by indicates that the numerically approximated effective Gram matrix (which is calculated in the following sections) is a good quantity to use for understanding generalization. We should note that refers to the numerical approximations in the following subsections. In Table S.1, we provide a complete list of results of generalization gap approximation for all the experiments.
| Paper | Architecture | Dataset | # samples | Training method | Bound on Test Data | Actual Value | Relative inaccuracy |
| Arora et al. (2019) | FC | MNIST-2 | 10,000 | GD (second layer fixed) | 0.05 ( loss) | 0.01 ( loss) | 4 |
| Dziugaite and Roy (2017) | FC | MNIST-2 | 55,000 | SGD | 0.161 (error) | 0.018 (error) | 7.9 |
| Wang and Ma (2022) | FC | MNIST-2 | 55,000 | SGD | 0.25 (CE loss) | ||
| Ours | FC | MNIST-10 | 1,100 | GD | 0.47 (CE loss) | 0.45 (CE loss) | 0.05 |
| Ours | LENET-5 | MNIST-10 | 1,100 | GD | 0.24 (CE loss) | 0.20 (CE loss) | 0.18 |
| Negrea et al. (2019) | CNN | MNIST-10 | 55,000 | SGLD | 0.25 (CE loss) | 0.02 (error) | |
| Mou et al. (2018) | CNN | MNIST-10 | 55,000 | SGLD | 1.25 (CE loss) | 0.02 (error) | |
| Ours | FC | CIFAR-2 | 1,100 | GD | 0.34 (CE loss) | 0.41 (CE loss) | 0.17 |
| Arora et al. (2019) | FC | CIFAR-2 | 10,000 | GD (second layer fixed) | 0.6 ( loss) | 0.45 ( loss) | 0.33 |
| Ours | LENET-5 | CIFAR-2 | 1,100 | GD | 0.46 (CE loss) | 0.49 (CE loss) | 0.06 |
| Ours | WRN-4-4 | CIFAR-2 | 1,100 | GD | 0.111 (CE loss) | 0.107 (CE loss) | 0.04 |
Table 2 compares previous results of generalization bounds. The small relative inaccuracy of our methods shows good quality of our approximations.
Remark 19.
While we have tabulated the results above, we should emphasize the following three points for interpreting these results. First, it is not meaningful to compare different theories in Table 2 to find a superior theory. One upper bound being better than another numerically says little about the quantity they both bound. If one simply wanted to predict the generalization gap well, one would be content with using just cross-validation, see (Kawaguchi et al., 2018, Section 4). However, this does not mean that there is no need to do any theory. The goal of work on generalization is to understand what properties of data, architectures and training lead to good generalization. Each work is answering a different facet of this question. This is why there is a big diversity of assumptions, techniques and conclusions. Second, one cannot compare these methods against each other since they have different assumptions on the architecture and training method. Hence, in Table 2, we compare the relative accuracy, which is approximation - actual / actual. This is a reasonable way to compare these approaches. And our approach indeed does very well. Third, our theory is for gradient flow. Thus, our implementation uses gradient descent, not stochastic gradient descent. In practice we cannot get a small training error for these datasets with gradient descent. And this is why we use fewer samples.
4.2 Initial residual lies primarily in the subspace of effective Gram matrix with small eigenvalues
Fig. 3 (left) shows that for MNIST, the initial residual lies primarily in the subspace of with small eigenvalues, while for the random task, the initial residual put more weights into subspace with larger eigenvalues, where the projection is not negligible even for the head eigenvalues. In Fig. 3 (right), the tail subspace of with less than 3% of the eigenvalues recovers 98% of . This shows that if the task that we need to fit is simple, in the sense that the initial residual predominantly lies in the tail subspace of , then the eventual generalization gap is small (the generalization gaps for MNIST and random task are 0.47 and 3.27 respectively). This indicates a benign training process, i.e., the generalization loss accumulates slowly.
Remark 20 (Comparing the statistics for different numbers of samples).
The effective Gram matrix lies in a different space when neural networks are trained with different numbers of samples . Therefore, to compare quantities like , and for different and the same , we use a “relative index” as described in Table 1. We rescale the original index vector to have indices from zero to one. We should emphasize that by normalizing the residual by in Eq. 11, the -norm of the initial residuals is similar when is the same, even if is different. Note that the estimated generalization gap is the average of the eigenvalues , each weighted by the projected residual . We therefore also compute to understand the effect of . Table S.1 details the numerical values of these quantities for different datasets and architectures.


4.3 As training proceeds, the residual projects more into the principal subspace of the effective Gram matrix
We next consider the training process starting from different times instead of . Analogously to what we have done in Section 3, the increment of the averaged loss difference from time to the end of training can be approximated by . The effective Gram matrix for the training process starting from can be calculated using revised contraction and perturbation factors and . The detailed calculation is given in Section B.2.
From Fig. 4, as training proceeds, the residual aligns more and more with the subspace of the effective Gram matrix with large eigenvalues. This is because in the initial phases of training, the residual is first fitted in the subspace with small eigenvalues, and this accumulates the generalization gap slowly. As training proceeds, to reduce the training loss, the network updates the residual to lie in less benign subspaces, those with larger eigenvalues.
4.4 Effective Gram matrix for different datasets
Fig. 6 compares the normalized projection of residual and eigenspectra of the effective Gram matrix for different synthetic datasets. From the classical analysis of linear regression, we know that data is more difficult to learn when labels are correlated with features corresponding to smaller proportions of eigenvalues of the input correlation matrix. In the relabeled MNIST datasets, Syn- with larger labels with less prominent features, and in the Gaussian datasets, Gaussian- with smaller puts less weight on the top eigenvalues as showed in Yang et al. (2022). In both cases, we manually created difficult tasks. Using experiments on synthetic datasets with different levels of difficulty, we see that for difficult tasks, the residual projects more onto the subspace corresponding to larger eigenvalues, and the effective Gram matrix has larger magnitude, which jointly lead to a larger predicted generalization gap by our theory. And indeed, the true generalization gap corroborates this trend.
Fig. 7 compares the training on MNIST and CIFAR-10. The initial residual of MNIST projects more in the eigenspace of the effective Gram matrix with small eigenvalues, and the eigenvalues of for the training of CIFAR are uniformly larger than that of MNIST. This shows that both good task-Gram matrix alignment and the small magnitude of the eigenvalues of are necessary for a “benign training process” and a good eventual generalization gap.


4.5 Effective Gram matrix for different architectures
Fig. 9 compares the normalized projection of residual and eigenvalues of the effective Gram matrix for MNIST and CIFAR when trained using different models (FC, LeNet-5 and WRN-4-4). The eigenspectrum of FC is uniformly larger than that of LeNeT-5 trained with MNIST. Similarly, of FC and LeNet-5 is larger than that of WRN-4-4 when trained with CIFAR. The large magnitude of the effective Gram matrix leads to a large generalization gap accumulation in all subspaces, resulting in worse generalization.
To demonstrate that our theory also applies to models other than neural networks, in Fig. 10, we fit ridgeless kernel regression (Rakhlin and Liang, 2020) with neural tangent kernel using cross-entropy loss for different times (we manually choose the time points so that they spread out over the full training process). Note that the kernel here is the standard NTK, which is not related to our effective Gram matrix. The evolution of the predictor is
Using a fixed Jacobian at initialization leads to larger eigenvalues and more projection of the residual onto the stiff subspaces of the effective Gram matrix , i.e., a larger eventual generalization gap, as is widely known (Fort et al. (2020)).




4.6 Effective Gram matrix for different number of samples
Fig. 11 compares the training of datasets with different sizes. When becomes larger, the initial residual of MNIST projects more in the tail subspaces of the effective Gram matrix , and the tail eigenvalue of becomes smaller. This coincides with the smaller generalization gap as we train with more samples.
5 Conclusion
We identified key quantities in the training process that control the generalization gap, namely, a contraction factor that brings trajectories on different datasets together, and a perturbation factor that arises from the differences in the sample sets. The merit of our analysis is that it can succinctly and faithfully characterize the generalization gap—of general neural networks. The expression in Theorem 13 depends only on the initial residual and the effective kernel . It is important to emphasize that this effective kernel is designed to understand the generalization gap, not the training dynamics. The existence and utility of this kernel indicates that we might be able to fruitfully think of deep networks in cohort with other models in a machine learning practitioner’s toolkit—perhaps they are not as anomalous as they appear to be.
Acknowledgment
This work was funded by grants provided by the National Science Foundation (IIS-2145164, CCF-2212519).
References
- Akbari et al. (2021) A. Akbari, M. Awais, M. Bashar, and J. Kittler. How does loss function affect generalization performance of deep learning? application to human age estimation. In Proceedings of the 38th International Conference on Machine Learning, volume 139 of Proceedings of Machine Learning Research, pages 141–151. PMLR, 2021.
- Allen-Zhu et al. (2019) Z. Allen-Zhu, Y. Li, and Y. Liang. Learning and generalization in overparameterized neural networks, going beyond two layers. In Advances in Neural Information Processing Systems, volume 32, pages 6158–6169, 2019.
- Arora et al. (2019) S. Arora, S. S. Du, W. Hu, Z. Li, and R. Wang. Fine-grained analysis of optimization and generalization for overparameterized two-layer neural networks. In Proceedings of the 36th International Conference on Machine Learning, 2019.
- Ba et al. (2016) J. L. Ba, J. R. Kiros, and G. E. Hinton. Layer normalization. arXiv preprint arXiv:1607.06450, 2016.
- Banerjee et al. (2022) A. Banerjee, T. Chen, X. Li, and Y. Zhou. Stability based generalization bounds for exponential family Langevin dynamics. In Proceedings of the 39th International Conference on Machine Learning, volume 162 of Proceedings of Machine Learning Research, pages 1412–1449. PMLR, 17–23 Jul 2022.
- Bartlett et al. (2017) P. L. Bartlett, D. J. Foster, and M. Telgarsky. Spectrally-normalized margin bounds for neural networks. In Advances in Neural Information Processing Systems, volume 30, pages 6240–6249, 2017.
- Bartlett et al. (2020) P. L. Bartlett, P. M. Long, G. Lugosi, and A. Tsigler. Benign overfitting in linear regression. Proceedings of the National Academy of Sciences, 117(48):30063–30070, 2020. doi: 10.1073/pnas.1907378117.
- Belkin et al. (2018) M. Belkin, S. Ma, and S. Mandal. To understand deep learning we need to understand kernel learning. In Proceedings of the 35th International Conference on Machine Learning, volume 80 of Proceedings of Machine Learning Research, pages 541–549. PMLR, 10–15 Jul 2018.
- Belkin et al. (2020) M. Belkin, D. Hsu, and J. Xu. Two models of double descent for weak features. SIAM Journal on Mathematics of Data Science, 2(4):1167–1180, 2020. doi: 10.1137/20M1336072.
- Bousquet and Elisseeff (2002) O. Bousquet and A. Elisseeff. Stability and generalization. Journal of Machine Learning Research, 2:499–526, 2002.
- Bowman and Montúfar (2022) B. Bowman and G. Montúfar. Spectral bias outside the training set for deep networks in the kernel regime. In Advances in Neural Information Processing Systems, volume 35, 2022.
- Cao and Gu (2019) Y. Cao and Q. Gu. Generalization bounds of stochastic gradient descent for wide and deep neural networks. In Advances in Neural Information Processing Systems, volume 32, pages 10836–10846, 2019.
- Charles and Papailiopoulos (2018) Z. Charles and D. Papailiopoulos. Stability and generalization of learning algorithms that converge to global optima. In Proceedings of the 35th International Conference on Machine Learning, volume 80 of Proceedings of Machine Learning Research, pages 745–754. PMLR, 10–15 Jul 2018.
- Chizat and Bach (2018) L. Chizat and F. Bach. On the global convergence of gradient descent for over-parameterized models using optimal transport. In Advances in Neural Information Processing Systems, volume 31, pages 3036–3046. Curran Associates, Inc., 2018.
- Chu and Raginsky (2023) Y. Chu and M. Raginsky. A unified framework for information-theoretic generalization bounds. In Advances in Neural Information Processing Systems, volume 36, pages 79260–79278, 2023.
- Chuang et al. (2021) C.-Y. Chuang, Y. Mroueh, K. Greenewald, A. Torralba, and S. Jegelka. Measuring generalization with optimal transport. In Advances in Neural Information Processing Systems, volume 34, pages 3031–3044, 2021.
- Du et al. (2019) S. S. Du, X. Zhai, B. Póczos, and A. Singh. Gradient descent provably optimizes over-parameterized neural networks. In International Conference on Learning Representations, 2019.
- Dziugaite and Roy (2017) G. K. Dziugaite and D. M. Roy. Computing nonvacuous generalization bounds for deep (stochastic) neural networks with many more parameters than training data. In Proceedings of the 33rd Conference on Uncertainty in Artificial Intelligence, 2017.
- Fort and Ganguli (2019) S. Fort and S. Ganguli. Emergent properties of the local geometry of neural loss landscapes. arXiv preprint arXiv:1910.05929, 2019.
- Fort et al. (2020) S. Fort, G. K. Dziugaite, M. Paul, S. Kharaghani, D. M. Roy, and S. Ganguli. Deep learning versus kernel learning: An empirical study of loss landscape geometry and the time evolution of the neural tangent kernel. In Advances in Neural Information Processing Systems, volume 33, pages 5850–5861, 2020.
- Futami and Fujisawa (2023) F. Futami and M. Fujisawa. Time-independent information-theoretic generalization bounds for sgld. arXiv preprint arXiv:2311.01046, 2023.
- Hafez-Kolahi et al. (2020) H. Hafez-Kolahi, Z. Golgooni, S. Kasaei, and M. Soleymani. Conditioning and processing: Techniques to improve information-theoretic generalization bounds. In Advances in Neural Information Processing Systems, volume 33, pages 3492–3503. Curran Associates, Inc., 2020.
- Hardt et al. (2016) M. Hardt, B. Recht, and Y. Singer. Train faster, generalize better: Stability of stochastic gradient descent. In Proceedings of The 33rd International Conference on Machine Learning, volume 48 of Proceedings of Machine Learning Research, pages 1225–1234, New York, NY, USA, June 20–22 2016. PMLR.
- Hastie et al. (2022) T. Hastie, A. Montanari, S. Rosset, and R. J. Tibshirani. Surprises in high-dimensional ridgeless least squares interpolation. The Annals of Statistics, 50(2):949–986, 2022. doi: 10.1214/21-AOS2133.
- Isidori (1995) A. Isidori. Nonlinear Control Systems. Communications and Control Engineering. Springer-Verlag, London, 3rd edition, 1995. doi: 10.1007/978-1-84628-615-5.
- Jacot et al. (2018) A. Jacot, F. Gabriel, and C. Hongler. Neural tangent kernel: Convergence and generalization in neural networks. In Advances in Neural Information Processing Systems, volume 31, pages 8571–8580. Curran Associates, Inc., 2018.
- Jacot et al. (2020) A. Jacot, B. Şimşek, F. Spadaro, C. Hongler, and F. Gabriel. Kernel alignment risk estimator: Risk prediction from training data. In Advances in Neural Information Processing Systems, volume 33, pages 15568–15578, 2020.
- Kawaguchi et al. (2018) K. Kawaguchi, L. P. Kaelbling, and Y. Bengio. Generalization in deep learning. Technical report, Massachusetts Institute of Technology, 2018.
- Kawaguchi et al. (2022) K. Kawaguchi, Z. Deng, K. Luh, and J. Huang. Robustness implies generalization via data-dependent generalization bounds. In Proceedings of the 39th International Conference on Machine Learning, volume 162 of Proceedings of Machine Learning Research, pages 10866–10894. PMLR, 17–23 Jul 2022.
- Kozachkov et al. (2023) L. Kozachkov, P. M. Wensing, and J.-J. E. Slotine. Generalization as dynamical robustness—the role of riemannian contraction in supervised learning. Transactions on Machine Learning Research, 2023.
- Krizhevsky (2009) A. Krizhevsky. Learning multiple layers of features from tiny images. Technical report, University of Toronto, 2009.
- Laurent and von Brecht (2018) T. Laurent and J. von Brecht. Deep linear networks with arbitrary loss: All local minima are global. In Proceedings of the 35th International Conference on Machine Learning, volume 80 of Proceedings of Machine Learning Research, pages 2902–2907. PMLR, 2018.
- LeCun et al. (1998) Y. LeCun, L. Bottou, Y. Bengio, and P. Haffner. Gradient-based learning applied to document recognition. Proceedings of the IEEE, 86(11):2278–2324, 1998.
- Li and Liang (2018) Y. Li and Y. Liang. Learning overparameterized neural networks via stochastic gradient descent on structured data. In Advances in Neural Information Processing Systems, volume 31, pages 8157–8166. Curran Associates, Inc., 2018.
- Liu et al. (2022) F. Liu, H. Yang, S. Hayou, and Q. Li. From optimization dynamics to generalization bounds via lojasiewicz gradient inequality. Transactions on Machine Learning Research, 2022. Accepted; to appear.
- Lohmiller and Slotine (1998) W. Lohmiller and J.-J. E. Slotine. On contraction analysis for non-linear systems. Automatica, 34(6):683–696, 1998. ISSN 0005-1098.
- Lohmiller and Slotine (2000) W. Lohmiller and J.-J. E. Slotine. Nonlinear process control using contraction theory. AIChE Journal, 46(3):588–596, March 2000. doi: 10.1002/aic.690460316.
- Lugosi and Neu (2022) G. Lugosi and G. Neu. Generalization bounds via convex analysis. In Proceedings of the 35th Conference on Learning Theory (COLT), volume 178 of Proceedings of Machine Learning Research, pages 3523–3544. PMLR, 2022.
- Magnus (1954) W. Magnus. On the exponential solution of differential equations. Communications on Pure and Applied Mathematics, 7(4):649–673, 1954. doi: 10.1002/cpa.3160070404.
- Mallinar et al. (2022) N. Mallinar, J. B. Simon, A. Abedsoltan, P. Pandit, M. Belkin, and P. Nakkiran. Benign, tempered, or catastrophic: A taxonomy of overfitting. In Advances in Neural Information Processing Systems, volume 35, pages 29912–29925. Curran Associates, Inc., 2022.
- Mao et al. (2024) J. Mao, I. Griniasty, H. K. Teoh, R. Ramesh, R. Yang, M. K. Transtrum, J. P. Sethna, and P. Chaudhari. The training process of many deep networks explores the same low-dimensional manifold. Proceedings of the National Academy of Sciences, 121(12):e2310002121, 2024. doi: 10.1073/pnas.2310002121.
- Marino and Tomei (1995) R. Marino and P. Tomei. Nonlinear Control Design: Geometric, Adaptive, and Robust. Prentice Hall, London, 1995. ISBN 978-0133426359.
- McAllester (1999) D. A. McAllester. Pac-bayesian model averaging. In Proceedings of the Twelfth Annual Conference on Computational Learning Theory (COLT), pages 164–170. ACM, 1999. doi: 10.1145/307400.307435.
- McDiarmid (1989) C. McDiarmid. On the method of bounded differences. In Surveys in Combinatorics, 1989 (Norwich, 1989), volume 141 of London Mathematical Society Lecture Note Series, pages 148–188. Cambridge University Press, 1989.
- Mei and Montanari (2022) S. Mei and A. Montanari. The generalization error of random features regression: Precise asymptotics and the double descent curve. Communications on Pure and Applied Mathematics, 75(4):667–766, 2022. doi: 10.1002/cpa.22008.
- Mei et al. (2019) S. Mei, T. Misiakiewicz, and A. Montanari. Mean-field theory of two-layers neural networks: dimension-free bounds and kernel limit. In Proceedings of the 32nd Conference on Learning Theory, volume 99 of Proceedings of Machine Learning Research, pages 2388–2464. PMLR, 2019.
- Mou et al. (2018) W. Mou, L. Wang, X. Zhai, and K. Zheng. Generalization bounds of sgld for non-convex learning: Two theoretical viewpoints. In Proceedings of the 31st Conference On Learning Theory, volume 75 of Proceedings of Machine Learning Research, pages 605–638. PMLR, 06–09 Jul 2018.
- Negrea et al. (2019) J. Negrea, M. Haghifam, G. K. Dziugaite, A. Khisti, and D. M. Roy. Information-theoretic generalization bounds for sgld via data-dependent estimates. In Advances in Neural Information Processing Systems, volume 32, 2019.
- Neu et al. (2021) G. Neu, G. K. Dziugaite, M. Haghifam, and D. M. Roy. Information-theoretic generalization bounds for stochastic gradient descent. In Proceedings of the 34th Annual Conference on Learning Theory, volume 134 of Proceedings of Machine Learning Research, pages 3526–3546. PMLR, 2021.
- Neyshabur et al. (2018) B. Neyshabur, S. Bhojanapalli, and N. Srebro. A pac-bayesian approach to spectrally-normalized margin bounds for neural networks. In International Conference on Learning Representations, 2018.
- Rakhlin and Liang (2020) A. Rakhlin and T. Liang. Just interpolate: Kernel ’ridgeless’ regression can generalize. Annals of Statistics, 48(3):1329–1347, 2020. doi: 10.1214/19-AOS1849.
- Ramesh et al. (2024) R. Ramesh, A. Bisulco, R. W. DiTullio, L. Wei, V. Balasubramanian, K. Daniilidis, and P. Chaudhari. Many perception tasks are highly redundant functions of their input data. arXiv preprint arXiv:2407.13841, 2024.
- Richards and Kuzborskij (2021) D. Richards and I. Kuzborskij. Stability & generalisation of gradient descent for shallow neural networks without the neural tangent kernel. In Advances in Neural Information Processing Systems, volume 34, pages 21812–21823, 2021.
- Steinke and Zakynthinou (2020) T. Steinke and L. Zakynthinou. Reasoning about generalization via conditional mutual information. In Proceedings of the 33rd Conference on Learning Theory, volume 125 of Proceedings of Machine Learning Research, pages 3437–3452. PMLR, 2020.
- Tsukamoto et al. (2021) H. Tsukamoto, S.-J. Chung, and J.-J. Slotine. Contraction theory for nonlinear stability analysis and learning-based control: A tutorial overview. Annual Reviews in Control, 52:135–148, October 2021. doi: 10.1016/j.arcontrol.2021.10.001.
- Valiant (1984) L. G. Valiant. A theory of the learnable. Communications of the ACM, 27(11):1134–1142, 1984. doi: 10.1145/1968.1972.
- Wang and Ma (2022) M. Wang and C. Ma. Generalization error bounds for deep neural networks trained by sgd. arXiv preprint arXiv:2206.03299, 2022.
- Xu and Raginsky (2017) A. Xu and M. Raginsky. Information-theoretic analysis of generalization capability of learning algorithms. In Advances in Neural Information Processing Systems, volume 30, pages 2524–2533, 2017.
- Xu and Mannor (2012) H. Xu and S. Mannor. Robustness and generalization. Machine Learning, 86(3):391–423, 2012. doi: 10.1007/s10994-011-5268-1.
- Yang et al. (2022) R. Yang, J. Mao, and P. Chaudhari. Does the data induce capacity control in deep learning? In Proceedings of the 39th International Conference on Machine Learning, volume 162 of Proceedings of Machine Learning Research, pages 25348–25368. PMLR, 2022.
- Zagoruyko and Komodakis (2016) S. Zagoruyko and N. Komodakis. Wide residual networks. In Proceedings of the British Machine Vision Conference (BMVC). BMVA Press, 2016.
Appendix A Proofs and Calculations in Section 3
A.1 Proof of Lemma 3
By the definition of the averaged loss difference ,
Taking the expectation on both sides, we have
By assumption, we have
Therefore,
By the assumption that as , we have that
as . Hence,
The scenarios when the assumptions in Lemma 3 hold
-
•
The expected generalization loss is non-increasing in : This holds for ridgeless linear regression without label noise. When label noise is non-zero, the generalization loss decays monotonically when the number of samples is greater than the number of features. This result also holds for ridge regression when the ridge coefficient decays with , but not too fast, i.e., where is the noise variance and is the true regressor. See Hastie et al. (2022) for reference. Similar results hold for kernel regression and random feature regression-based architectures Mei and Montanari (2022), which are both widely used models in the analysis of neural networks. For consistent estimators, the generalization loss converges to the Bayes risk asymptotically. Although this decrease need not be strictly monotonic. Estimators like Empirical Risk Minimizer (ERM), Structural Risk Minimization (SRM) are consistent under mild assumptions on the hypothesis class, e.g., having finite capacity.
-
•
The expected training loss is non-decreasing: This holds for ridgeless linear regression in general, and therefore for kernel regression and random feature-based models of neural networks. Note that this assumption can be modified slightly to be . This new condition holds for empirical risk minimization (ERM) with bounded loss in general. The resulting left-hand side of the inequality in Lemma 3 gets an additive term of correspondingly. The rest of our calculations stay as they are.
-
•
The expected generalization gap is non-negative: This holds for empirical risk minimization (ERM), in general.
Concentration of to
We first define the notion of stability for deterministic algorithm that maps from space of datasets to weight space, i.e. .
Definition 21.
An algorithm is uniformly -stable if for all datasets , differing in at most one sample, we have
Now we define the set of algorithms that maps dataset to points on the gradient flow trajectory trained on at certain time points.
Lemma 22.
Assume that (1) for all , (2) , is -stable, then for all , with probability ,
-
Proof.
Let denote a modified dataset of by replacing the sample with a different sample . Let , be the corresponding trajectories trained with and (the removed-th sample version of ). Note that . Let and be the averaged loss difference calculated on and respectively. By assumptions (1) and (2), we have
Hence we have
(19)
Remark 23.
In general, the convergence of to can be guaranteed by different versions of algorithm stability (e.g. hypothesis stability, pointwise hypothesis stability and uniform stability (Bousquet and Elisseeff, 2002)). Charles and Papailiopoulos (2018) shows that the algorithm is -uniformly stable if is -Lipchitz in and is -PL (Polyak Lojasiewicz) in , where is a constant depending on and . Other versions of stability can also be guaranteed by PL and QG (quadratic growth) conditions as showed in Charles and Papailiopoulos (2018).
A.2 Proof of Lemma 4
By taking the derivative of the pointwise loss difference , we have,
Hence,
where
and
A.3 Evolution of
The evolution of can be derived through that of .
Here we have,
and
In the calculation above, we use , as an abbreviation for , respectively. Notice that we have the following decomposition of the gradient covariance matrix :
Hence, we have
where represents the covariance matrix of for sampled uniformly from the dataset .
Evolution of :
A modified version of and ,
gives the evolution of ,
A.4 Evolution of
We derive the equation governing the evolution of by calculating its time derivative.
Here the third equality follows from the evolution of :
Note that
A.5 Proof of Lemma 10
We have the following decomposition of the gradient covariance :
where
Hence, we have
where
A.6 Proof of Theorem 13
Now we prove the positive semi-definiteness (PSD) of by showing that is PSD. For any vector , rewrite as , where for all . Then is the trace of covariance of the set of vectors , hence non-negative, which implies that is PSD for all . Hence, the matrix is PSD as an integral of PSD matrices.
-
Proof of Lemma 14.
Let be the largest singular value of the propagator and and be its corresponding left and right singular vectors respectively, i.e.,
where . We first give a bound on through its evolution.
In the second equality, since , we have
The third equality follows from the evolution of the propagator . Note that , which implies that , hence we have
Let , . Then . Hence we have,
For the first term, . By the integrability of , and the dominated convergence theorem (DCT),
Note that the existence of , which is guaranteed by , and the uniform boundedness of , indicates that the limit of the product function being 0 in the second equality. For the second term,
as by condition (1). Hence, as , which shows the existence of in 2-norm of matrix.
∎
Remark 24.
Sometimes the effective Gram matrix calculated from the propagator derived from is not convergent, but in this case, we can create a perturbed version of with controlled smallest eigenvalue of , which guarantees the convergence of while preserving the trajectory of given . For example, in Section 3.5 we construct as a perturbed version of .
A.7 Calculations for the regression example
The gradient for the averaged loss and are
The averaged contraction factor is
The propagator of the evolution is
Hence, the effective metric can be calculated easily as
where , and we have
For , , , hence, for small enough, . Hence, we have , .
Here we also calculate the solution of and although not required in the derivation of the effective gram matrix.
Similarly, we have
where , . We can see that when trained on the dataset , the progress on the direction is slightly less than the other direction, which introduces the non-zero averaged loss difference during training.
A.8 Approximation of the contraction factor
In this section, we analyze the averaged version of the batch-wise contraction factor as introduced in Section B.1. By the fundamental theorem of calculus, we have the following expression of the numerator and denominator of the averaged contraction factor .
where , is the line segment intersecting and .
We approximate , by , approximate , by . We approximate the integral by the value at the point , where , then we have the following approximation of .
Appendix B Experimental Details
Dataset
We use the MNIST and CIFAR10 datasets for experiments in Section 4. We do experiments on 10-classes and 2-classes (we select classes 0,3) problems on both MNIST and CIFAR10 (denoted as MNIST-10, MNIST-2, CIFAR-10, CIFAR-2 respectively), and 5-classes (we select classes 0,1,2,3,4) problem on MNIST (denoted as MNIST0-5). For all experiments, we choose .
Architectures
We use LeNet-5 (a network with two convolutional layers of 20 and 50 channels respectively, both of 5×5 kernel size, and a fully-connected layer with 500 hidden neurons), LeNeT-5-GS (the original LeNeT-5 with an additional gray-scale layer), WRN-4-4 (wide residual network with 4 layers and a widening factor of 4, the batch normalization layers are all replaced with layer normalization layers Ba et al. (2016)) and FC (two layer fully-connected net) for training, We use two layer fully-connected net for synthetic data generation.
Synthetic data generation
We created two types of synthetic datasets: 1) Datasets Syn- is created by modifying the labeling regime of MNIST dataset.
-
•
Approximate the second moment matrix of input by its empirical version calculated by 10000 samples from the original MNIST training set.
-
•
Eigenvalue decomposition of the empirical second moment matrix , where denotes the eigen spectrum sorted from the largest to the smallest.
-
•
Project the input of training set (except for the samples used for calculating empirical second moment matrix) and validation set of MNIST onto . Whiten each pixel of the projection.
-
•
Relabel the original input by a teacher network with random weights applied to the projected input.
2) Datasets Gaussian- is created with Gaussian data with different covariance matrices, labeled by a teacher network with random weights.
-
•
Create covariance matrix with -th eigenvalue being . The eigenvalue decomposition of is .
-
•
Sample the input from the multivariate Gaussian distribution .
-
•
Project the input onto . Whiten each elements of the projection.
-
•
Label the original input by a teacher network with random weights applied to the projected input.
3) Dataset MNIST(random label) is created by randomly assigning labels to the original MNIST inputs, according to a uniform distribution on the ten classes {0,1,2,3,4,5,6,7,8,9}.
B.1 Contraction and perturbation factors for the omitting--samples setting in Section 4
In the omitting -samples setting, by similar calculations as in Appendix A, the batch-wise contraction and perturbation factors are
The averaged contraction and perturbation factors are
where represents the covariance matrix of for sampled uniformly from the dataset . Note that the averaged contraction factor for removed--samples settings are the same for different ’s.
B.2 The analysis of the increment of averaged loss difference .
In this section, we consider the training process starting from time . Different trajectories and are different at time , so the batchwise loss difference and averaged loss difference are nonzero in general. We now consider the increment for . The evolution of is,
where by revising the denominator in Eq. 8 and Eq. 9, we have
The evolution of the residual starting from is
Combining with Lemma 10, we have the following decomposition for the covariance trace,
By similar arguments as in Theorem 13, we have the quadratic form expression for the increment of averaged loss difference ,
where
Let
when the limit exists, then we have
where , and the limit exists. We call the effective Gram matrix of a neural network starting from .
B.3 The approximation of generalization gap
Table S.1 compares the generalization gaps, averaged loss difference and its approximations for a variety of different architectures and datasets. We can see that in almost all cases, these quantities are very close, indicating that the approximation of averaged loss difference represents well of the generalization gap. The small generalization errors provide guarantees for the quality of the used models. The small training loss shows that the models are trained till near interpolation. The second last column shows the estimates of the kernel magnitude. We can see from the last column of the table that when the same datasets are used, even the number of samples are different, the norm of the initial residual are almost the same (eg. last column of row 2-6 in the table for the results of MNIST-5 with different number of samples), which justifies the idea of normalizing the initial residual by , and shows that the normalization makes the effective Gram matrix decomposition of datasets with different samples comparable.
| Architecture | Dataset | # samples | Generalization error | ||||||||
| FC | MNIST-2 | 1100 | 0.018 | 0.018 | 0.021 | 0.051 | 0.053 | 0.028 | 0.034 | 0.595644 | 0.513084 |
| FC | MNIST-5 | 55 | 0.255 | 0.266 | 0.271 | 0.336 | 0.360 | 0.134 | 0.036 | 7.374783 | 0.808355 |
| FC | MNIST-5 | 110 | 0.221 | 0.224 | 0.232 | 0.247 | 0.258 | 0.092 | 0.038 | 6.687616 | 0.820471 |
| FC | MNIST-5 | 550 | 0.127 | 0.128 | 0.142 | 0.095 | 0.101 | 0.040 | 0.038 | 4.664132 | 0.821945 |
| FC | MNIST-5 | 1100 | 0.111 | 0.112 | 0.128 | 0.084 | 0.090 | 0.033 | 0.038 | 4.567158 | 0.823081 |
| FC | MNIST-5 | 2200 | 0.093 | 0.089 | 0.092 | 0.070 | 0.076 | 0.028 | 0.036 | 3.780354 | 0.824114 |
| FC | MNIST-10 | 1100 | 0.469 | 0.472 | 0.476 | 0.448 | 0.462 | 0.134 | 0.036 | 22.119434 | 0.911234 |
| LENET-5 | MNIST-10 | 1100 | 0.241 | 0.243 | 0.228 | 0.203 | 0.221 | 0.075 | 0.048 | 6.582657 | 0.899971 |
| FC | CIFAR-2 | 1100 | 0.346 | 0.446 | 0.342 | 0.420 | 0.433 | 0.154 | 0.037 | 10.059950 | 0.513471 |
| LENET-5-GS | CIFAR-2 | 2200 | 0.461 | 0.438 | 0.461 | 0.495 | 0.553 | 0.140 | 0.042 | 5.696342 | 0.509838 |
| LENET-5 | CIFAR-2 | 1100 | 0.627 | 0.642 | 0.375 | 0.450 | 0.504 | 0.137 | 0.043 | 8.446142 | 0.496051 |
| WRN-4-4 | CIFAR-2 | 1100 | 0.111 | 0.147 | 0.110 | 0.187 | 0.204 | 0.107 | 0.090 | 0.535692 | 0.498821 |
| FC | syn-(1,10) | 1100 | 0.221 | 0.237 | 0.212 | 0.160 | 0.180 | 0.084 | 0.038 | 4.419841 | 0.571913 |
| FC | syn-(11,20) | 1100 | 0.234 | 0.293 | 0.371 | 0.368 | 0.399 | 0.137 | 0.039 | 5.008938 | 0.512861 |
| FC | syn-(21,30) | 1100 | 0.235 | 0.391 | 0.484 | 0.421 | 0.440 | 0.159 | 0.040 | 6.834943 | 0.501674 |
| FC | syn-(31,40) | 1100 | 0.347 | 0.583 | 0.546 | 0.529 | 0.554 | 0.192 | 0.041 | 8.572351 | 0.483528 |
| FC | syn-(41,50) | 1100 | 0.373 | 0.682 | 0.599 | 0.549 | 0.584 | 0.192 | 0.037 | 10.590858 | 0.520236 |
| FC | MNIST(random label) | 55 | 3.265 | 3.789 | 3.276 | 4.831 | 4.770 | 0.902 | 0.041 | 55.534283 | 0.906837 |
| FC | Gaussian-1 | 1100 | 0.062 | 0.057 | 0.053 | 0.063 | 0.068 | 0.039 | 0.038 | 2.711061 | 0.601203 |
| FC | Gaussian-0.5 | 1100 | 0.087 | 0.115 | 0.126 | 0.122 | 0.135 | 0.064 | 0.038 | 4.457899 | 0.569315 |
| FC | Gaussian-0.1 | 1100 | 0.188 | 0.198 | 0.213 | 0.227 | 0.239 | 0.110 | 0.038 | 3.605311 | 0.517485 |
| FC | Gaussian-0.05 | 1100 | 0.251 | 0.259 | 0.257 | 0.280 | 0.295 | 0.124 | 0.035 | 3.497570 | 0.513735 |
| FC | Gaussian-0.01 | 1100 | 0.488 | 0.502 | 0.488 | 0.518 | 0.533 | 0.220 | 0.039 | 3.283361 | 0.518636 |
B.4 Estimation of the propagator
The propagator plays a big role in evolution of the residual in Eq. 13 and the effective kernel in Eq. 18. We next introduce two different ways of approximating .
Product approximation
By a discrete approximation of the evolution of for a small , we have We can derive a discrete approximation of for to be
| (21) |
with the products taken from the right.


Magnus expansion (Magnus, 1954)
We may write the propagator using its Lie algebra as . When does not commute with itself at different times, the Magnus expansion provides a way to write this time-ordered exponential in terms of an infinite series where the first two terms are
| (22) | ||||
where is the commutator of matrices and . Note that if and commute . Magnus expansion can be approximated by numerical integration.
Fig. S.1 shows the approximation results for and when different approximations of are used. We can see from the plot that the Magnus expansion gives good approximation when is small, but the approximations diverge from the true values of and for large . The second order Magnus expansion is even worse than the first order one, this could be result form the overshooting of . The term being highly oscillatory, and the step size being too large can be possible reasons. In comparison, the product approximation performs well till the end of training. Hence, for all experiments in Section 4, we calculate the effective Gram matrix through product approximation.