Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-081

Quantile Gradient Step

Problem

Take one gradient step for the pinball (quantile) loss with target quantile q.

Let residual = w * x - y; the subgradient factor is q - 1 when residual < 0 and q otherwise. Return w - lr * factor * x.

Hint

The pinball subgradient is q - 1 below the target and q above it.

Test cases

case 1
in: [1,2,1,0.5,0.1]
expected: 0.9
case 2
in: [0,1,2,0.5,0.1]
expected: 0.05
case 3
in: [1,1,1,0.9,0.2]
expected: 0.82
case 4
in: [-1,2,-3,0.1,0.1]
expected: -1.02
Starter codePython
def quantile_gradient_step(w, x, y, q, lr):
    # Your code here
    pass

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