MoonSay /Tutorials/Machine Learning Interview #9
Contents
  1. 01Introduction
  2. 02Gradient descent
  3. 03The learning rate
  4. 04Batch gradient descent
  5. 05Stochastic gradient descent
  6. 06Mini-batch gradient descent
  7. 07Momentum and Adam
  8. 08Common misconceptions
  9. 09Interview questions and model answers
  10. 10Summary
  11. References
Gradient Descent/Chapter 04 of 10

04Batch gradient descent

4.1The exact gradient

Batch gradient descent (also called full-batch) uses the whole training set at every step:

\theta_{t+1}=\theta_t-\frac{\eta}{n}\sum_{i=1}^{n}\;\nabla\ell_i(\theta_t). \tag{8}

This is (2) computed exactly. Its path is smooth and deterministic: run it twice and you get the same result. For a strongly convex, smooth loss it converges linearly, the error shrinking by a constant factor per step as in (7) (Bottou et al., 2018, §4); with a constant learning rate below the limit (6) it converges to the minimum itself.

4.2The cost of a step

Each step evaluates n gradients of dimension d: it costs O(nd). With a million examples, you read all million just to move once, and one epoch gives exactly one update. A subtler problem is redundancy: real data sets contain many similar examples. LeCun et al. (1998, §4.1) give the extreme case: if 1{,}000 training examples are ten copies of the same 100, the average over all 1{,}000 equals the average over the first 100, so batch gradient descent does ten times the work for exactly the same step. Batch gradient descent is the right tool when the data set is small, when you want a deterministic, reproducible answer on a convex problem, or inside second-order methods such as L-BFGS, which need accurate gradients.