Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-032

Gradient Noise Injection

Problem

Add reproducible Gaussian noise to a gradient vector.

Call random.seed(seed), then add an independent random.gauss(0.0, std) draw to every component. Return the noisy gradient as a list. An empty input returns [].

Hint

Reseeding with the same seed reproduces the exact same noise draws.

Test cases

case 1
in: [[1,2,3],0.1,0]
expected: [1.0941715404680665,1.860342189529885,2.932028555192158]
case 2
in: [[0.5,-0.5],0.2,7]
expected: [0.4488239423104799,-0.3977136974966972]
case 3
in: [[0],1,42]
expected: [-0.14409032957792836]
case 4
in: [[],0.1,3]
expected: []
Starter codePython
def add_gradient_noise(grads, std, seed):
    # Your code here
    pass

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