brainpy.math.surrogate.arctan

Contents

brainpy.math.surrogate.arctan#

brainpy.math.surrogate.arctan(x, alpha=1.0)[source]#

Judge spiking state with an arctan function.

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:

\[g(x) = \frac{1}{\pi} \arctan(\frac{\pi}{2}\alpha x) + \frac{1}{2}\]

Backward function:

\[g'(x) = \frac{\alpha}{2(1 + (\frac{\pi}{2}\alpha x)^2)}\]
>>> 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)
>>> for alpha in [0.5, 1., 2., 4.]:
>>>   grads = bm.vector_grad(bm.surrogate.arctan)(xs, alpha)
>>>   plt.plot(xs, grads, label=r'$\alpha$=' + str(alpha))
>>> plt.legend()
>>> plt.show()

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

../../_images/brainpy-math-surrogate-arctan-1.png
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