Gradient Sampling Lab
Compare full-batch, mini-batch, and one-example stochastic gradients on one genuine loss surface.
A standalone two-parameter regression lab for the gradient-source question: how does using all examples, a subset, or one example change the update path? The full-data objective stays fixed while the gradient evidence changes.
Step by step
- Start from one deterministic two-feature regression dataset and one shared parameter point.
- Use the full dataset to calculate a stable batch gradient.
- Use a deterministic subset to calculate a mini-batch gradient.
- Use one example to calculate a stochastic gradient.
- Compare all three genuine parameter trajectories on the same full-data loss surface.
- Inspect which sample IDs produced the current update, then continue to Optimizer Studio for SGD, Momentum, RMSProp, and Adam.
Core formulas
Batch gradient
g_B = (1/|B|) Σᵢ∈B ∇ℓᵢ(θ)The batch B decides which examples contribute to the current gradient estimate.
Full-batch update
B = all training examplesUsing every example produces the least noisy gradient estimate for this fixed dataset.
Stochastic update
|B| = 1One-example gradients update frequently but can be noisy relative to the full-data objective.
When to use Gradient Sampling Lab
- Understanding the difference between batch, mini-batch, and stochastic gradient estimates.
- Seeing why smaller batches create noisier optimization paths.
- Preparing for the separate Optimizer Studio.