-
-
Notifications
You must be signed in to change notification settings - Fork 46.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Softplus activation function (#9944)
- Loading branch information
1 parent
c6ec99d
commit 80a2087
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Softplus Activation Function | ||
Use Case: The Softplus function is a smooth approximation of the ReLU function. | ||
For more detailed information, you can refer to the following link: | ||
https://en.wikipedia.org/wiki/Rectifier_(neural_networks)#Softplus | ||
""" | ||
|
||
import numpy as np | ||
|
||
|
||
def softplus(vector: np.ndarray) -> np.ndarray: | ||
""" | ||
Implements the Softplus activation function. | ||
Parameters: | ||
vector (np.ndarray): The input array for the Softplus activation. | ||
Returns: | ||
np.ndarray: The input array after applying the Softplus activation. | ||
Formula: f(x) = ln(1 + e^x) | ||
Examples: | ||
>>> softplus(np.array([2.3, 0.6, -2, -3.8])) | ||
array([2.39554546, 1.03748795, 0.12692801, 0.02212422]) | ||
>>> softplus(np.array([-9.2, -0.3, 0.45, -4.56])) | ||
array([1.01034298e-04, 5.54355244e-01, 9.43248946e-01, 1.04077103e-02]) | ||
""" | ||
return np.log(1 + np.exp(vector)) | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |