Workspace/Coding labs
Loading progress

Verify a batch gradient update

Intermediate65 min

Implement gradient_step(xs, ys, w, b, learning_rate) for scalar linear predictions. Use mean half-squared error over equal nonempty sequences. Return (new_w, new_b, loss_before_update), updating both parameters from the same original snapshot. Require finite numeric inputs, reject booleans, and require a finite nonnegative learning rate. The test suite checks actual calculus with a finite-difference comparison.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Inputgradient_step([2], [5], 1, 0, 0.1)

Output(1.6, 0.3, 4.5)

The weight gradient is -6 and the bias gradient is -3.
EXAMPLE 2

Inputgradient_step([1], [2], 2, 0, 0.1)

Output(2.0, 0.0, 0.0)

A perfect prediction has no update.
solution.pyPython 3.12