brainpy.math.surrogate.sigmoid#
- brainpy.math.surrogate.sigmoid(x, alpha=4.0, origin=False)[source]#
Spike function with the sigmoid-shaped surrogate gradient.
If origin=False, return the forward function:
\[\begin{split}g(x) = \begin{cases} 1, & x \geq 0 \\ 0, & x < 0 \\ \end{cases}\end{split}\]If origin=True, computes the original function:
\[g(x) = \mathrm{sigmoid}(\alpha x) = \frac{1}{1+e^{-\alpha x}}\]Backward function:
\[g'(x) = \alpha * (1 - \mathrm{sigmoid} (\alpha x)) \mathrm{sigmoid} (\alpha x)\]>>> import brainpy as bp >>> import brainpy.math as bm >>> import matplotlib.pyplot as plt >>> bp.visualize.get_figure(1, 1, 4, 6) >>> xs = bm.linspace(-2, 2, 1000) >>> for alpha in [1., 2., 4.]: >>> grads = bm.vector_grad(bm.surrogate.sigmoid)(xs, alpha) >>> plt.plot(xs, grads, label=r'$\alpha$=' + str(alpha)) >>> plt.legend() >>> plt.show()
(
Source code
,png
,hires.png
,pdf
)