brainpy.math.surrogate.inv_square_grad#
- brainpy.math.surrogate.inv_square_grad(x, alpha=100.0)[source]#
Spike function with the inverse-square surrogate gradient.
Forward function:
\[\begin{split}g(x) = \begin{cases} 1, & x \geq 0 \\ 0, & x < 0 \\ \end{cases}\end{split}\]Backward function:
\[g'(x) = \frac{1}{(\alpha * |x| + 1.) ^ 2}\]>>> import brainpy as bp >>> import brainpy.math as bm >>> import matplotlib.pyplot as plt >>> xs = bm.linspace(-1, 1, 1000) >>> for alpha in [1., 10., 100.]: >>> grads = bm.vector_grad(bm.surrogate.inv_square_grad)(xs, alpha) >>> plt.plot(xs, grads, label=r'$\alpha$=' + str(alpha)) >>> plt.legend() >>> plt.show()
(
Source code
,png
,hires.png
,pdf
)