Skip to content

Commit abc0025

Browse files
added script demonstrates the implementation of the Sigmoid function.
The sigmoid function is a logistic function, which describes growth as being initially exponential, but then slowing down and barely growing at all when a limit is reached. It's commonly used as an activation function in neural networks.
1 parent 788d95b commit abc0025

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
This script demonstrates the implementation of the Sigmoid function.
3+
4+
The sigmoid function is a logistic function, which describes growth as being initially
5+
exponential, but then slowing down and barely growing at all when a limit is reached.
6+
It's commonly used as an activation function in neural networks.
7+
8+
For more detailed information, you can refer to the following link:
9+
https://en.wikipedia.org/wiki/Sigmoid_function
10+
"""
11+
12+
import numpy as np
13+
14+
15+
def sigmoid(vector: np.ndarray) -> np.ndarray:
16+
"""
17+
Implements the sigmoid activation function.
18+
19+
Parameters:
20+
vector (np.ndarray): A vector that consists of numeric values
21+
22+
Returns:
23+
np.ndarray: Input vector after applying sigmoid activation function
24+
25+
Formula: f(x) = 1 / (1 + e^(-x))
26+
27+
Examples:
28+
>>> sigmoid(np.array([-1.0, 0.0, 1.0, 2.0]))
29+
array([0.26894142, 0.5 , 0.73105858, 0.88079708])
30+
31+
>>> sigmoid(np.array([-5.0, -2.5, 2.5, 5.0]))
32+
array([0.00669285, 0.07585818, 0.92414182, 0.99330715])
33+
"""
34+
return 1 / (1 + np.exp(-vector))
35+
36+
37+
if __name__ == "__main__":
38+
import doctest
39+
40+
doctest.testmod()

0 commit comments

Comments
 (0)