MCPcopy
hub / github.com/ddbourgin/numpy-ml / Sigmoid

Class Sigmoid

numpy_ml/neural_nets/activations/activations.py:30–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28
29
30class Sigmoid(ActivationBase):
31 def __init__(self):
32 """A logistic sigmoid activation function."""
33 super().__init__()
34
35 def __str__(self):
36 """Return a string representation of the activation function"""
37 return "Sigmoid"
38
39 def fn(self, z):
40 r"""
41 Evaluate the logistic sigmoid, :math:`\sigma`, on the elements of input `z`.
42
43 .. math::
44
45 \sigma(x_i) = \frac{1}{1 + e^{-x_i}}
46 """
47 return 1 / (1 + np.exp(-z))
48
49 def grad(self, x):
50 r"""
51 Evaluate the first derivative of the logistic sigmoid on the elements of `x`.
52
53 .. math::
54
55 \frac{\partial \sigma}{\partial x_i} = \sigma(x_i) (1 - \sigma(x_i))
56 """
57 fn_x = self.fn(x)
58 return fn_x * (1 - fn_x)
59
60 def grad2(self, x):
61 r"""
62 Evaluate the second derivative of the logistic sigmoid on the elements of `x`.
63
64 .. math::
65
66 \frac{\partial^2 \sigma}{\partial x_i^2} =
67 \frac{\partial \sigma}{\partial x_i} (1 - 2 \sigma(x_i))
68 """
69 fn_x = self.fn(x)
70 return fn_x * (1 - fn_x) * (1 - 2 * fn_x)
71
72
73class ReLU(ActivationBase):

Callers 15

plot_activationsFunction · 0.90
test_sigmoid_activationFunction · 0.90
test_sigmoid_gradFunction · 0.90
test_FullyConnectedFunction · 0.90
test_MultiplyLayerFunction · 0.90
test_AddLayerFunction · 0.90
test_Conv2DFunction · 0.90
test_Conv1DFunction · 0.90
test_Deconv2DFunction · 0.90
test_sigmoid_activationFunction · 0.90

Calls

no outgoing calls

Tested by 12

test_sigmoid_activationFunction · 0.72
test_sigmoid_gradFunction · 0.72
test_FullyConnectedFunction · 0.72
test_MultiplyLayerFunction · 0.72
test_AddLayerFunction · 0.72
test_Conv2DFunction · 0.72
test_Conv1DFunction · 0.72
test_Deconv2DFunction · 0.72
test_sigmoid_activationFunction · 0.72
test_sigmoid_gradFunction · 0.72