brainpy.math.surrogate.s2nn#
- brainpy.math.surrogate.s2nn(x, alpha=4.0, beta=1.0, epsilon=1e-08)[source]#
Judge spiking state with the S2NN surrogate spiking function [1].
If origin=False, computes 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:
\[\begin{split} \begin{split}g(x) = \begin{cases} \mathrm{sigmoid} (\alpha x), x < 0 \\ \beta \ln(|x + 1|) + 0.5, x \ge 0 \end{cases}\end{split}\end{split}\]Backward function:
\[\begin{split} \begin{split}g'(x) = \begin{cases} \alpha * (1 - \mathrm{sigmoid} (\alpha x)) \mathrm{sigmoid} (\alpha x), x < 0 \\ \frac{\beta}{(x + 1)}, x \ge 0 \end{cases}\end{split}\end{split}\]>>> 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(-3, 3, 1000) >>> grads = bm.vector_grad(bm.surrogate.s2nn)(xs, 4., 1.) >>> plt.plot(bm.as_numpy(xs), bm.as_numpy(grads), label=r'$\alpha=4, \beta=1$') >>> grads = bm.vector_grad(bm.surrogate.s2nn)(xs, 8., 2.) >>> plt.plot(bm.as_numpy(xs), bm.as_numpy(grads), label=r'$\alpha=8, \beta=2$') >>> plt.legend() >>> plt.show()
(
Source code
,png
,hires.png
,pdf
)- Parameters:
- Returns:
out – The spiking state.
- Return type:
jax.Array
References