Skip to content

feat: add softsign activation function #11710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions neural_network/activation_functions/softsign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Softsign activation function

Use Case: Softsign provides a smooth transition without sharp gradients
and is an alternative to sigmoid functions.

For more detailed information, you can refer to the following link:
https://paperswithcode.com/method/softsign-activation
"""

import numpy as np


def softsign(vector: np.ndarray) -> np.ndarray:
"""
Implements the Softsign Activation Function.

Parameters:
vector (np.ndarray): The input array for Softsign activation.

Returns:
np.ndarray: The output after applying Softsign activation.

Formula: f(x) = x / (1 + |x|)

Examples:
>>> softsign(np.array([-10, -5, -1, 0 ,1 ,5 ,10]))
array([-0.90909091, -0.83333333, -0.5 , 0. , 0.5 ,
0.83333333, 0.90909091])

>>> softsign(np.array([100]))
array([0.99009901])

"""
return vector / (1 + np.abs(vector))


if __name__ == "__main__":
import doctest

doctest.testmod()