Skip to content

Commit 78a0f61

Browse files
sukyung99sukyung99cclauss
authored
Add Maths / Sigmoid Function (#3880)
* Add Maths / Sigmoid Function * Update Sigmoid Function * Add doctest and type hints * Fix Trim Trailing Whitespace * Fix Error * Modified Black * Update sigmoid.py Co-authored-by: sukyung99 <[email protected]> Co-authored-by: Christian Clauss <[email protected]>
1 parent c6dd975 commit 78a0f61

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Diff for: maths/sigmoid.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
This script demonstrates the implementation of the Sigmoid function.
3+
4+
The function takes a vector of K real numbers as input and then 1 / (1 + exp(-x)).
5+
After through Sigmoid, the element of the vector mostly 0 between 1. or 1 between -1.
6+
7+
Script inspired from its corresponding Wikipedia article
8+
https://en.wikipedia.org/wiki/Sigmoid_function
9+
"""
10+
11+
import numpy as np
12+
13+
14+
def sigmoid(vector: np.array) -> np.array:
15+
"""
16+
Implements the sigmoid function
17+
18+
Parameters:
19+
vector (np.array): A numpy array of shape (1,n)
20+
consisting of real values
21+
22+
Returns:
23+
sigmoid_vec (np.array): The input numpy array, after applying
24+
sigmoid.
25+
26+
Examples:
27+
>>> sigmoid(np.array([-1.0, 1.0, 2.0]))
28+
array([0.26894142, 0.73105858, 0.88079708])
29+
30+
>>> sigmoid(np.array([0.0]))
31+
array([0.5])
32+
"""
33+
return 1 / (1 + np.exp(-vector))
34+
35+
36+
if __name__ == "__main__":
37+
import doctest
38+
39+
doctest.testmod()

0 commit comments

Comments
 (0)