File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments