Nestorovβs Accelerated Gradient β’ Change the order of operations β’ At any iteration, to compute the current step: β First extend the previous step β Then compute the gradient step at the resultant position β Add the two to obtain the final step
Nestorovβs Accelerated Gradient β’ Nestorovβs method βπ (π) = πΎβπ (πβ1) β ππΌ π πΉπ π π (π) + πΎβπ (πβ1) π (π) = π (πβ1) + βπ (π)
Nestorovβs Accelerated Gradient β’ Comparison with momentum (example from Hinton) β’ Converges much faster
Moving on: Topics for the day β’ Incremental updates β’ Revisiting βtrendβ algorithms β’ Generalization β’ Tricks of the trade β Divergences.. β Activations β Normalizations
The training formulation output (y) Input (X) β’ Given input output pairs at a number of locations, estimate the entire function
Gradient descent β’ Start with an initial function β’ Adjust its value at all points to make the outputs closer to the required value β Gradient descent adjusts parameters to adjust the function value at all points β Repeat this iteratively until we get arbitrarily close to the target function at the training points
Gradient descent β’ Start with an initial function β’ Adjust its value at all points to make the outputs closer to the required value β Gradient descent adjusts parameters to adjust the function value at all points β Repeat this iteratively until we get arbitrarily close to the target function at the training points
Gradient descent β’ Start with an initial function β’ Adjust its value at all points to make the outputs closer to the required value β Gradient descent adjusts parameters to adjust the function value at all points β Repeat this iteratively until we get arbitrarily close to the target function at the training points
Gradient descent β’ Start with an initial function β’ Adjust its value at all points to make the outputs closer to the required value β Gradient descent adjusts parameters to adjust the function value at all points β Repeat this iteratively until we get arbitrarily close to the target function at the training points
Effect of number of samples β’ Problem with conventional gradient descent: we try to simultaneously adjust the function at all training points β We must process all training points before making a single adjustment β βBatchβ update
Alternative: Incremental update β’ Alternative: adjust the function at one training point at a time β Keep adjustments small β Eventually, when we have processed all the training points, we will have adjusted the entire function β’ With greater overall adjustment than we would if we made a single βBatchβ update
Alternative: Incremental update β’ Alternative: adjust the function at one training point at a time β Keep adjustments small β Eventually, when we have processed all the training points, we will have adjusted the entire function β’ With greater overall adjustment than we would if we made a single βBatchβ update
Alternative: Incremental update β’ Alternative: adjust the function at one training point at a time β Keep adjustments small β Eventually, when we have processed all the training points, we will have adjusted the entire function β’ With greater overall adjustment than we would if we made a single βBatchβ update
Alternative: Incremental update β’ Alternative: adjust the function at one training point at a time β Keep adjustments small β Eventually, when we have processed all the training points, we will have adjusted the entire function β’ With greater overall adjustment than we would if we made a single βBatchβ update
Alternative: Incremental update β’ Alternative: adjust the function at one training point at a time β Keep adjustments small β Eventually, when we have processed all the training points, we will have adjusted the entire function β’ With greater overall adjustment than we would if we made a single βBatchβ update
Incremental Update: Stochastic Gradient Descent β’ Given π 1 , π 1 , π 2 , π 2 ,β¦, π π , π π β’ Initialize all weights π 1 , π 2 , β¦ , π πΏ β’ Do: β For all π’ = 1: π β’ For every layer π : β Compute πΌ π π π¬ππ(π π , π π ) β Update π π = π π β ππΌ π π π¬ππ(π π , π π ) β’ Until πΉπ π has converged 43
Caveats: order of presentation β’ If we loop through the samples in the same order, we may get cyclic behavior
Caveats: order of presentation β’ If we loop through the samples in the same order, we may get cyclic behavior β’ We must go through them randomly
Caveats: order of presentation β’ If we loop through the samples in the same order, we may get cyclic behavior
Caveats: order of presentation β’ If we loop through the samples in the same order, we may get cyclic behavior
Caveats: order of presentation β’ If we loop through the samples in the same order, we may get cyclic behavior
Caveats: order of presentation β’ If we loop through the samples in the same order, we may get cyclic behavior β’ We must go through them randomly to get more convergent behavior
Caveats: learning rate output (y) Input (X) β’ Except in the case of a perfect fit, even an optimal overall fit will look incorrect to individual instances β Correcting the function for individual instances will lead to never-ending, non-convergent updates β We must shrink the learning rate with iterations to prevent this β’ Correction for individual instances with the eventual miniscule learning rates will not modify the function
Incremental Update: Stochastic Gradient Descent β’ Given π 1 , π 1 , π 2 , π 2 ,β¦, π π , π π β’ Initialize all weights π 1 , π 2 , β¦ , π πΏ ; π = 0 β’ Do: β Randomly permute π 1 , π 1 , π 2 , π 2 ,β¦, π π , π π β For all π’ = 1: π β’ π = π + 1 β’ For every layer π : β Compute πΌ π π π¬ππ(π π , π π ) β Update π π = π π β π π πΌ π π π¬ππ(π π , π π ) β’ Until πΉπ π has converged 51
Incremental Update: Stochastic Gradient Descent β’ Given π 1 , π 1 , π 2 , π 2 ,β¦, π π , π π β’ Initialize all weights π 1 , π 2 , β¦ , π πΏ ; π = 0 β’ Do: β Randomly permute π 1 , π 1 , π 2 , π 2 ,β¦, π π , π π β For all π’ = 1: π Randomize input order β’ π = π + 1 β’ For every layer π : Learning rate reduces with j β Compute πΌ π π π¬ππ(π π , π π ) β Update π π = π π β π π πΌ π π π¬ππ(π π , π π ) β’ Until πΉπ π has converged 52
Stochastic Gradient Descent β’ The iterations can make multiple passes over the data β’ A single pass through the entire training data is called an βepochβ β An epoch over a training set with π samples results in π updates of parameters
When does SGD work β’ SGD converges βalmost surelyβ to a global or local minimum for most functions β Sufficient condition: step sizes follow the following conditions ΰ· π π = β π β’ Eventually the entire parameter space can be searched 2 < β ΰ· π π π β’ The steps shrink β The fastest converging series that satisfies both above requirements is π π β 1 π β’ This is the optimal rate of shrinking the step size for strongly convex functions β More generally, the learning rates are optimally determined β’ If the loss is convex, SGD converges to the optimal solution β’ For non-convex losses SGD converges to a local minimum
Batch gradient convergence β’ In contrast, using the batch update method, for strongly convex functions, π (π) β π β < π π π (0) β π β 1 β Giving us the iterations to π convergence as π πππ π β’ For generic convex functions, the π convergence is 1 π π β’ Batch gradients converge βfasterβ β But SGD performs π updates for every batch update
SGD convergence β’ We will define convergence in terms of the number of iterations taken to get within π of the optimal solution π π (π) β π π β β < π β Note: π π here is the error on the entire training data, although SGD itself updates after every training instance β’ Using the optimal learning rate 1/π , for strongly convex functions, π (π) β π β < 1 π π (0) β π β 1 β Giving us the iterations to π convergence as π π β’ For generically convex (but not strongly convex) function, various proofs 1 1 report an π convergence of π using a learning rate of π .
SGD Convergence: Loss value If: β’ π is π -strongly convex, and β’ at step π’ we have a noisy estimate of the 2 β€ π» 2 for all π’ , subgradient ΰ· π π’ with π½ π π’ ΰ· β’ and we use step size π π’ = Ξ€ 1 ππ’ Then for any π > 1 : π½ π π₯ π β π(π₯ β ) β€ 17π» 2 (1 + log π ) ππ
SGD Convergence β’ We can bound the expected difference between the loss over our data using the optimal weights, π₯ β , and log(π) the weights at any single iteration, π₯ π , to π« for π log(π) strongly convex loss or π« for convex loss π 1 β’ Averaging schemes can improve the bound to π« π 1 and π« π β’ Smoothness of the loss is not required
SGD example β’ A simpler problem: K-means β’ Note: SGD converges slower β’ Also note the rather large variation between runs β Lets try to understand these results..
Recall: Modelling a function π(π) π = π(π; πΏ) β’ To learn a network π π; πΏ to model a function π(π) we minimize the expected divergence ΰ·’ πΏ = argmin ΰΆ± πππ€ π π; π , π π π(π)ππ π π = argmin πΉ πππ€ π π; π , π π π 61
Recall: The Empirical risk d i X i β’ In practice, we minimize the empirical error π = 1 πΉπ π π π; π , π π π ΰ· πππ€ π π π ; π , π π π=1 ΰ·’ πΏ = argmin πΉπ π π π; π , π π π β’ The expected value of the empirical error is actually the expected divergence πΉ πΉπ π π π; π , π π = πΉ πππ€ π π; π , π π 62
Recap: The Empirical risk d i X i β’ In practice, we minimize the empirical error π = 1 πΉπ π π π; π , π π π ΰ· πππ€ π π π ; π , π π π=1 The empirical error is an unbiased estimate of the expected error ΰ·’ πΏ = argmin πΉπ π πππ€ π π; π , π π Though there is no guarantee that minimizing it will minimize the π expected error β’ The expected value of the empirical error is actually the expected error πΉ πΉπ π π π; π , π π = πΉ πππ€ π π; π , π π 63
Recap: The Empirical risk d i X i The variance of the empirical error: var(Err) = 1/N var(div) The variance of the estimator is proportional to 1/N The larger this variance, the greater the likelihood that the W that β’ In practice, we minimize the empirical error minimizes the empirical error will differ significantly from the W that π minimizes the expected error = 1 πΉπ π π π; π , π π π ΰ· πππ€ π π π ; π , π π The empirical error is an unbiased estimate of the expected error π=1 ΰ·’ Though there is no guarantee that minimizing it will minimize the πΏ = argmin πΉπ π πππ€ π π; π , π π π expected error β’ The expected value of the empirical error is actually the expected error πΉ πΉπ π π π; π , π π = πΉ πππ€ π π; π , π π 64
SGD d i X i β’ At each iteration, SGD focuses on the divergence of a single sample πππ€ π π π ; π , π π β’ The expected value of the sample error is still the expected divergence πΉ πππ€ π π; π , π π 65
SGD d i X i β’ At each iteration, SGD focuses on the divergence of a single sample πππ€ π π π ; π , π π The sample error is also an unbiased estimate of the expected error β’ The expected value of the sample error is still the expected divergence πΉ πππ€ π π; π , π π 66
SGD d i X i The variance of the sample error is the variance of the divergence itself: var(div) β’ At each iteration, SGD focuses on the divergence This is N times the variance of the empirical average minimized by batch update of a single sample πππ€ π π π ; π , π π The sample error is also an unbiased estimate of the expected error β’ The expected value of the sample error is still the expected divergence πΉ πππ€ π π; π , π π 67
Explaining the variance π(π¦) π(π¦; π) π¦ β’ The blue curve is the function being approximated β’ The red curve is the approximation by the model at a given π β’ The heights of the shaded regions represent the point-by-point error β The divergence is a function of the error β We want to find the π that minimizes the average divergence
Explaining the variance π(π¦) π(π¦; π) π¦ β’ Sample estimate approximates the shaded area with the average length of the lines of these curves is the red curve itself β’ Variance: The spread between the different curves is the variance
Explaining the variance π(π¦) π(π¦; π) π¦ β’ Sample estimate approximates the shaded area with the average length of the lines β’ This average length will change with position of the samples
Explaining the variance π(π¦) π(π¦; π) π¦ β’ Having more samples makes the estimate more robust to changes in the position of samples β The variance of the estimate is smaller
Explaining the variance With only one sample π(π¦) π(π¦; π) π¦ β’ Having very few samples makes the estimate swing wildly with the sample position β Since our estimator learns the π to minimize this estimate, the learned π too can swing wildly
Explaining the variance With only one sample π(π¦) π(π¦; π) π¦ β’ Having very few samples makes the estimate swing wildly with the sample position β Since our estimator learns the π to minimize this estimate, the learned π too can swing wildly
Explaining the variance With only one sample π(π¦) π(π¦; π) π¦ β’ Having very few samples makes the estimate swing wildly with the sample position β Since our estimator learns the π to minimize this estimate, the learned π too can swing wildly
SGD example β’ A simpler problem: K-means β’ Note: SGD converges slower β’ Also has large variation between runs
SGD vs batch β’ SGD uses the gradient from only one sample at a time, and is consequently high variance β’ But also provides significantly quicker updates than batch β’ Is there a good medium?
Alternative: Mini-batch update β’ Alternative: adjust the function at a small, randomly chosen subset of points β Keep adjustments small β If the subsets cover the training set, we will have adjusted the entire function β’ As before, vary the subsets randomly in different passes through the training data
Incremental Update: Mini-batch update β’ Given π 1 , π 1 , π 2 , π 2 ,β¦, π π , π π β’ Initialize all weights π 1 , π 2 , β¦ , π πΏ ; π = 0 β’ Do: β Randomly permute π 1 , π 1 , π 2 , π 2 ,β¦, π π , π π β For π’ = 1: π: π β’ π = π + 1 β’ For every layer k: β βπ π = 0 β’ For tβ = t : t+b -1 β For every layer π : Β» Compute πΌ π π πΈππ€(π π’ , π π’ ) Β» βπ π = βπ π + πΌ π π πΈππ€(π π’ , π π’ ) β’ Update β For every layer k: π π = π π β π π βπ π β’ Until πΉπ π has converged 78
Incremental Update: Mini-batch update β’ Given π 1 , π 1 , π 2 , π 2 ,β¦, π π , π π β’ Initialize all weights π 1 , π 2 , β¦ , π πΏ ; π = 0 β’ Do: β Randomly permute π 1 , π 1 , π 2 , π 2 ,β¦, π π , π π β For π’ = 1: π: π Mini-batch size β’ π = π + 1 β’ For every layer k: Shrinking step size β βπ π = 0 β’ For tβ = t : t+b -1 β For every layer π : Β» Compute πΌ π π πΈππ€(π π’ , π π’ ) Β» βπ π = βπ π + πΌ π π πΈππ€(π π’ , π π’ ) β’ Update β For every layer k: π π = π π β π π βπ π β’ Until πΉπ π has converged 79
Mini Batches d i X i β’ Mini-batch updates compute and minimize a batch error π = 1 πΆππ’πβπΉπ π π π; π , π π π ΰ· πππ€ π π π ; π , π π π=1 β’ The expected value of the batch error is also the expected divergence πΉ πΆππ’πβπΉπ π π π; π , π π = πΉ πππ€ π π; π , π π 80
Mini Batches d i X i β’ Mini-batch updates computes an empirical batch error π = 1 πΆππ’πβπΉπ π π π; π , π π π ΰ· πππ€ π π π ; π , π π The batch error is also an unbiased estimate of the expected error π=1 β’ The expected value of the batch error is also the expected divergence πΉ πΆππ’πβπΉπ π π π; π , π π = πΉ πππ€ π π; π , π π 81
Mini Batches d i X i β’ Mini-batch updates computes an empirical batch error The variance of the batch error: var(Err) = 1/b var(div) π This will be much smaller than the variance of the sample error in SGD = 1 πΆππ’πβπΉπ π π π; π , π π π ΰ· πππ€ π π π ; π , π π The batch error is also an unbiased estimate of the expected error π=1 β’ The expected value of the batch error is also the expected divergence πΉ πΆππ’πβπΉπ π π π; π , π π = πΉ πππ€ π π; π , π π 82
Minibatch convergence 1 β’ For convex functions, convergence rate for SGD is π« π . β’ For mini-batch updates with batches of size π , the 1 1 convergence rate is π« ππ + π β Apparently an improvement of π over SGD β But since the batch size is π , we perform π times as many computations per iteration as SGD β We actually get a degradation of π β’ However, in practice β The objectives are generally not convex; mini-batches are more effective with the right learning rates β We also get additional benefits of vector processing
SGD example β’ Mini-batch performs comparably to batch training on this simple problem β But converges orders of magnitude faster
Measuring Error β’ Convergence is generally defined in terms of the overall training error β Not sample or batch error β’ Infeasible to actually measure the overall training error after each iteration β’ More typically, we estimate is as β Divergence or classification error on a held-out set β Average sample/batch error over the past π samples/batches
Training and minibatches β’ In practice, training is usually performed using mini- batches β The mini-batch size is a hyper parameter to be optimized β’ Convergence depends on learning rate β Simple technique: fix learning rate until the error plateaus, then reduce learning rate by a fixed factor (e.g. 10) β Advanced methods : Adaptive updates, where the learning rate is itself determined as part of the estimation
Training and minibatches β’ In practice, training is usually performed using mini- batches β The mini-batch size is a hyper parameter to be optimized β’ Convergence depends on learning rate β Simple technique: fix learning rate until the error plateaus, then reduce learning rate by a fixed factor (e.g. 10) β Advanced methods : Adaptive updates, where the learning rate is itself determined as part of the estimation
Recall: Momentum β’ The momentum method βπ (π) = πΎβπ (πβ1) + ππΌ π πΉπ π π (πβ1) β’ Updates using a running average of the gradient
Momentum and incremental updates β’ The momentum method βπ (π) = πΎβπ (πβ1) + ππΌ π πΉπ π π (πβ1) β’ Incremental SGD and mini-batch gradients tend to have high variance β’ Momentum smooths out the variations β Smoother and faster convergence
Nestorovβs Accelerated Gradient β’ At any iteration, to compute the current step: β First extend the previous step β Then compute the gradient at the resultant position β Add the two to obtain the final step β’ This also applies directly to incremental update methods β The accelerated gradient smooths out the variance in the gradients
More recent methods β’ Several newer methods have been proposed that follow the general pattern of enhancing long- term trends to smooth out the variations of the mini-batch gradient β RMS Prop β ADAM: very popular in practice β Adagrad β AdaDelta β β¦ β’ All roughly equivalent in performance
Variance-normalized step β’ In recent past β Total movement in Y component of updates is high β Movement in X components is lower β’ Current update, modify usual gradient-based update: β Scale down Y component β Scale up X component β’ A variety of algorithms have been proposed on this premise β We will see a popular example 96
RMS Prop β’ Notation: β Updates are by parameter β Sum derivative of divergence w.r.t any individual parameter π₯ is shown as π π₯ πΈ β The squared derivative is π π₯ 2 πΈ = π π₯ πΈ 2 β The mean squared derivative is a running estimate of the 2 πΈ average squared derivative. We will show this as πΉ π π₯ β’ Modified update rule: We want to β scale down updates with large mean squared derivatives β scale up updates with small mean squared derivatives 97
RMS Prop β’ This is a variant on the basic mini-batch SGD algorithm β’ Procedure: β Maintain a running estimate of the mean squared value of derivatives for each parameter β Scale update of the parameter by the inverse of the root mean squared derivative 2 πΈ π = πΏπΉ π π₯ 2 πΈ πβ1 + 1 β πΏ 2 πΈ π πΉ π π₯ π π₯ π π₯ π+1 = π₯ π β π π₯ πΈ 2 πΈ π + π πΉ π π₯ 98
RMS Prop (updates are for each weight of each layer) β’ Do: β Randomly shuffle inputs to change their order 2 πΈ π = 0 β Initialize: π = 1 ; for all weights π₯ in all layers, πΉ π π₯ β For all π’ = 1: πΆ: π (incrementing in blocks of πΆ inputs) β’ For all weights in all layers initialize π π₯ πΈ π = 0 β’ For π = 0: πΆ β 1 β Compute Β» Output π(π π+π ) ππ¬ππ(π(π π+π ),π π+π ) Β» Compute gradient ππ ππ¬ππ(π(π π+π ),π π+π ) Β» Compute π π₯ πΈ π += ππ β’ update: π π¬ π = πΉπ π π π π¬ πβπ + π β πΉ π π¬ π π π π π π π½ π π+π = π π β π π π¬ π π¬ π + π π π π β’ π = π + 1 Until πΉ(πΏ 1 , πΏ 2 , β¦ , πΏ πΏ ) has converged β’ 99
Visualizing the optimizers: Bealeβs Function β’ http://www.denizyuret.com/2015/03/alec-radfords-animations-for.html 101
Visualizing the optimizers: Long Valley β’ http://www.denizyuret.com/2015/03/alec-radfords-animations-for.html 102
Visualizing the optimizers: Saddle Point β’ http://www.denizyuret.com/2015/03/alec-radfords-animations-for.html 103
Story so far β’ Gradient descent can be sped up by incremental updates β Convergence is guaranteed under most conditions β Stochastic gradient descent: update after each observation. Can be much faster than batch learning β Mini-batch updates: update after batches. Can be more efficient than SGD β’ Convergence can be improved using smoothed updates β RMSprop and more advanced techniques
Topics for the day β’ Incremental updates β’ Revisiting βtrendβ algorithms β’ Generalization β’ Tricks of the trade β Divergences.. β Activations β Normalizations
Tricks of the trade.. β’ To make the network converge better β The Divergence β Dropout β Batch normalization β Other tricks β’ Gradient clipping β’ Data augmentation β’ Other hacks..
Training Neural Nets by Gradient Descent: The Divergence Total training error: πΉπ π = π πΌ ΰ· πΈππ€(π π , π π ; π 1 , π 2 , β¦ , π πΏ ) π β’ The convergence of the gradient descent depends on the divergence β Ideally, must have a shape that results in a significant gradient in the right direction outside the optimum β’ To βguideβ the algorithm to the right solution 107
Recommend
More recommend