Skip to content
DeepForgeby svx
All problems
HardOptimizationop-071

Barzilai-Borwein Step

Problem

Compute both Barzilai-Borwein step sizes from s = x_new - x_old and y = grad_new - grad_old.

BB1 is (s dot s) / (s dot y) and BB2 is (s dot y) / (y dot y). Return [bb1, bb2], using 0.0 for either value whose denominator is zero.

Hint

BB1 and BB2 differ by which side of the secant equation they minimize.

Test cases

case 1
in: [[1,1],[2,1]]
expected: [0.6666666666666666,0.6]
case 2
in: [[0.5,-1],[1,-2]]
expected: [0.5,0.5]
case 3
in: [[1,2],[0,0]]
expected: [0,0]
case 4
in: [[2,0],[1,1]]
expected: [2,1]
Starter codePython
def barzilai_borwein_step(s, y):
    # Returns [bb1, bb2]
    # Your code here
    pass

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