Skip to content
DeepForgeby svx
All problems
EasyCalculusca-196

Surrogate Gradient

Problem

Spiking neural networks replace the derivative of the Heaviside spike with a smooth surrogate. A common choice is the derivative of arctan(k*x):

g(x) = k / (1 + (k*x)^2)

Given x and the sharpness k > 0, return g(x).

Hint

The surrogate is symmetric and peaks at x = 0 with value k.

Test cases

case 1
in: [0,5]
expected: 5
case 2
in: [0.1,5]
expected: 4
case 3
in: [-0.1,5]
expected: 4
case 4
in: [1,1]
expected: 0.5
case 5
in: [0.5,2]
expected: 1
Starter codePython
def surrogate_gradient(x, scale):
    # Your code here
    pass

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