Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-117

SVM Dual Coordinate Step

Problem

Take one projected coordinate step on the SVM dual.

Compute grad = 1 - y[j] * sum_i(alpha[i] * y[i] * K[i][j]), then set alpha[j] to alpha[j] - lr * grad clipped into [0, C]. Return the updated alpha list.

Hint

Clip the updated multiplier into the box [0, C].

Test cases

case 1
in: [[0,0],[1,-1],[[1,0.5],[0.5,1]],0,1,0.5]
expected: [0,0]
case 2
in: [[0.5,0.5],[1,1],[[2,0],[0,2]],1,1,0.5]
expected: [0.5,0.5]
case 3
in: [[1,0.2],[1,-1],[[1,0],[0,1]],1,0.5,1]
expected: [1,0]
Starter codePython
def svm_dual_coordinate_step(alpha, y, K, j, C, lr):
    # Your code here
    pass

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