Batch size is a dial between two costs. Small batches give many updates per pass through the data, but each one points in a wobbly direction. Large batches give steady directions, but only a few updates. This problem measures both sides of the dial on real numbers.
A one-weight model predicts and scores each example by its squared error . That example's gradient with respect to is
To measure the noise without training getting in the way, the weight is frozen at a single value and never updated. The examples are read in the order given, which is already shuffled.
For one batch size :
Task: write batch_size_sweep(xs, ys, w, batch_sizes). For each batch size in batch_sizes, in the order given, return the pair [updates, noise]: the number of batches as a whole number, and the noise rounded to 4 decimal places. The result is a list of these pairs.
xs and ys have the same length, at least 1. Every batch size is a whole number of at least 1.
Worked through, batch_size_sweep([1.0, 2.0, 3.0], [1.0, 3.0, 2.0], 1.0, [2]):
| example | |||
|---|---|---|---|
| 1 | 1 | 1 | |
| 2 | 2 | 3 | |
| 3 | 3 | 2 |
. With the batches are examples 1–2, with gradient , and example 3 alone, with gradient . So and
The answer is [[2, 4.2164]].
Running several batch sizes over the same data puts both costs side by side: how many updates a pass buys, and how far each of those updates strays from the direction the whole dataset would have given.
Once your code passes every test, a reference solution shows up here so you can compare it with yours.