Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-249

SAM Sharpness Estimate

Problem

Estimate the local sharpness of the loss from a SAM ascent step.

Return (loss_adv - loss_clean) / rho, the loss increase per unit perturbation. If rho is not positive, return 0.0.

Hint

A larger loss increase over the same perturbation means a sharper minimum.

Test cases

case 1
in: [0.5,0.7,0.1]
expected: 1.9999999999999996
case 2
in: [1,0.9,0.05]
expected: -1.9999999999999996
case 3
in: [2,2,0.2]
expected: 0
case 4
in: [1,1.5,0]
expected: 0
Starter codePython
def sam_sharpness_estimate(loss_clean, loss_adv, rho):
    # Your code here
    pass

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