All problems
Subgradient Absolute Value Step
Problem
For f(x) = |x|, a subgradient at x is sign(x) with 0 chosen at the kink. One subgradient step is x_new = x - lr * sign(x).
Given x and lr, return x_new.
Hint
The kink is already a minimum, so it stays put.
Test cases
case 1
in: [2,0.5]
expected: 1.5
case 2
in: [-1,2]
expected: 1
case 3
in: [0,1]
expected: 0
Starter codePython
def subgradient_absolute_value_step(x, lr):
# Your code here
pass3 test cases · run your code against them in the editor