brainpy.math.surrogate.gaussian_grad

Contents

brainpy.math.surrogate.gaussian_grad#

brainpy.math.surrogate.gaussian_grad(x, sigma=0.5, alpha=0.5)[source]#

Spike function with the Gaussian gradient function [1].

The forward function:

\[\begin{split}g(x) = \begin{cases} 1, & x \geq 0 \\ 0, & x < 0 \\ \end{cases}\end{split}\]

Backward function:

\[g'(x) = \alpha * \text{gaussian}(x, 0., \sigma)\]
>>> import brainpy as bp
>>> import brainpy.math as bm
>>> import matplotlib.pyplot as plt
>>> xs = bm.linspace(-3, 3, 1000)
>>> bp.visualize.get_figure(1, 1, 4, 6)
>>> for s in [0.5, 1., 2.]:
>>>   grads = bm.vector_grad(bm.surrogate.gaussian_grad)(xs, s, 0.5)
>>>   plt.plot(bm.as_numpy(xs), bm.as_numpy(grads), label=r'$\alpha=0.5, \sigma=$' + str(s))
>>> plt.legend()
>>> plt.show()

(Source code, png, hires.png, pdf)

../../_images/brainpy-math-surrogate-gaussian_grad-1.png
Parameters:
  • x (jax.Array, Array) – The input data.

  • sigma (float) – The parameter to control the variance of gaussian distribution.

  • alpha (float) – The parameter to control the scale of the gradient.

Returns:

out – The spiking state.

Return type:

jax.Array

References