Skip to content

Commit

Permalink
add tanh activation (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoming0625 committed Apr 20, 2024
1 parent ca6fd53 commit 5b970fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions braintools/functional/_activations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import braincore as bc

__all__ = [
"tanh",
"relu",
"squareplus",
"softplus",
Expand Down Expand Up @@ -60,6 +61,22 @@
'softmin',
]

def tanh(x: ArrayLike) -> jax.Array:
r"""Hyperbolic tangent activation function.
Computes the element-wise function:
.. math::
\mathrm{tanh}(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}}
Args:
x : input array
Returns:
An array.
"""
return jnp.tanh(x)


def softmin(x, axis=-1):
r"""
Expand Down
1 change: 1 addition & 0 deletions docs/apis/functional.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Activation Functions
:nosignatures:
:template: classtemplate.rst

tanh
relu
squareplus
softplus
Expand Down

0 comments on commit 5b970fe

Please sign in to comment.