W HY RESAMPLING OUTPERFORMS REWEIGHTING FOR CORRECTING SAMPLING BIAS WITH STOCHASTIC DESCENTS
Anonymous authors
Paper under double-blind review
A BSTRACT
A data set sampled from a certain population is biased if the subgroups of the population are sampled at proportions that are signiﬁcantly different from their underlying proportions.
Training machine learning models on biased data sets requires correction techniques to compensate for the bias.
We consider two commonlyused techniques, resampling and reweighting, that rebalance the proportions of the subgroups to maintain the desired objective function.
Though statistically equivalent, it has been observed that resampling outperforms reweighting when combined with stochastic gradient algorithms.
By analyzing illustrative examples, we explain the reason behind this phenomenon using tools from dynamical stability and stochastic asymptotics.
We also present experiments from regression, classiﬁcation, and off-policy prediction to demonstrate that this is a general phenomenon.
We argue that it is imperative to consider the objective function design and the optimization algorithm together while addressing the sampling bias.
I NTRODUCTION
A data set sampled from a certain population is called biased if the subgroups of the population are sampled at proportions that are signiﬁcantly different from their underlying population proportions.
Applying machine learning algorithms naively to biased training data can raise serious concerns and lead to controversial results (Sweeney, 2013; Kay et al., 2015; Menon et al., 2020).
In many domains such as demographic surveys, fraud detection, identiﬁcation of rare diseases, and natural disasters prediction, a model trained from biased data tends to favor oversampled subgroups by achieving high accuracy there while sacriﬁcing the performance on undersampled subgroups.
Although one can improve by diversifying and balancing during the data collection process, it is often hard or impossible to eliminate the sampling bias due to historical and operational issues.
In order to mitigate the biases and discriminations against the undersampled subgroups, a common technique is to preprocess the data set by compensating the mismatch between population proportion and the sampling proportion .
Among various approaches, two commonly-used choices are reweighting and resampling .
In reweighting, one multiplies each sample with a ratio equal to its population proportion over its sampling proportion.
In resampling, on the other hand, one corrects the proportion mismatch by either generating new samples for the undersampled subgroups or selecting a subset of samples for the oversampled subgroups.
Both methods result in statistically equivalent models in terms of the loss function (see details in Section 2).
However, it has been observed in practice that resampling often outperforms reweighting signiﬁcantly, such as boosting algorithms in classiﬁcation (Galar et al., 2011; Seiffert et al., 2008), off-policy prediction in reinforcement learning (Schlegel et al., 2019) and so on.
The obvious question is why.
Main contributions.
Our main contribution is to provide an answer to this question: resampling outperforms reweighting because of the stochastic gradient-type algorithms used for training.
To the best of our knowledge, our explanation is the ﬁrst theoretical quantitative analysis for this phenomenon.
With stochastic gradient descent (SGD) being the dominant method for model training, our analysis is based on some recent developments for understanding SGD.
We show via simple and explicitly analyzable examples why resampling generates expected results while reweighting per- forms undesirably.
Our theoretical analysis is based on two points of view, one from the dynamical stability perspective and the other from stochastic asymptotics.
In addition to the theoretical analysis, we present experimental examples from three distinct categories (classiﬁcation, regression, and off-policy prediction) to demonstrate that resampling outperforms reweighting in practice.
This empirical study illustrates that this is a quite general phenomenon when models are trained using stochastic gradient type algorithms.
Our theoretical analysis and experiments show clearly that adjusting only the loss functions is not sufﬁcient for ﬁxing the biased data problem.
The output can be disastrous if one overlooks the optimization algorithm used in the training.
In fact, recent understanding has shown that objective function design and optimization algorithm are closely related, for example optimization algorithms such as SGD play a key role in the generalizability of deep neural networks.
Therefore in order to address the biased data issue, we advocate for considering data, model, and optimization as an integrated system.
Related work.
In a broader scope, resampling and reweighting can be considered as instances of preprocessing the training data to tackle biases of machine learning algorithms.
Though there are many well-developed resampling (Mani & Zhang, 2003; He & Garcia, 2009; Maciejewski &
Stefanowski, 2011) and reweighting (Kumar et al., 2010; Malisiewicz et al., 2011; Chang et al., 2017) techniques, we only focus on the reweighting approaches that do not change the optimization problem.
It has been well-known that training algorithms using disparate data can lead to algorithmic discrimination (Bolukbasi et al., 2016; Caliskan et al., 2017), and over the years there have been growing efforts to mitigate such biases, for example see (Amini et al., 2019; Kamiran & Calders, 2012; Calmon et al., 2017;
Zhao et al., 2019; L ´ opez et al., 2013).
We also refer to (Haixiang et al., 2017;
He & Ma, 2013; Krawczyk, 2016) for a comprehensive review of this growing research ﬁeld.
Our approaches for understanding the dynamics of resampling and reweighting under SGD are based on tools from numerical analysis for stochastic systems.
Connections between numerical analysis and stochastic algorithms have been rapidly developing in recent years.
The dynamical stability perspective has been used in (Wu et al., 2018) to show the impact of learning rate and batch size in minima selection.
The stochastic differential equations (SDE) approach for approximating stochastic optimization methods can be traced in the line of work (Li et al., 2017; 2019; Rotskoff & VandenEijnden, 2018; Shi et al., 2019), just to mention a few.
P ROBLEM SETUP
Let us consider a population that is comprised of two different groups, where a proportion a 1 of the population belongs to the ﬁrst group, and the rest with the proportion a 2 = 1 − a 1 belongs to the second (i.e., a 1 , a 2 > 0 and a 1 + a 2 = 1 ).
In what follows, we shall call a 1 and a 2 the population proportions .
Consider an optimization problem for this population over a parameter θ .
For simplicity, we assume that each individual from the ﬁrst group experiences a loss function
V 1 ( θ ) , while each individual from the second group has a loss function of type V 2 ( θ ) .
Here the loss function V 1 ( θ ) is assumed to be identical across all members of the ﬁrst group and the same for
V 2 ( θ ) across the second group, however it is possible to extend the formulation to allow for loss function variation within each group.
Based on this setup, a minimization problem over the whole population is to ﬁnd
[Equation]
For a given set Ω of N individuals sampled uniformly from the population, the empirical minimization problem is
[Equation]
where i r ∈ { 1 , 2 } denotes which group an individual r belongs to.
When N grows, the empirical loss in (2) is consistent with the population loss in (1) as there are approximately a 1 fraction of samples from the ﬁrst group and a 2 fraction of samples from the second.
However, the sampling can be far from uniformly random in reality.
Let n 1 and n 2 with n 1 + n 2 = N denote the number of samples from the ﬁrst and the second group, respectively.
It is convenient to deﬁne f
i , i = 1 , 2 as the sampling proportions for each group, i.e., f 1 = n 1 /N and f 2 = n 2 /N with f 1 + f 2 = 1 .
The data set is biased when the sampling proportions f 1 and f 2 are different from the population proportions a 1 and a 2 .
In such a case, the empirical loss is f 1 V 1 ( θ ) + f 2 V 2 ( θ ) , which is clearly wrong when compared with (1).
Let us consider two basic strategies to adjust the model: reweighting and resampling.
In reweighting, one assigns to each sample r ∈ Ω a weight a i r /f
i r and the reweighting loss function is
[Equation]
In resampling, one either adds samples to the minority group (i.e., oversampling) or removing samples from the majority group (i.e., undersampling).
Although the actual implementation of oversampling and undersampling could be quite sophisticated in order to avoid overﬁtting or loss of information, mathematically we interpret the resampling as constructing a new set of samples of size M , among which a 1 M samples are of the ﬁrst group and a 2 M samples of the second.
The resampling loss function is
[Equation]
Notice that both V w ( θ ) and V s ( θ ) are consistent with the population loss function V ( θ ) .
This means that, under mild conditions on V 1 ( θ ) and V 2 ( θ ) , a deterministic gradient descent algorithm from a generic initial condition converges to similar solutions for V w ( θ ) and V s ( θ ) .
For a stochastic gradient descent algorithm, the expectations of the stochastic gradients of V w ( θ ) and V s ( θ ) also agree at any θ value.
However, as we shall explain below, the training behavior can be drastically different for a stochastic gradient algorithm.
The key reason is that the variances experienced for V w ( θ ) and V s ( θ ) can be drastically different: computing the variances of gradients for resampling and reweighting reveals that
[Equation]
These formulas indicate that, when f 1 /f 2 is signiﬁcantly misaligned with a 1 /a 2 , the variance of reweighting can be much larger.
Without knowing the optimal learning rates a priori, it is difﬁcult to select an efﬁcient learning rate for reliable and stable performance for stiff problems, when only reweighting is used.
In comparison, resampling is more favorable especially when the choice of learning rates is restrictive.
S TABILITY ANALYSIS
Let us use a simple example to illustrate why resampling outperforms reweighting under SGD, from the viewpoint of stability.
Consider two loss functions V 1 and V 2 with disjoint supports,
[Equation]
each of which is quadratic on its support.
The population loss function is V ( θ ) =
a 1 V 1 ( θ )+ a 2 V 2 ( θ ) , with two local minima at θ = − 1 and θ = 1 .
The gradients for V 1 and V 2 are
[Equation]
Suppose that the population proportions satisfy a 2 > a 1 , then θ = 1 is the global minimizer and it is desired that SGD should be stable near it.
However, as shown in Figure 1, when the sampling proportion f 2 is signiﬁcantly less than the population proportion a 2 , for reweighting θ = 1 can easily become unstable: even if one starts near the global minimizer θ = 1 , the trajectories for reweighting always gear towards θ = − 1 after a few steps (see Figure 1(1)).
On the other hand, for resampling θ = 1 is quite stable (see Figure 1(2)).
V ( ) - - -    3 -0.
V ( )
[Figure]
Hence resampling is more reliable than reweighting.
We include more comparisons with various learning rates in Appendix D to show that resampling is stable for a wider range of η . The expectations of the stochastic gradient are the same for both methods. It is the difference in the second moment that explains why trajectories near the two minima exhibit different behaviors. Our explanation is based on the stability analysis framework used in (Wu et al., 2018).
By deﬁnition, a stationary point θ ∗ is stochastically stable if there exists a uniform constant 0 < C ≤ 1 such that E [ (cid:107) θ k − θ ∗ (cid:107) 2 ] ≤ C (cid:107) θ 0 − θ ∗ (cid:107) 2 , where θ k is the k -th iterate of SGD.
The stability conditions for resampling and reweighting are stated in the following two lemmas, in which we use η to denote the learning rate.
Lemma 1.
For resampling, the conditions for the SGD to be stochastically stable around θ =
−and θ
= 1 are respectively
[Equation]
Lemma 2.
For reweighting, the condition for the SGD to be stochastically stable around θ =
−and θ
= 1 are respectively
[Equation]
Note that the stability conditions for resampling are independent of the sampling proportions ( f 1 , f 2 ) , while the ones for reweighting clearly depend on ( f 1 , f 2 ) .
We defer the detailed computations to Appendix A.
Lemma 2 shows that reweighting can incur a more stringent stability criterion.
Let us consider the case a 1 = 12 − (cid:15), a 2 = 12 + (cid:15) with a small constant (cid:15) > 0 and f 2 /f 1 (cid:28) 1 .
For reweighting, the global minimum θ = 1 is stochastically stable only if η (1 + f 1 /f 2 ) ≤ 4 + O ( (cid:15) ) .
This condition becomes rather stringent in terms of the learning rate η since f 1 /f
(cid:29) 1 .
On the other hand, the local minimizer θ = − 1 is stable if η (1 + f 2 /f 1 ) ≤ 4 + O ( (cid:15) ) , which could be satisﬁed for a broader range of η because f 2 /f 1 (cid:28) 1 .
In other words, for a ﬁxed learning rate η , when the ratio f 2 /fbetween the sampling proportions is sufﬁciently small, the desired minimizer θ = 1 is no longer statistically stable with respect to SGD.
SDE ANALYSIS
The stability analysis can only be carried for a learning rate η of a ﬁnite size.
However, even for a small learning rate η , one can show that the reweighting method is still unreliable from a different perspective.
This section applies stochastic differential equation analysis to demonstrate it.
Let us again use a simple example to illustrate the main idea.
Consider the following two loss functions,
[Equation]
with 0 < (cid:15) (cid:28) 1 .
The population loss function is V ( θ ) =
a 1 V 1 ( θ ) + a 2 V 2 ( θ ) with local minimizers θ = − 1 and θ = 1 .
Note that the O ( (cid:15) ) terms are necessary.
Without it, if the SGD starts in ( −∞ , 0) , all iterates will stay in this region because there is no drift from V 2 ( θ ) .
Similarly, if the SGD starts in (0 , ∞ ) , no iterates will move to ( −∞ , 0) .
That means the result of SGD only depends on the initialization when O ( (cid:15) ) term is absent.
In Figure 2, we present numerical simulations of the resampling and reweighting methods for the designed loss function V ( θ ) .
If a 2 > a 1 , then the global minimizer of V ( θ ) is θ = 1 (see the Figure 2(1)).
Consider a setup with population proportions a 1 /a 2 = 0 .
6 along sampling proportions f 1 /f 2 = 0 .
9 / 0 . 1 , which are quite different.
Figures 2(2) and (3) show the dynamics under the reweighting and resampling methods, respectively.
The plots show that, while the trajectory for resampling is stable across all the time, the trajectory for reweighting quickly escapes to the (nonglobal) local minimizer θ = − 1 even when it starts near the global minimizer θ = 1 .
V ( )
[Figure]
When the learning rate is sufﬁciently small, one can approximate the SGD by an SDE, which in this piece-wise linear loss example is approximately a Langevin dynamics with a piecewise constant mobility.
In particular when the dynamics reaches equilibrium, the stationary distribution of the stochastic process is approximated by a Gibbs distribution, which gives the probability densities at the stationary points.
Let us denote p s ( θ ) and p w ( θ ) as the stationary distribution over θ under resampling and reweighting, respectively.
Suppose that a 2 > a 1 and hence V (1) < V ( − 1) .
The following lemmas quantitatively summarize the results.
Lemma 3.
When a 2 > a 1 , V (1) <
V ( − 1) .
The stationary distribution for resampling satisﬁes the relationship
[Equation]
Lemma 4.
With a 2 > a 1 , V (1) <
V ( − 1) < 0 .
Under the condition f 2 f 1 ≤ a 2 a
[Equation]
V
[Equation]
) for the sampling proportions, the stationary distribution for reweighting satisﬁes the relationship
[Equation]
The proofs of the above two lemmas can be found in Appendix B. Lemma 3 shows that for resampling it is always more likely to ﬁnd θ at the global minimizer 1 than at the local minimizer
− 1 .
Lemma 4 states that for reweighting it is more likely to ﬁnd θ at the local minimizer − 1 when f 2 f 1 ≤ a 2 a 1 (cid:113) V ( − 1) V (1) .
Together, they explain the phenomenon shown in Figure 2.
To better understand the condition in Lemma 4, let us consider the case a 1 = 12 − (cid:15), a 2 = 12 + (cid:15) with a small constant (cid:15) > 0 .
Under this setup, V ( − 1) /V
(1) ≈ 1 .
Whenever the ratio of the sampling proportions f 2 /f 1 is signiﬁcantly less than the ratio of the population proportions a 2 /a 1 ≈ 1 , reweighting will lead to the undesired behavior.
The smaller the ratio f 2 /f 1 is, the less likely the global minimizer will be visited.
Remark 1 .
The reason for constructing this piecewise linear loss function is to obtain an approximately explicitly solvable SDE with a constant coefﬁcient for the noise.
For general one dimensional problems, we can leverage Lamperti transform to map a generic noise term to a constant one, see for example (Pavliotis, 2014).
However, such a transformation may change the properties of the corresponding potential function, and one should be cautious that the usual stationary distribution analysis may not be informative anymore.
In higher dimensions, it is in general technically difﬁcult to analyze with the stationary distribution theory without a constant diffusion coefﬁcient.
Remark 2 .
Lemmas 3 and 4 can be further extended to more general cases in 1D. When V ( θ ) is piecewise strictly convex function with two local minima (Lemmas 7 and 8) or V ( θ ) has ﬁnite number of local minima (Lemmas 9 and 10), under certain conditions, resampling always has a higher stationary probability at the global minimum, while reweighting does the opposite if the sampling proportion is signiﬁcantly different from the population proportion.
We refer to Appendix
B.3 for more details of these extensions.
Multi-dimensional results.
Let us now consider the minimization of V ( θ )
= a 1 V 1 ( θ ) + a 2 V 2 ( θ ) for more general V 1 , V 2 and also θ in high dimensions.
It is in fact not clear how to extend the above stochastic analysis to more general functions V ( θ ) .
Instead we focus on the transition time from one stationary point to another in order to understand the behavior of resampling and reweighting.
For this purpose, we again resort to the SDE approximation of the SGD in the continuous time limit.
Such a SDE approximation, ﬁrst introduced in (Li et al., 2017), involves a data-dependent covariance coefﬁcient for the diffusion term and is justiﬁed in the weak sense with an error of order O ( √ η ) .
More speciﬁcally, the dynamics can be approximated by
[Equation]
where Θ( t = kη )
≈ θ k for the step k parameter θ k , η is the learning rate, and Σ(Θ) is the covariance of the stochastic gradient at location Θ .
In the SDE theory, the drift term ∇ V ( · ) is usually assumed to be Lipschitz.
However, in machine learning (for example neural network training with non-smooth activation functions), it is common to encounter non-Lipschitz gradients of loss functions (as in the example presented in Section 3).
To ﬁll this gap, we provide in Appendix C a justiﬁcation of
SDE approximation for the drift with jump discontinuities, based on the proof presented in (M ¨ ullerGronbach et al., 2020).
The following two lemmas summarize the transition times between the two local minimizers.
Lemma 5.
Assume that there are only two local minimizers θ ∗ 1 , θ ∗ 2 for the objective function V ( θ ) .
Let τ θ ∗ 1 → θ ∗ 2 be the transition time for Θ( t ) in (7) from the (cid:15) -neighborhood of θ ∗ 1 (a closed ball of radius (cid:15) centered at θ ∗ 1 ) to the (cid:15) -neighborhood of θ ∗ 2 and τ θ ∗ 2 → θ ∗ 1 be the transition time in the opposite direction.
Then
[Equation]
Here det( ∇ 2 L ( θ ∗ 1 )) and det( ∇ 2 L ( θ ∗ 2 )) are the determinants of the Hessians at θ ∗ 1 and θ ∗ 2 , respectively.
δV ( θ ∗ k ) ≡ V ( θ ◦ ) − V ( θ ∗ k ) for k = 1 , 2 where θ ◦ is the saddle point between θ ∗ 1 , θ ∗ 2 .
This lemma is known in the diffusion process literature as the Eyring-Kramers formula; see, e.g., (Berglund, 2011;
Bovier et al., 2004; 2005).
Using the above lemma, we obtain the following result for the transition times for resampling and reweighting.
Lemma 6.
Assume that there are only two local minimizers θ ∗ 1 , θ ∗ 2 for the objective function V ( θ ) .
Also assume that the loss function V 1 ( · ) for the ﬁrst group is O ( (cid:15) ) in the (cid:15) -neighborhood of θ ∗and the loss function V 2 ( · ) for the second group is O ( (cid:15) ) in the (cid:15) -neighborhood of θ ∗ 1 .
In addition, assume that the determinants of the Hessian at two local minimizers are the same.
Then the ratio of the transition times between the two local minimizers for resampling is
[Equation]
and the ratio for reweighting is
[Equation]
See Appendix B for the proof.
When the ratio is larger than 1 , it means that θ ∗ 1 is more stable than θ ∗ 2 .
This result shows that for reweighting the relative stability of the two minimizers highly depends on the sampling proportions ( f 1 , f 2 ) .
On the other hand, for resampling it is independent of ( f 1 , f 2 ) , which is precisely the desired result for a bias correction procedure.
To see how the sampling proportions affect the behavior of reweighting, let us consider a simple case where θ ∗ 1 is the global minimizer, ∇ V 1 ( θ ∗ 1 ) ∇ V 1 ( θ ∗ 1 ) (cid:62) =
∇ V 2 ( θ ∗ 2 ) ∇ V 2 ( θ ∗ 2 ) (cid:62) , a 1 = 12 + (cid:15), a 2 = 12 − (cid:15) , and f 1 (cid:28) f 2 .
This ensures that δV ( θ ∗ 1 ) > δV ( θ ∗ 2 ) and the above ratio for resampling is larger than 1 , which is the desired result.
However, f 1 (cid:28) f 2 implies that f 1 a 21 (cid:28) 1 , f 2 a 22 (cid:29) 1 , and the above ratio for reweighting is much smaller than 1 , which means that the local minimizer θ ∗ 2 is more stable than the global minimizer θ ∗ 1 .
E XPERIMENTS
This section examines the empirical performance of resampling and reweighting for problems from classiﬁcation, regression, and reinforcement learning.
As mentioned in the previous sections, the noise of stochastic gradient algorithms makes optimal learning rate selections much more restrictive for reweighting, when the data sampling is highly biased.
In order to achieve good learning efﬁciency and reasonable performance in a neural network training, adaptive stochastic gradient methods such as Adam (Kingma & Ba, 2014) are applied in the ﬁrst two experiments.
We observe that resampling consistently outperforms reweighting with various sampling ratios when combined with these adaptive learning methods.
Classiﬁcation.
This experiment uses the Porto Seguro’s safe driver prediction data set 2 to predict the probability of a driver to ﬁle a claim.
One issue of the provided training data set after preprocessing is that the data distribution under the column “target”, which indicates whether a claim is ﬁled, is already highly skewed: the ratio of unﬁled claims and ﬁled claims is a 1 /a 2 = 26 .
Assuming this as the underlying population distribution since ﬁling a claim can be considered as a rare event, we create biased data sets with different sampling proportions f 1 /f 2 (see Figure 3) by extracting samples uniformly randomly.
The code from the imbalanced-learn package 3 is adapted to compare the performance between resampling (including both oversampling and undersampling methods) and reweighting.
We apply a 10-fold cross validation to the training data set, and we train and evaluate the performance on this stratiﬁed 10-fold training data set using StratiﬁedKFold in sklearn 4 .
For each training subset, we setup a 5-layer neural network with the binary cross-entropy loss function and train with the default
Adam optimizer.
The training takes 20 epochs with the batch-size equal to 1000.
As we discussed in Section 2, the resampling methods adjust sample size to make the population proportions close to a 1 /a 2 , and reweighting multiplies each sample by a i /f i along with a normalizing factor.
We observe that the training loss for resampling is consistently lower than the one for reweighting, which is consistent with the theoretical analysis.
For example in the case f 1 /f 2 = 1 / 5 .
8 , the averaged training losses are 0 .
72 and 1 . 9 for resampling and reweighting, respectively.
To estimate the performance, rather than using the classiﬁcation accuracy that can be misleading for biased data, we use the metric that computes the area under the receiver operating characteristic curve (ROCAUC) from the prediction scores.
The ROC curves plots the true positive rate on the y -axis versus the false positive rate on the x -axis.
As a result, a larger area under the curve indicates a better performance of a classiﬁer.
As shown in Figure 3, resampling outperforms reweighting in terms of the ROC-AUC scores for different sampling proportions f 1 /f 2 .
[Figure]
Nonlinear Regression.
This experiment uses the California Housing Prices data set 5 to predict the median house values.
The target median house values, ranging from 15 k to 500 k, are distributed quite non-uniformly.
We select subgroups with median house values > 400 k ( 1726 in total) and < 200 k
( 11767 in total)
and combine them to make our dataset.
In the pre-processing step, we drop the “ocean proximity” feature and randomly set 30% of the data to be the test data.
The remaining training data set with 8 features is fed into a 3-layer neural network.
The population proportion of two subgroups is assumed to be a 1 /a
≈ 1 , while resampling and reweighting are tested with various sampling ratios f 1 /f 2 near 11767 / 1726 .
Their performance of is compared also with the baseline (i.e. trained without using either resampling or reweighting).
In each test, the mean squared error (MSE) is chosen as the loss function and Adam is used as the optimizer in the model.
The batch-size is 32 and the number of epochs is 400 for each case.
As shown in Table 1, resampling signiﬁcantly outperforms reweighting for all sampling ratios in terms of a lower averaged MSE, and its good stability is reﬂected in its lowest standard deviation for multiple runs.
[Table]
Off-policy prediction.
In the off-policy prediction problem in reinforcement learning, the objective is to ﬁnd the value function of policy π using the trajectory { ( a t , s t , s t +1 ) }
Tt =1 generated by a behavior policy µ .
To achieve this, the standard approach is to update the value function based on the behavior policy’s temporal difference (TD) error δ ( s t ) =
R ( s t ) + γV ( s t +1 )
− V ( s t ) with an importance weight E
π
[ δ | s t = s ] = (cid:80)
a ∈
A π ( a | s ) µ ( a | s ) E [ δ | s t = s, a t = a ] µ ( a | s ) , where the summation is taken over the action space A .
The resulting reweighting TD learning for policy π is
[Equation]
where η is the learning rate.
This update rule is an example of reweighting.
On the other hand, the expected TD error can also be written in the resampling form, E π [ δ | s t = s ] = (cid:80)
a ∈ A E [ δ | s t = s, a t = a ] π ( a | s )
= (cid:80) a ∈ A (cid:80) π ( a | s ) N j =
E [ δ j | s t = s, a t = a ] , where N is the total number of samples for s t = s .
This results to a resampling TD learning algorithm:
at step t ,
[Equation]
where ( a k , s k , s k +1 ) is randomly chosen from the data set { ( a j , s j , s j +1 ) } s j = s t with probability π ( a k | s t ) .
Consider a simple example with discrete state space S
= { i } n − 1 i =0 , action space
A = {± 1 } , discount factor γ = 0 .
9 and transition dynamics s t +1 =
mod ( s t + a t , n ) , where the operator mod ( m, n ) gives the remainder of m divided by n .
Figure 4 shows the results of the off-policy TD learning by these two approaches, with the choice of n = 32 and r ( s )
= 1 + sin(2 πs/n ) and learning rate η = 0 .
The target policy is π ( a i | s )
= 12 while the behavior policy is µ ( a i | s )
=
12 + ca i .
The difference between the two policies becomes larger as the constant c ∈ [0 , 1 / 2] increases.
From the previous analysis, if one group has much fewer samples as it should have, then the minimizer of the reweighting method is highly affected by the sampling bias.
This is veriﬁed in the plots: as c becomes larger, the performance of reweighting deteriorates, while resampling is rather stable and almost experiences no difference with the on-policy prediction in this example
[Figure]
D ISCUSSIONS
This paper examines the different behaviors of reweighting and resampling for training on biasedly sampled data with the stochastic gradient descent.
From both the dynamical stability and stochastic asymptotics viewpoints, we explain why resampling is numerically more stable and robust than reweighting.
Based on this theoretical understanding, we advocate for considering data, model and optimization as an integrated system, while addressing the bias.
An immediate direction for future work is to apply the analysis to more sophisticated stochastic training algorithms and understand their impact on resampling and reweighting.
Another direction is to extend our analysis to unsupervised learning problems.
For example, in the principal component analysis one computes the dominant eigenvectors of the covariance matrix of a data set.
When the data set consists of multiple subgroups sampled with biases and a stochastic algorithm is applied to compute the eigenvectors, then an interesting question is how resampling or reweighting would affect the result.
A P ROOFS IN SECTIONA. P ROOF OF L EMMA
Proof.
In resampling, near θ = − 1 the gradient is θ + 1 with probability a 1 and 0 with probability a 2 .
Let us denote the random gradient at each step by W ( θ + 1) , where W is a Bernoulli random variable with mean E ( W )
=
a 1 and variance V ( W ) =
a 1 a 2 .
At the learning rate η , the iteration can be written as
[Equation]
The ﬁrst and second moments of the iterates are
[Equation]
According to the deﬁnition of the stochastic stability, SGD is stable around θ = − 1 if the multiplicative factor of the second equation is bounded by 1 , i.e.
[Equation]
Consider now the stability around θ = 1 , the iteration can be written as
[Equation]
where W is again a Bernoulli random variable with E ( W )
= a 2 and V ( W ) =
a 1 a 2 .
The same computation shows that the second moment follows
[Equation]
Therefore, the condition for the SGD to be stable around θ = 1 is
[Equation]
A. P ROOF OF L EMMA
Proof.
In reweighting, near θ = − 1 the gradient is a 1 f 1 ( θ + 1) with probability f 1 and 0 with probability f 2 .
Let us denote the random gradient at each step by W ( θ + 1) , where W is a Bernoulli random variable with E ( W )
=
a 1 and V ( W ) =
f 1 f 2 (cid:16) a 1 f 1 (cid:17) 2 .
At the learning rate η , the iteration can be written as
[Equation]
[Equation]
Hence the second moments of the iterates are given by
[Equation]
Therefore, the condition for the SGD to be stable around θ = − 1 is
[Equation]
Consider now the stability around θ = 1 , the gradient is 0 with probability f 1 and a 2 f 2 ( θ − 1) with probability f 2 .
An analysis similar to the case θ = − 1 shows that the condition for the SGD to be stable around θ = 1 is
[Equation]
B P ROOFS IN SECTIONB. P ROOF OF L EMMA
Proof.
In resampling, with probability a 1 the gradients over the four intervals ( −∞ , − 1) , ( − 1 , 0) , (0 , 1) , and (1 , ∞ ) are − 1 , 1 , (cid:15) , and (cid:15) .
With probability a 2 , they are − (cid:15) , − (cid:15) , − 1 , and 1 across these four intervals.
The variances of the gradients are a 1 a 2 (1 − (cid:15) ) 2 , a 1 a 2 (1 + (cid:15) ) 2 , a 1 a 2 (1 + (cid:15) ) 2 , a 1 a 2 (1 − (cid:15) ) 2 , respectively, across the same intervals.
Since (cid:15) (cid:28) 1 , the variance can be written as a 1 a 2 + O ( (cid:15) ) across all intervals.
Then the SGD dynamics with learning rate η can be approximated by
[Equation]
where W ∼ N (0 , 1) is a normal random variable.
When η is small, one can approximate the dynamics by a stochastic differential equation of form
[Equation]
by identifying θ k ≈ Θ( t = kη ) (see Appendix C for details).
The stationary distribution of this stochastic process is
[Equation]
where Z is a normalization constant.
Plugging in θ = − 1 , 1 results in p s (1)
[Equation]
Under the assumption that (cid:15) (cid:28) 1 , the last term is negligible.
When a 2 > a 1 , V ( θ ) is minimized at θ = 1 , which implies − ( V (1) − V ( − 1)) > 0 .
Hence, this ratio is larger than 1.
B. P ROOF OF L EMMA
Proof.
In reweighting, with probability f 1 the gradients are − a 1 f 1 , a 1 f 1 , a 1 f 1 (cid:15) , and a 1 f 1 (cid:15) over the four intervals ( −∞ , − 1) , ( − 1 , 0) , (0 , 1) , and (1 , ∞ ) , respectively.
With probability f 2 , they are − a 2 f 2 (cid:15) , − a 2 f 2 (cid:15) , − a 2 f 2 , and a 2 f 2 .
The variances of the gradients are f 1 f 2 ( a 1 f 1 − a 2 f 2 (cid:15) ) 2 , f 1 f 2 ( a 1 f 1 + a 2 f 2 (cid:15) ) 2 , f 1 f 2 ( a 1 f 1 (cid:15) + a 2 f 2 ) 2 , and f 1 f 2 ( a 1 f 1 (cid:15) − a 2 f 2 ) 2 , respectively, across the same intervals.
Since (cid:15) (cid:28) 1 , the variance can be written as f 1 f 2 a 21 f 21 + O ( (cid:15) ) for θ < 0 and f 1 f 2 a 22 f 22 + O ( (cid:15) ) for θ > 0 .
With θ k ≈ Θ( kη ) , the approximate SDE for θ < 0 is given by
[Equation]
while the one for θ > 0 is
[Equation]
(see Appendix C for the SDE derivations).
The stationary distributions for θ < 0 and θ > 0 are, respectively,
[Equation]
Plugging in θ = − 1 , 1 results in p
[Equation]
The next step is to ﬁgure out the relationship between Z 1 and Z 2 .
Consider an SDE with non-smooth diffusion d Θ = − V (cid:48)
(Θ) dt + σdB .
The Kolmogorov equation for the stationary distribution is
[Equation]
This suggests that σ 2 p is continuous at the discontinuity θ = 0 .
In our setting, since V (0) = 0 , this simpliﬁes to
[Equation]
This simpliﬁes to
[Equation]
Inserting this into (11) results in p w (1)
[Equation]
By the assumption [Equation] 1) V (1) and V (1) <
V ( − 1) < 0 , one has (cid:16) a 1 a 2 (cid:17) 2 (cid:16) f 2 f 1 (cid:17) 2 ≤ V ( − 1) V (1) <and − f 2 /f 1 a 22 V (1) ≤ − f 1 /f 2 a 21 V ( − 1) .
Hence the above ratio is less than 1 .
B. E XTENDED RESULTS FOR 1 - DIMENSION
Consider the population loss function V ( θ )
= a 1 V 1 ( θ ) + a 2 V 2 ( θ ) with,
[Equation]
where h 1 , h 2 are strictly convex functions and continuously differentiable.
We assume V ( θ ) has two local minimizers θ 1 < 0 , θ 2 > 0 and the values are negative at local minima.
Therefore, when a 2 > a 1 , θ 2 should be the global minimizer.
In addition, we assume that the geometries of h 1 , hat two local minimizers are similar, i.e., h 1 ( θ 1 ) =
h 2 ( θ 2 ) , h (cid:48) 1 ( θ 1 ) = h (cid:48) 2 ( θ 2 ) ; if we set g i ( θ ) to be the anti-derivative of 1 /h (cid:48)
i ( θ ) , then g 1 ( θ 1 ) =
g 2 ( θ 2 ) .
Moreover, we assume that the two disjoint convex functions are smooth at the disjoint point, i.e., h (cid:48) 1 (0)
=
h (cid:48) 2 (0) and g 1 (0) =
g 2 (0) .
The following two lemmas extend Lemmas 3 and 4 to piecewise strictly convex function based on the above assumptions.
Lemma 7.
When a 2 > a 1 , V ( θ 2 ) <
V ( θ 1 ) .
The stationary distribution for resampling satisﬁes the relationship
[Equation]
Proof.
In resampling, with probability a 1 the gradients in the two intervals ( −∞ , 0) , (0 , ∞ ) are h (cid:48) 1 ( θ ) , (cid:15) respectively; with probability a 2 the gradients are − (cid:15), h (cid:48)
2 ( θ ) respectively.
Therefore, the expectation of the gradients µ ( θ ) is a 1 h (cid:48) 1 ( θ ) + O ( (cid:15) ) in ( −∞ , 0) and a 2 h (cid:48)
2 ( θ )
+ O ( (cid:15) ) in (0 , ∞ ) .
The variance of the gradients σ ( θ ) is a 1 a 2 h
[Equation]
[Equation]
[Equation] + O ( [Equation] ) in ( −∞ , 0) and a 1 a 2 h (cid:48) 2 ( θ ) 2 + O ( (cid:15) ) in (0 , ∞ ) .
The p.d.f p s ( t, θ ) satisﬁes
[Equation]
therefore, the stationary distribution p s ( θ ) satisﬁes
[Equation]
or equivalently,
[Equation]
which implies p s ( θ ) = 1 Z e − F ( θ ) with normalization constant Z = (cid:82) ∞
−∞ e − F ( θ ) , where
[Equation]
By inserting µ [Equation] σ in different intervals
[Equation]
one has
[Equation] Hence [Equation] the ratio of the stationary probabiliy at two local minimizers θ 1 < 0 , θ 2 > 0 is
[Equation]
(cid:19)(cid:19) + O ( (cid:15) ) , where g i ( θ ) = (cid:82) 1 h (cid:48)
i dθ, i = 1 , 2 .
By the assumption that g 1 ( θ 1 ) =
g 2 ( θ 2 ) and h (cid:48) 1 ( θ 1 )
=
h (cid:48) 2 ( θ 2 ) , g 1 (0) =
g 2 (0) and h (cid:48) 1 (0)
=
h (cid:48) 2 (0) one has,
[Equation]
Since a 2 > a 1 > 0 , 1 a 2 − 1 a 1 < 0 .
Because of the strictly convexity of h 1 , h (cid:48) 1 ( θ ) > 0 in ( θ 1 , 0) , therefore, one has g 1 (0) − g 1 ( θ 1 ) =
(cid:82) 0 θ1 h (cid:48) 1 ( θ ) dθ > 0 .
Therefore p
[Equation]
Lemma 8.
When a 2 > a 1 , V ( θ 2 ) <
V ( θ 1 ) .
Under the condition f 1 f 2 > (cid:113) a 1 a 2 , the stationary distribution for resampling satisﬁes the relationship
[Equation]
1 ( θ ) dθ (cid:19) + O ( (cid:15) ) < 1 .
One sufﬁcient condition such that f 1 f 2 > (cid:113) a 1 a 2 is when f 1 , f 2 is signiﬁcantly different from a 1 , a 2 in the sense that f 1 > f 2 when the actually population proportion a 1 < a 2 .
Proof.
In reweighting, with probability f 1 the gradients over the two intervals ( −∞ , 0) , (0 , ∞ ) are a 1 f 1 h (cid:48) 1 ( θ ) , a 1 f 1 (cid:15) respectively; with probability f 2 the gradients are − a 2 f 2 (cid:15), a 2 f 2 h (cid:48)
2 ( θ ) respectively.
Therefore, the expectation of the gradients µ ( θ ) is a 1 h (cid:48) 1 ( θ )+ O ( (cid:15) ) in ( −∞ , 0) and a 2 h (cid:48) 2 ( θ )+ O ( (cid:15) ) in (0 , ∞ ) .
The variance of the gradients σ ( θ ) is f 2 f 1 a 21 h (cid:48) 1 ( θ )
+ O ( (cid:15) ) in ( −∞ , 0) and f 1 f 2 a 22 h (cid:48) 2 ( θ ) 2 + O ( (cid:15) ) in (0 , ∞ ) .
From the similar analysis as in Lemma 7, the stationary distribution is p w ( θ ) =
1 Z e − F ( θ ) with the same F ( θ ) deﬁned in equation 13, but F 1 , F 2 are deﬁned as follows
[Equation]
f 1 af 2 ( h (cid:48) 2 )(cid:19)
+ O ( (cid:15) ) .
Hence, the ratio of the stationary probabiliy at two local minimizers θ 1 < 0 , θ 2 > 0 is
[Equation]
where g i ( θ ) = (cid:82) 1 f (cid:48) i dθ, i = 1 , 2 .
By the assumption that g 1 ( θ 1 ) =
g 2 ( θ 2 ) and h (cid:48) 1 ( θ 1 )
=
h (cid:48) 2 ( θ 2 ) , g 1 (0) =
g 2 (0) and h (cid:48) 1 (0)
=
h (cid:48) 2 (0) one has,
[Equation]
Because of the strictly convexity of h 1 , one has g 1 (0) − g 1 ( θ 1 ) > 0 .
By the assumption f 1 f 2 > (cid:113) a 1 a 2 , then (cid:16) f 1 f 2 a 1 − f 2 f 1 a 2 (cid:17) > 0 , which gives p s ( θ 1 ) p s ( θ 2 ) > 1 .
We can further extend the results in 1D for a ﬁnite number of local minima.
Consider the population loss function V ( θ )
= (cid:80) ki
=1 a i V i
( θ ) with,
[Equation]
i
[Equation]
where h i ( θ ) , 1 ≤ i ≤ k are strictly convex functions and continuously differentiable, O ( (cid:15) ) term is sufﬁciently small and smooth so that the derivatives and integrals are also O ( (cid:15) ) compared with h i ( θ ) .
Here θ i , 1 ≤ i ≤ k − 1 are k − 1 disjoint points, and θ 0 =
−∞ , θ k = ∞ .
We assume that V ( θ ) has k local minimizers θ ∗ i for θ
i − 1 < θ ∗ i ≤ θ i .
In the same way as in the two local minima case, we assume that h i ( θ ) has a similar geometry at the minimizers and
h i ( θ ) , h
i +1 ( θ ) are smooth enough at the disjoint point θ i .
In order to obtain the ratio of the stationary distribution at two arbitrary local minimizes, we take an additional assumption that g i ( θ i − 1 ) =
g i
( θ i ) for all i , where g i ( θ ) is the antiderivative of 1 /h (cid:48)
i ( θ ) .
Intuitively, this assumption requires that each local minimum has an equal barrier on both sides.
To be more speciﬁc, the assumptions we mentioned above are the following: at all
[Equation]
1 h (cid:48)
i ( θ ) dθ , then g i ( θ ∗ i ) =
g j ( θ ∗ j ) for any i (cid:54) =
j ; at all the disjoint points, h (cid:48)
i ( θ i ) =
h i +
( θ i ) , g i ( θ i − 1 )
=
g i
( θ i ) =
g i +
( θ i ) for all i .
The following two lemmas extend the 1D case to ﬁnite number of local minima under the above assumptions.
Lemma 9.
The stationary distribution for resampling at any two local minizers θ ∗ p , θ ∗ q with p > q satisﬁes the relationship
[Equation]
It is easy to see from the above lemma that for resampling, the stationary solution has the highest probability at the global minimizer.
Proof.
For resampling, with probability a i , the gradient is h (cid:48)
i
( θ ) for θ ∈
( θ i − 1 , θ i ) , and O ( (cid:15) ) for θ / ∈
( θ i − 1 , θ i ) .
Therefore, the expectation and variance in ( θ i − 1 , θ i ) are µ = a i h (cid:48)
i ( θ ) + O ( (cid:15) ) and
σ = a i (1 − a i ) h (cid:48)
i ( θ ) 2 + O ( (cid:15) ) .
The stationary solution is
[Equation] , with F ( θ ) =
F i ( θ ) − F i ( θ i − 1 ) + i
[Equation] (cid:88)
[Equation]
where Z = (cid:82) ∞
−∞ e − F ( θ ) is a normalization constant and
[Equation]
Therefore, the ratio of the stationary probability at any two local minimizers θ ∗ p , θ ∗ q is p
[Equation]
(cid:33)
[Equation]
By the assumption that g p ( θ ∗ p
[Equation]
= g q
[Equation]
θ ∗ q
[Equation]
h
[Equation]
p
[Equation]
θ
[Equation]
p
[Equation]
=
[Equation]
q ( θ ∗ q ) and g i ( θ i − 1 ) =
g i
( θ i ) =
g i +
( θ i ) , h (cid:48)
i ( θ i ) =
h (cid:48)
i +1 ( θ i ) for all i , then the above ratio can be simpliﬁed to p s ( θ
[Equation]
p
[Equation]
a
[Equation]
where the last inequality can be easily derived from that g p ( θ p ) − g p
[Equation]
θ
[Equation]
p
[Equation]
=
[Equation]
> 0 because of the strictly convexity of h p .
Lemma 10.
The stationary distribution for reweighting at any two local minizers θ ∗ p , θ ∗ q with p > q satisﬁes the relationship,
[Equation]
It is not that easy to see how the empirical proportion f i affects the ratio.
First, note that g p ( θ p ) − g p ( θ ∗ p ) =
(cid:82) θ p θ ∗ p 1 h (cid:48)
p ( θ ) dθ >
because of the strictly convexity of h p .
Let us consider the case when a p > a q (it is similar for a p < a q ).
In this case, V ( θ ∗ p ) <
V ( θ ∗ q ) , therefore, we expect the above ratio larger than 1 , which implies that
[Equation]
− f q a q (1 − f q ) > 0 .
Note that if f p = a p , f q = a q , then this term is always larger than 0 , but when f p , f q are signiﬁcantly different from a p , a q in the sense that f p < f q and f p < a p , f q > a q , then f p a p (1 − f p ) − f q a q (1 − f q ) < 0 , which will lead to p s ( θ ∗ p )
p s ( θ ∗ q ) < 1 , i.e., higher probability of converging to θ ∗ q , which is not desirable.
Proof.
For reweighting, with probability f i , the gradient is a i f i h (cid:48)
i ( θ ) for θ ∈
( θ i − 1 , θ i ) , and O ( (cid:15) ) for θ / ∈
( θ i − 1 , θ i ) .
Therefore, the expectation and variance in ( θ i − 1 , θ i ) are µ = a i h (cid:48)
i ( θ ) + O ( (cid:15) ) and
σ = (1 − f i ) a
i f i h (cid:48) i ( θ )
+ O ( (cid:15) ) .
The stationary solution p w ( θ ) = 1 Z e − F ( θ ) , with F ( θ ) =
F i ( θ ) − F i ( θ i − 1 )
+ i − 1 (cid:88) j
=
F j ( θ j ) − F j ( θ j − 1 ) , for θ ∈ ( θ i − 1 , θ i ) , where Z = (cid:82) ∞
−∞ e − F ( θ ) is a normalization constant and
F i (
[Equation]
f i
[Equation] [Equation]
i ) (cid:90)
[Equation]
log (cid:18)
[Equation]
Therefore, the ratio of the stationary probability at any two local minimizers θ ∗ p , θ ∗ q is
[Equation]
By the assumption that g p ( θ ∗ p )
=
g q ( θ ∗ q ) , h (cid:48) p ( θ ∗ p ) = h (cid:48)
q ( θ ∗ q ) and g i ( θ i − 1 )
=
g i
( θ i ) =
g i +
( θ i ) , h (cid:48)
i ( θ i ) =
h (cid:48)
i +1 ( θ i ) for all
i
[Equation]
then the above ratio can be simpliﬁed to
[Equation]
B. P ROOF OF L EMMA
Proof.
By the variance of the gradients for resampling and reweighting in (5), and given that at the stationary point E [ ∇ V ( θ ∗ 1 )]
=
E [ ∇ V ( θ ∗ 2 )]
= 0 , one can omit the last term in the variance.
In addition, since ∇ V 1 ( θ ∗ 2 ) , ∇ V 2 ( θ ∗ 1 )
=
O ( (cid:15) ) (cid:28) ∇ V 1 ( θ ∗ 1 ) , ∇ V 2 ( θ ∗ 2 ) by assumption, all the higher order terms are included in an O ( √ (cid:15) ) term.
One can then derive Lemma 6 from Lemma 5.
C A J USTIFICATION OF THE SDE APPROXIMATION
The stochastic differential equation approximation of SGD involving data-dependent covariance coefﬁcient Gaussian noise was ﬁrst introduced in (Li et al., 2017) and justiﬁed in the weak sense.
Consider the SDE d Θ = b
[Equation]
dB.
The Euler-Maruyama discretization with time step η results in
[Equation]
In our case, b ( · ) = − V (cid:48) ( · ) .
When b satisﬁes Lipschitz continuity and some technical smoothness conditions, according to (Li et al., 2017) for any function g from a smooth class M , there exists
C > 0 and α > 0 such that for all k = 0 , 1 , 2 , · · · , N ,
[Equation]
However, as the loss function considered in this paper has jump discontinuous in the ﬁrst derivative, the classical approximation error results for SDE do not apply.
In fact, the problem V / ∈ C 1 ( R n ) is a common issue in machine learning and deep neural networks, as many loss functions involves non-smooth activation functions such as ReLU and leaky ReLU.
In our case, we need to justify the SDE approximation adopted in Section 3.
It turns out that strong approximation error can be obtained if
• the noise coefﬁcient σ is Lipschitz continuous and non-degenerate, and • the drift coefﬁcient b is piece-wise Lipschitz continuous, in the sense that b has ﬁnitely many discontinuity points −∞ = ξ 0 < ξ 1 < · · · < ξ m < ξ m +1 = ∞ and in each interval ( ξ i − 1 , ξ i ) , b is Lipschitz continuous.
Under these conditions, the following approximation result holds: for all k = 0 , 1 , 2 , · · · , N , there exists C > 0 such that
[Equation]
Here Θ kη is the solution to SDE at time kη .
The proof strategy closely follows from (M¨ullerGronbach et al., 2020).
The key is to construct a bijective mapping G : R → R that transforms (14) to SDE with Lipschitz continuous coefﬁcients.
With such a bijection G , one can deﬁne a stochastic process Z : [0 , T ] × Ω → R by Z t =
G (Θ t ) and the transformed SDE is
[Equation]
As the SGD updates can essentially be viewed as data from the Euler-Maruyama scheme, considering Z k as updates from Euler-Maruyama scheme leads to
[Equation]
To control the second item, we introduce
[Equation]
where t ∈ [0 , kη ] .
Then as shown in (M ¨ uller-Gronbach et al., 2020),
[Equation]
, with B being the set of pairs ( y 1 , y 2 ) ∈ R 2 where the joint Lipschitz estimate | b ( y 1 ) − b ( y 2 ) | does not apply due to at least one discontinuity.
In (M ¨ uller-Gronbach et al., 2020), it is estimated by
[Equation]
which leads us to (16).
D N UMERICAL COMPARISONS WITH DIFFERENT LEARNING RATES
In this section, we present extensive numerical results to show the effect of learning rates in our toy examples.
The Figure 5 corresponds to the example in Section 3, and Figure 6 corresponds to the example in Section 4.
V ( ) -3 -
V ( ) -3 -
 V ( ) -3 -
V ( ) -3 -
V ( ) (a) η = 0.
V ( ) (b) η = 0.
V ( ) (c) η = 0.
V ( ) (d) η = 0.
[Figure]
We can see that unless the learning rate η < 0 .
12 , resampling is more reliable in the sense that its trajectory stays around the desired minimizer.