Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-096

Group Soft Threshold

Problem

Apply the group soft-thresholding (group lasso proximal) operator to a coefficient vector.

Compute norm = sqrt(sum(x ** 2)). If norm <= lam, return all zeros; otherwise return every component scaled by 1 - lam / norm.

Hint

Shrink the whole group by a single factor, or zero it out entirely.

Test cases

case 1
in: [[3,4],2]
expected: [1.7999999999999998,2.4]
case 2
in: [[0.3,0.4],0.5]
expected: [0,0]
case 3
in: [[0,0],0.1]
expected: [0,0]
case 4
in: [[5],1]
expected: [4]
Starter codePython
def group_soft_threshold(v, lam):
    # Your code here
    pass

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