22
33def sigmoid (sop ):
44 """
5- Applies the sigmoid function.
5+ Apply the sigmoid activation function element-wise:
6+ ``sigmoid(x) = 1 / (1 + exp(-x))``.
67
7- sop: The input to which the sigmoid function is applied.
8+ Parameters
9+ ----------
10+ sop : numeric, list, tuple, or numpy.ndarray
11+ The input value(s). Lists and tuples are converted to a
12+ numpy array before computing.
813
9- Returns the result of the sigmoid function.
14+ Returns
15+ -------
16+ activated : numeric or numpy.ndarray
17+ The element-wise sigmoid of the input.
1018 """
1119
1220 if type (sop ) in [list , tuple ]:
@@ -16,11 +24,19 @@ def sigmoid(sop):
1624
1725def relu (sop ):
1826 """
19- Applies the ReLU function.
27+ Apply the ReLU activation function element-wise:
28+ ``relu(x) = max(0, x)``.
2029
21- sop: The input to which the relu function is applied.
30+ Parameters
31+ ----------
32+ sop : numeric, list, tuple, or numpy.ndarray
33+ The input value(s). Scalars are handled as a special case.
34+ Lists and tuples are converted to a numpy array.
2235
23- Returns the result of the ReLU function.
36+ Returns
37+ -------
38+ activated : numeric or numpy.ndarray
39+ The element-wise ReLU of the input.
2440 """
2541
2642 if not (type (sop ) in [list , tuple , numpy .ndarray ]):
@@ -38,10 +54,20 @@ def relu(sop):
3854
3955def softmax (layer_outputs ):
4056 """
41- Applies the softmax function.
57+ Apply a sum-normalised softmax: divide each value by the sum of
58+ all values plus a tiny constant to avoid division by zero.
4259
43- layer_outputs: The input to which the softmax function is applied.
60+ Note that this is not the canonical softmax (which uses
61+ exponentials); it just normalises the inputs so they sum to one.
4462
45- Returns the result of the softmax function.
63+ Parameters
64+ ----------
65+ layer_outputs : numpy.ndarray
66+ The values to normalise.
67+
68+ Returns
69+ -------
70+ activated : numpy.ndarray
71+ The normalised values.
4672 """
4773 return layer_outputs / (numpy .sum (layer_outputs ) + 0.000001 )
0 commit comments