All problems
Lasso Coordinate Descent Sweep
Problem
For a Lasso objective 0.5 * ||A x - b||^2 + lambda * ||x||_1, one coordinate update sets x_j = soft(a_j dot r_j, lambda) / ||a_j||^2, where a_j is column j and r_j = b - sum_{k != j} a_k x_k.
Given A as nested rows, b, x, and lambda, perform one full sweep in order and return the updated x.
Hint
Use the partial residual with all other coordinates fixed.
Test cases
case 1
in: [[[1,0],[0,1]],[1,-2],[0.5,0.5],0.1]
expected: [0.9,-1.9]
case 2
in: [[[1,1]],[2],[1,0],0.5]
expected: [1.5,0]
case 3
in: [[[2,0],[0,2]],[3,4],[0,0],0.25]
expected: [1.4375,1.9375]
Starter codePython
def lasso_coordinate_descent_sweep(a, b, x, lam):
# Your code here
pass3 test cases · run your code against them in the editor