Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-236

LAMB Trust Ratio Clamp

Problem

Compute the LAMB trust ratio and clamp it to a maximum.

Return min(max_ratio, ||w|| / (||u|| + eps)), where w is the weight vector and u is the raw update vector. Clamping stops a single layer from taking an oversized coordinated step.

Hint

Only the ratio above max_ratio is clipped; small ratios pass through.

Test cases

case 1
in: [[3,4],[0,1],1e-8,5]
expected: 4.999999950000001
case 2
in: [[1,1],[2,2],0,10]
expected: 0.5
case 3
in: [[1,1],[0.01,0.01],1e-8,2]
expected: 2
case 4
in: [[0,0],[1,1],1e-8,4]
expected: 0
Starter codePython
def lamb_trust_ratio_clamp(w, u, eps, max_ratio):
    # Your code here
    pass

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