Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-070

Polyak Step Size

Problem

Compute the Polyak step size.

Return (f_current - f_best) / grad_norm_sq, or 0.0 if grad_norm_sq is not positive. This assumes the optimal objective value f_best is known.

Hint

The step shrinks as the current gap to the optimum shrinks.

Test cases

case 1
in: [10,5,4]
expected: 1.25
case 2
in: [1,1,2]
expected: 0
case 3
in: [3,0,0]
expected: 0
case 4
in: [2.5,1,6]
expected: 0.25
Starter codePython
def polyak_step_size(f_current, f_best, grad_norm_sq):
    # Your code here
    pass

4 test cases · run your code against them in the editor