All problems
PGD Attack Step
Problem
One projected gradient descent attack step: x_adv = x + alpha * sign(grad), then project each entry back into the epsilon ball [x - epsilon, x + epsilon].
The signature is pgd_step(x, grad, epsilon, alpha). Both x and grad are 2D matrices.
Hint
PGD is FGSM followed by a projection back into the allowed epsilon ball.
Test cases
case 1
in: [[[1],[1]],[[1],[1]],0.1,0.05]
expected: [[1.05],[1.05]]
case 2
in: [[[0],[1]],[[1],[1]],0.5,1]
expected: [[0.5],[1.5]]
case 3
in: [[[1],[0]],[[0],[0]],0.2,0.1]
expected: [[1],[0]]
case 4
in: [[[0.2],[1]],[[1],[1]],0.5,0.4]
expected: [[0.6],[1.4]]
Starter codePython
def pgd_step(x, grad, epsilon, alpha):
# Your code here
pass4 test cases · run your code against them in the editor