Skip to content

Commit d5f02bc

Browse files
author
sukyung99
committed
Add Maths / Sigmoid Function
1 parent eb5a951 commit d5f02bc

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

maths/sigmoid.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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: float):
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+
23+
Returns:
24+
sigmoid_vec (np.array): The input numpy array, after applying
25+
sigmoid.
26+
27+
>>> vec = np.array([-1.0, 1.0, 2.0])
28+
>>> sigmoid(vec)
29+
array([0.26894142, 0.73105858, 0.88079708])
30+
"""
31+
32+
return 1 / (1 + np.exp(-vector))
33+
34+
35+
if __name__ == "__main__":
36+
print(
37+
sigmoid(np.array([-1.0, 1.0, 2.0]))
38+
) # --> [0.26894142, 0.73105858, 0.88079708]

0 commit comments

Comments
 (0)