All problems
Fletcher-Reeves Beta With Restart
Problem
Compute the Fletcher-Reeves conjugate gradient coefficient with a restart test.
Return (grad dot grad) / (grad_old dot grad_old), but return 0.0 when the old gradient is zero or when grad dot p_old is not negative, meaning the previous direction is no longer a descent direction.
Hint
A non-negative gradient-direction dot product triggers a restart to steepest descent.
Test cases
case 1
in: [[2,-2],[1,1],[-1,0]]
expected: 4
case 2
in: [[1,0],[1,1],[1,0]]
expected: 0
case 3
in: [[0,0],[0,0],[1,1]]
expected: 0
case 4
in: [[1,2],[0.5,0.5],[-2,-4]]
expected: 10
Starter codePython
def fletcher_reeves_beta(grad, grad_old, p_old):
# Your code here
pass4 test cases · run your code against them in the editor