Esempio n. 1
0
    def test_representative(self):
        expected = 0.880797
        actual = sigmoid(2)
        self.assertAlmostEqual(expected, actual, places=6)

        expected = 0.268941
        actual = sigmoid(-1)
        self.assertAlmostEqual(expected, actual, places=6)
Esempio n. 2
0
    def test_infinity(self):
        expected = 1
        actual = sigmoid(float('inf'))
        self.assertEqual(expected, actual)

        expected = 0
        actual = sigmoid(-float('inf'))
        self.assertEqual(expected, actual)
Esempio n. 3
0
def predict(network, x):
    W1, W2, W3 = network['W1'], network['W2'], network['W3']
    b1, b2, b3 = network['b1'], network['b2'], network['b3']

    a1 = np.dot(x, W1) + b1
    z1 = sigmoid(a1)
    a2 = np.dot(z1, W2) + b2
    z2 = sigmoid(a2)
    a3 = np.dot(z2, W3) + b3
    y = softmax(a3)

    return y
Esempio n. 4
0
 def test_supports_ndarray(self):
     expected = np.array([0.268941, 0.5, 0.731059])
     actual = sigmoid(np.array([-1, 0, 1]))
     np.testing.assert_allclose(expected, actual, atol=1e-6)
 def test_representative(self):
     expected = 0.952574
     actual = sigmoid(3)
     places = len(str(expected).split('.')[1])
     self.assertAlmostEqual(expected, actual, places=places)
Esempio n. 6
0
def swish(x):
    return np.nan_to_num(x * sigmoid(x),
                         nan=0.0,
                         posinf=np.inf,
                         neginf=-np.inf)