def test_sigma(self): self.assertAlmostEqual(Sigmoid.activation(0), 0.5, places=2) self.assertAlmostEqual(Sigmoid.activation(50), 1, places=2) self.assertAlmostEqual(Sigmoid.activation(-50), 0, places=2) self.assertAlmostEqual(Sigmoid.activation(1), 0.731, places=2) self.assertAlmostEqual(Sigmoid.activation(-1), 0.2689, places=2)
def test_sigma_prime(self): self.assertAlmostEqual(Sigmoid.gradient(0), 0.25, places=3) self.assertAlmostEqual(Sigmoid.gradient(-50), 0, places=3) self.assertAlmostEqual(Sigmoid.gradient(50), 0, places=3) self.assertAlmostEqual(Sigmoid.gradient(50), Sigmoid.activation(50) * (1 - Sigmoid.activation(50)), places=3)
def test_get_final_layer_error_for_1_element_vectors(self): cross_entropy = cost_functions.CrossEntropyCost(self.net) z_last = np.array([3], float) z_last_prime = Sigmoid.gradient(z_last) y = np.array([0], float) a_last = Sigmoid.activation(z_last) nabla = cross_entropy.get_final_layer_error(a_last, y, z_last_prime) self.assertAlmostEqual(nabla[0], (a_last - y), places=2) z_last = np.array([-1], float) z_last_prime = Rectifier.gradient(z_last) y = np.array([0.5], float) a_last = Sigmoid.activation(z_last) nabla = cross_entropy.get_final_layer_error(a_last, y, z_last_prime) self.assertAlmostEqual(nabla[0], (a_last - y), places=2)
def test_get_final_layer_error_for_arrays(self): quadratic = cost_functions.QuadraticCost(neural_net=self.net) z_last = np.array([3, -1], float) z_last_prime = Sigmoid.gradient(z_last) y = np.array([0, 0.5], float) a_last = Sigmoid.activation(z_last) nabla = quadratic.get_final_layer_error(a_last, y, z_last_prime) self.assertAlmostEqual(nabla[0], (a_last[0] - y[0]) * z_last_prime[0], places=2) self.assertAlmostEqual(nabla[1], (a_last[1] - y[1]) * Sigmoid.gradient(z_last[1]), places=2)