Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-294

Quadratic Penalty Gradient Step

Problem

For the penalized objective f(x) = x^2 + mu * max(0, g)^2 with a scalar constraint value g, the gradient is 2x + 2 mu g when g > 0 and 2x otherwise.

Given x, the learning rate lr, the penalty mu, and g, return the updated x after one step.

Hint

The penalty term only contributes inside the feasible violation.

Test cases

case 1
in: [1,0.1,2,1]
expected: 0.3999999999999999
case 2
in: [0,0.5,1,-3]
expected: 0
case 3
in: [2,0.25,4,0.5]
expected: 0
Starter codePython
def quadratic_penalty_gradient_step(x, lr, mu, g):
    # Your code here
    pass

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