All problems
Box Constrained Projected Gradient Step
Problem
A projected gradient step moves along -grad with step lr, then projects the result onto the box [lo, hi].
Given x, grad, lr, lo, and hi, return the updated point.
Hint
Gradient step first, clipping second.
Test cases
case 1
in: [[0,0],[1,-1],0.5,-0.2,0.2]
expected: [-0.2,0.2]
case 2
in: [[0.5],[2],1,0,1]
expected: [0]
case 3
in: [[1,1],[-1,-1],2,0,3]
expected: [3,3]
Starter codePython
def projected_gradient_box_step(x, grad, lr, lo, hi):
# Your code here
pass3 test cases · run your code against them in the editor