All problems
Elastic Net Proximal Step
Problem
Apply the proximal operator of the elastic net after a gradient step.
Compute z = (w - lr * grad) / (1 + lr * l2), then soft-threshold z at t = lr * l1. Return z - t when z > t, z + t when z < -t, and 0.0 otherwise.
Hint
The L2 part shrinks multiplicatively before the L1 soft threshold.
Test cases
case 1
in: [1,0.5,0.1,0.1,0.2]
expected: 0.9213725490196077
case 2
in: [0.05,0,0.1,1,0]
expected: 0
case 3
in: [-2,-0.5,0.1,0.2,0.5]
expected: -1.837142857142857
case 4
in: [0,0,0.1,0.5,1]
expected: 0
Starter codePython
def elastic_net_prox(w, grad, lr, l1, l2):
# Your code here
pass4 test cases · run your code against them in the editor