changeset 42:38aa9098bf2d

derivative of sigmoid
author Jeff Hammel <k0scist@gmail.com>
date Mon, 04 Sep 2017 14:34:00 -0700
parents 8c1648921827
children 2f0caec46e26
files tests/test_sigmoid.py tvii/sigmoid.py
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test_sigmoid.py	Mon Sep 04 14:31:25 2017 -0700
+++ b/tests/test_sigmoid.py	Mon Sep 04 14:34:00 2017 -0700
@@ -6,7 +6,7 @@
 
 import os
 import unittest
-from tvii.sigmoid import sigmoid
+from tvii.sigmoid import sigmoid, sigmoidprime
 
 
 class TestSigmoid(unittest.TestCase):
@@ -19,5 +19,9 @@
         assert answer[0] == 0.5
         assert abs(answer[1] - 0.88079708) < 1e-6
 
+    def test_derivative(self):
+
+        self.assertAlmostEqual(sigmoidprime(0), 0.25)
+
 if __name__ == '__main__':
     unittest.main()
--- a/tvii/sigmoid.py	Mon Sep 04 14:31:25 2017 -0700
+++ b/tvii/sigmoid.py	Mon Sep 04 14:34:00 2017 -0700
@@ -10,3 +10,8 @@
     if not isinstance(z, np.ndarray) and isiterable(z):
         z = np.array(z)
     return 1./(1. + np.exp(-z))
+
+
+def sigmoidprime(z):
+    """"derivative of sigmoid"""
+    return sigmoid(z)*(1-sigmoid(z))