Towards Optimal One Pass Large Scale Learning with Averaged Stochastic Gradient Descent
Wei Xu
Introduction
For prediction problems, we want to find a function with parameter to predict the value of the outcome variable given an observed vector . Typically, the problem is formulated as an optimization problem:
where is the number of data points, is the parameter that minimize the empirical cost, are the training example, is a loss function which gives small value if is a good prediction for , and is a regularization function for which typically gives small value for small . Some commonly used are: for support vector machine (SVM), for L2 SVM, and for linear regression. Some commonly used regularization functions are: L2 regularization , and L1 regularization .
For large scale machine learning problems, we need to deal with optimization problems with millions or even billions of training samples. The classical optimization techniques such as interior point methods or conjugate gradient descent have to go through all data points to just evaluate the objective once. Not to say that they need to go through the whole data set many times in order to find the best .
On the other hand, stochastic gradient descent (SGD) has been shown to have great promise for large scale learning (Zhang, 2004; Hazan et al., 2006; Shalev-Shwartz et al., 2007; Bottou and Bousquet, 2008; Shalev-Shwartz and Tewari, 2009; Langford et al., 2009). Let be one data sample, be the cost of for , be the gradient function, and be all the training samples at step. The SGD method updates according to its stochastic gradient:
where is learning rate at the step. can be either a scalar or a matrix. Let the expected loss of over test data be , the optimal parameter be , and the Hessian be . Note that and are random variables depending on . Hence both and are random variables depending on . If is a scalar, the best asymptotic convergence for the expected excess loss is , which is obtained by using , where is the smallest eigenvalue of and is some constant. The asymptotic convergence rate of SGD can be potentially benefit from using second order information (Bottou and Bousquet, 2008; Schraudolph et al., 2007; Amari et al., 2000). The optimal asymptotic convergence rate is achieved by using matrix valued learning rate . If this optimal matrix step size is used, then asymptotically second order SGD is as good as explicitly optimizing the empirical loss. More precisely, this means that both and converge to a same positive constant.
Since is unknown in advance, methods for adaptively estimating is proposed (Bottou and LeCun, 2005; Amari et al., 2000). However, for high dimensional data sets, maintaining a full matrix is too computationally expensive. Hence various methods for approximating have been proposed (LeCun et al., 1998; Schraudolph et al., 2007; Roux et al., 2008; Bordes et al., 2009). However, with the approximated , the optimal convergence cannot be guaranteed. It is worth to point out that most of the existing analysis for second order SGD is asymptotic, namely, that they do not tell how much data is needed for the algorithm to reach their asymptotic region.
In order to accelerate the convergence speed of SGD, averaged stochastic gradient (ASGD) was proposed in Polyak and Juditsky (1992). For ASGD, the running average of the parameters obtained by SGD is used as the estimator for . Polyak and Juditsky (1992) showed a very nice result that converges to as good as full second order SGD, which means that if there are enough training samples, ASGD can obtain the parameter as good as the empirical optimal parameter in just one pass of data. And another advantage of ASGD is that, unlike second order SGD, ASGD is extremely easy to implement. Zhang (2004); Nemirovski et al. (2009) gave some nice non-asymptotic analysis for ASGD with a fixed learning rate. However, the convergence bounds obtained by Zhang (2004); Nemirovski et al. (2009) are far less appealing than that of Polyak and Juditsky (1992).
Despite its nice properties, ASGD receives little attention in recent research for online large scale learning. The reason for the lack of interest in ASGD might be that its potential good convergence has not been realized by researchers in real applications. Our analysis shows the cause of this may due to the fact the ASGD needs a prohibitively large amount of data to reach asymptotics if learning rate is chosen arbitrarily.
A typical choice for the learning rate is to make it decease as fast as for some constant . In this paper, we assume a particular form of learning rate schedule which satisfies this condition,
where , and are some constants. Based on this form of learning rate schedule, we provide non-asymptotic analysis of ASGD. Our analysis shows that and should to be properly set according to the curvature of the expected cost function. should be a problem independent constant. With our recipe for setting the learning rate, we show that ASGD outperforms SGD if the data size is large enough for SGD to reach its asymptotic region.
To demonstrate the effectiveness of ASGD with the proposed learning rate schedule, we apply ASGD for training linear classification and regression models. We compare ASGD with other prominent large scale SVM solvers on several benchmark tasks. Our experimental results show the clear advantage of ASGD.
In the rest of the paper, for matrices and , means is positive semi-definite, is defined as . We will assume for some constant , and in all the theorems and lemmas. Through out this paper we denote and . To help the reader focus on the main idea, we put most proofs to the Appendix.
The paper is organized as follows: Section 2 establish some results on stochastic linear equation; Section 3 extends the result to ASGD for quadratic loss functions; Section 4 works on general non-quadratic loss functions; Section 5 discusses some implementation issues; Section 6 shows experimental results; Section 7 concludes the paper; and Appendix includes all the proofs.
Stochastic Linear Equation
To motivate the problem, we first take a close look at the SGD update (2). Let and the first order Taylor expansion of around be , where and . Then can be decomposed as:
where , and . So the SGD update (2) can be re-written as
It is easy to see that is martingale with respect to , i.e., , and has identical distribution for different . is also martingale with respect to . However, as we will see in later section, its magnitude depends on . If is smooth, we have . For smooth , we have . Both and are asymptotically negligible if suitable conditions are met. We also note that for quadratic .
By the above analysis, we first consider the following simple stochastic approximation procedure which ignores and :
where is a positive definite matrix with the smallest eigenvalue and the largest eigenvalue , is martingale difference process, i.e., , the variance of is . We will see that this algorithm can be used to find the root of equation
If and , then the estimator in (6) satisfies:
The immediate conclusion from Theorem 1 is the asymptotic convergence bound of .
The above bound is consistent with Theorem 1 in Polyak and Juditsky (1992) and is the best possible asymptotic convergence rate that can be achieved by any algorithms (Fabian, 1973). However, we are more interested in the non-asymptotic behavior of .
If we choose , it takes samples for in (6) to reach the asymptotic region. And at this point, begins to become better than .
Proof Let , we have
On the other hand, the best possible convergence for is obtained with and :
It takes samples for in (6) to reach the asymptotic region.
By Corollary 4, we should limit in order to have fast convergence. For the linear problem (5), we should always use . If we use some arbitrary value such as 1 for , although still has asymptotic optimal convergence according to Polyak and Juditsky (1992), but it needs much more samples to reach the asymptotic region in situations where is very small. For the general SGD update (4), we need to trade-off against the convergence of and . Hence should not be 0. In general, should be a constant factor times of .
Regression Problem
In this section, we will analyze the convergence for regression problems. As we noted in section 2, the SGD update can be decomposed as (4), where for quadratic loss of linear regression. As in the proof of Theorem 1, can be written as:
We already have a bound for and in Theorem 1. Now we work on . We will make two assumptions:
(9) is related to the continuity of and the distribution of . (10) is related to the convergence of standard SGD. A bound similar to (10) can be found in section 3.1 of Hazan et al. (2006). Using these assumptions, we can bound :
With the above lemma, we can obtain the following asymptotic convergence result:
For quadratic loss, with assumption (9) (10), satisfies
The corollary follows by applying (16), (17) and Lemma 5. The best convergence rate is obtained when . Now we take a close look at the constant factor in assumption (9) to have a better understanding of the non-asymptotic behavior of .
For ridge regression , if , then
Assuming , Lemma 12 in the Appendix shows that will diverge if learning rate is greater than . So and . Plugging these bounds for and into Lemma 5, we have the following for ,
Note that the best possible SGD error bound is with and . We see that is negligible compared to the error of SGD if . Together with the analysis in Section 2, we conclude that ASGD begins to outperform SGD after . The conclusion we draw in this section applies not only to the case of with constant norm. Similar conclusion can be drawn if is normally distributed or if each dimension of is independently distributed, and/or if L2 regularization is used.
Based on above analysis, for linear regression problems, we propose to use the following values for (3) to calculate the learning rate: , , . We will see that in the next section for general non-quadratic loss, optimal is different since we need to further consider the convergence of .
Non-quadratic loss
For non-quadratic loss, we need to analyze the contribution of to the error. We need the following two additional assumptions:
Similar to (9), (12) is related to the continuity of and the distribution of and . Similar to (10), (13) is related to the convergence of standard SGD. We note that the asymptotic normality of (Fabian, 1968) suggests that assumption (13) is reasonable.
With Assumption (9) (10) (12) and (13) , we have
where .
For non-quadratic loss, with assumption (9) (10) (12) and (13), if , then satisfies
The corollary follows by applying (16), (17), Lemma 5 and Lemma 8. The best convergence rate is obtained when , which is different from that for quadratic loss.
Implementation
In this section, we discuss how we implement ASGD for linear models with L2 regularization. The running average can be recursively updated by , which is very easy to implement. However, for sparse data sets, this can be very costly compared to SGD since is typically a dense vector. Consider the following average procedure:
where is the L2 regularization coefficient, , and is the rate of averaging. Hence is sparse when is sparse. We want to take the advantage of the sparsity of for updating and . Let
After some manipulation, we get the following:
Now define and with , we get
Hence we obtain the following efficient algorithm for updating :
At any step of the algorithm, can be obtained by . Note that in Algorithm 1, none of the operations involves two dense vectors. Thus the number of operations per sample is , where is the number of non-zero elements in .
Experiments
In this section, we provide 3 sets of experiments. The first experiment illustrate the importance of learning rate scheduling for ASGD. The second experiment illustrates the asymptotic optimal convergence of ASGD. In the third set of experiments, we apply ASGD on many public benchmark data sets and compare it with several state of the art algorithms.
Our first experiment is used to show how different learning rate schedule affects the convergence of ASGD using a synthetic problem. The exemplar optimization problem is , where is a symmetric 100x100 matrix with eigenvalues and follows normal distribution with zero mean and unit covariance. It can be shown that the optimal is . Figure 1 shows the excess risk of the solution vs. number of training samples . We note that in this particular example the excess risk is simply . For the good example of ASGD (ASGD in the figure), we use our proposed learning rate schedule according to Section 3. For a bad example of ASGD (ASGD_BAD in the figure), we use , which looks simple and also has optimal asymptotic convergence according to Corollary 2. Figure 1 also shows the performance of standard SGD using learning rate schedule and batch method . We see that both ASGD and ASGD_BAD eventually outperforms SGD and come close to the batch method. However, it takes only a few thousands example for ASGD to get to the asymptotic region, while it takes hundreds of thousands of examples for ASGD_BAD. This huge difference illustrates the significant role of learning rate scheduling for ASGD.
2 Asymptotic optimal convergence
3 Experiments on benchmark data sets
In the third set of experiments, we compare ASGD with several other algorithms for training large scale linear models: online limited-memory BFGS (oLBFGS) of Schraudolph et al. (2007), stochastic gradient descent (SGD2) of Bottou (2007), dual coordinate descent (LIBLINEAR) of Fan et al. (2008), Pegasos of Shalev-Shwartz et al. (2007) and SGDQN of Bordes et al. (2009). We performed extensive evaluation of ASGD on many data sets. Due to space limit, we only show detailed results on four tasks in this paper. COVTYPE is the detection of class 2 among 7 forest cover types (Blackard et al). All dimensions are normalized between 0 and 1. DELTA is a synthetic data set from the PASCAL Large Scale Challenge (Sonnenburg et al., 2008). We use the default data preprocessing provided by the challenge organizers. RCV1 is the classification of documents belonging to class CCAT in RCV1 text data set (Lewis et al., 2004). We use the same preprocessing as provided in Bottou (2007). MNIST9 is the classification of digit 9 against all other digits in MNIST digit image data set (LeCun et al., 1998). For this task, we generate our own image feature vectors for recognition. The experiments for these four tasks use squared hinge loss with regularization . Since is unknown, we use the regularization coefficient as , which is a lower bound for true . Table 1 summarizes the data sets, where is the calculated from 1000 samples, is the point where average begins (See Section 5). Figure 3 shows the test error rate (left), elapsed time (middle) and test cost (right) at different points within first two passes of training data.
We also include more experimental results on data sets from Pascal Large Scale Challenge. However, to save space, we only show figures for test error rate. All experiments use the default data preprocessing provided by the challenge organizers. Table 2 summarize the data sets. Figure 4 and Figure 5 shows result for L2 SVM, logistic regression and SVM. LIBLINEAR is not included in the figures for logistic regression because the dual coordinate descent method used by LIBLINEAR cannot solve logistic regression. Although the theory of ASGD only applies to smooth cost functions, we also include the results of SVM to satisfy the possible curiosity of some readers.
As we can see from the figures, ASGD clearly outperforms all other 5 algorithms in terms accuracy in most of the data sets. In fact, for most of the data sets, ASGD reaches good performance with only one pass of data, while many other algorithms still perform poorly at that point. The only exception is the beta data set, where all methods performs equally bad because the two classes in this data set are not linearly separable. Moreover, the performance of the other 5 methods tend to be more volatile, while performance of ASGD is more robust due to average. In terms of time spent on one pass of data, ASGD is similar to the other methods except oLBFGS, which means that ASGD needs less time to reach similar test performance compared to the other methods. Another interesting point is that although the current theory of ASGD is based on the assumption that cost function is smooth, as shown in the figures, ASGD also works pretty well with non-smooth loss such as hinge loss.
Conclusion
ASGD is relatively easy to implement compared to other algorithms. And as demonstrated on both synthetic and real data sets, with our proposed learning rate schedule, ASGD performs better than other more complicated algorithms for large scale learning problems. In this paper, we only apply ASGD to linear models with convex loss, which has unique local optimum. It would be more interesting to see how ASGD can be applied to more complicated models such as conditional random fields (CRF) or models with multiple local optimums such as neural networks.
The author would like to thank Leon Bottou for the insightful discussions, Antoine Bordes for providing source code of SGDQN, SGD2 and oLBFGS, and Yi Zhang for the suggestions to improve the exposition of this paper.
References
A Proofs
Let . If , then
Proof For , let , where . We only need to show
where we used the fact for .
For , let , where . We only need to show
By mean value theorem, there exists some s.t. . Hence
The following is a key lemma which is used several times in this paper.
If and , then we have the following bound for .
where is the same as in Theorem 1.
Proof It is easy to verify the following relation by induction on ,
Now we calculate the difference between and .
It is clear that from the first line of above equation that . Hence we obtain the first inequality of the lemma. We have
Define as . Since , we have . Hence
Now plugging (14) into above inequality, we obtain the claim of the lemma. With Lemma 11, we can now prove Theorem 1.
where is defined in Lemma 11. Hence
And we have since .
Proof (Lemma 7) Let . We have the following:
For linear regression problem , assuming all are , then (2) will diverge if learning rate is greater than .
Proof Let be defined as in Lemma 11. We obtain the following from (2),
Let , , , . Taking expectation with respect to , noticing that , we get
where , . Hence
If , then
Noticing that as , we conclude that is diverging if .
Proof (Lemma 8) Let ,