Stochastic Gradient Descent, Exactly

Worked numerical examples of full-batch, single-sample, and mini-batch gradient updates with live tensors and checked exercises.

Stochastic Gradient Descent, Exactly

Trace full-batch, single-sample, and mini-batch updates step by step across a four-row dataset.

  1. Tiny Linear Data

    per-sample losses vs mean loss across four slightly conflicting rows

  2. Full-Batch Gradient

    averaging per-sample gradients across all four rows before updating w

  3. One Sample Gradient

    updating the weight from a single training row's gradient

  4. Two Stochastic Updates in Order

    evaluating the second sample's gradient at the weight produced by the first sample

  5. One Epoch Is One Pass

    four sequential parameter updates inside a single pass over the dataset

  6. Same Samples, Different Order

    why stochastic gradient descent is not commutative across sample orderings

  7. Mini-Batch Gradient

    bridging full-batch stability and single-sample update frequency with mini-batches

  8. Side-by-Side Updates

    one full-batch step, two mini-batch steps, and four single-sample steps side by side

  9. Why the Steps Differ

    per-sample gradient variance and why fixed-step SGD wiggles around the optimum

  10. What SGD Is and Is Not

    separating cheaper per-step optimization from generalization and exact convergence