Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-076

Elastic Net Coordinate Step

Problem

Compute one coordinate-descent update for the elastic net.

Return soft_threshold(rho_j, lam1) / (z_j + lam2), applying the usual three-branch soft-threshold rule with threshold lam1. Return 0.0 when the denominator is not positive.

Hint

lam2 shrinks the denominator while lam1 soft-thresholds the numerator.

Test cases

case 1
in: [1,2,0.25,0.5]
expected: 0.3
case 2
in: [0.1,2,0.25,0.5]
expected: 0
case 3
in: [-1,4,0.5,1]
expected: -0.1
case 4
in: [0.3,0,0.1,0]
expected: 0
Starter codePython
def elastic_net_coordinate_step(rho_j, z_j, lam1, lam2):
    # Your code here
    pass

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