braincore.surrogate.piecewise_exp#
- braincore.surrogate.piecewise_exp(x, alpha=1.0)[source]#
Judge spiking state with a piecewise exponential 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}g(x) = \begin{cases} \frac{1}{2}e^{\alpha x}, & x < 0 \\ 1 - \frac{1}{2}e^{-\alpha x}, & x \geq 0 \end{cases}\end{split}\]Backward function:
\[g'(x) = \frac{\alpha}{2}e^{-\alpha |x|}\]>>> import braincore as bc >>> import matplotlib.pyplot as plt >>> xs = jax.numpy.linspace(-3, 3, 1000) >>> for alpha in [0.5, 1., 2., 4.]: >>> grads = bc.vector_grad(bc.surrogate.piecewise_exp)(xs, alpha) >>> plt.plot(xs, grads, label=r'$\alpha$=' + str(alpha)) >>> plt.legend() >>> plt.show()
- Parameters:
x (jax.Array, Array) – The input data.
alpha (float) – Parameter to control smoothness of gradient
- Returns:
out – The spiking state.
- Return type:
jax.Array
References