Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-098

Huber IRLS Weight

Problem

Compute the Huber IRLS weight for a residual.

Return 1.0 when abs(residual) <= delta, otherwise delta / abs(residual). Outliers receive a weight that decays like the reciprocal of their residual.

Hint

Inliers are weighted fully; outliers are downweighted proportionally.

Test cases

case 1
in: [0.5,1]
expected: 1
case 2
in: [2,1]
expected: 0.5
case 3
in: [-3,2]
expected: 0.6666666666666666
case 4
in: [0,1]
expected: 1
Starter codePython
def huber_irls_weight(residual, delta):
    # Your code here
    pass

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