class TestForMultipleHiddenLayers(unittest.TestCase): def setUp(self): self.patcher = patch('builtins.print') self.mock_object = self.patcher.start() self.x_test = np.array([[1], [0]]) self.y_test = np.array([[1], [0]]) self.hidden_node_biases = [0.10399593413625441, 0.9477095968224993] self.output_node_biases = [0.1683069001902736] self.weights = [ 0.08946817286422626, 0.10066428298027419, 0.8768683269443115 ] self.net = NeuralNet(1, 4, 1, 1, self.hidden_node_biases, self.output_node_biases, self.weights, learning_rate=0.01) def tearDown(self): self.patcher.stop() def test_weights(self): self.assertEqual(self.net.get_weights(), self.weights) def test_biases(self): self.assertEqual( self.net.get_biases(), [0.10399593413625441, 0.9477095968224993, 0.1683069001902736]) def test_partial_derivatives_for_biases(self): self.net.train(self.x_test, self.y_test, 1) self.assertEqual( self.net.get_biases(), [0.10397901969529151, 0.9470426291307198, 0.16445586456466701]) def test_partial_derivatives_for_weights(self): self.net.train(self.x_test, self.y_test, 1) self.assertEqual( self.net.get_weights(), [0.08948139076478426, 0.10032526109304217, 0.8740529208576437])
class TestForMultipleOutputs(unittest.TestCase): def setUp(self): self.patcher = patch('builtins.print') self.mock_object = self.patcher.start() self.x_test = np.array([[1, 0], [0, 1], [0, 0], [1, 1]]) self.y_test = np.array([[0, 1], [0, 1], [1, 0], [1, 0]]) self.hidden_node_biases = [2, 2] self.output_node_biases = [3, 3] self.weights = [5, 5, 5, 5, 5, 5, 5, 5] self.net = NeuralNet(2, 3, 2, 2, self.hidden_node_biases, self.output_node_biases, self.weights, activation_function=ActivationFunction.LOG, learning_rate=0.01) def tearDown(self): self.patcher.stop() def test_weights(self): self.assertEqual(self.net.get_weights(), self.weights) def test_biases(self): self.assertEqual(self.net.get_biases(), [2, 2, 3, 3]) def test_partial_derivatives_for_biases(self): self.net.train(self.x_test, self.y_test, 1) self.assertEqual(self.net.get_biases(), [ 2.000000000000002, 2.000000000000002, 3.0000000257168224, 2.99999997428318 ]) def test_partial_derivatives_for_weights(self): self.net.train(self.x_test, self.y_test, 1) self.assertEqual(self.net.get_weights(), [ 5.0, 5.0, 5.0, 5.0, 5.000000021300251, 4.999999978699751, 5.000000021300251, 4.999999978699751 ])