class HopfieldNetworkOperationTests(unittest.TestCase): def setUp(self): self.net = HopfieldNetwork(3) self.input_patterns = np.array([[1, -1, 1], [-1, 1, -1]]) weights = np.array([[0.0, -1.0, 1.0], [-1.0, 0.0, -1.0], [1.0, -1.0, 0.0]]) self.net.set_weights(weights) def test_calculate_neuron_output(self): neuron_output = self.net.calculate_neuron_output(0, self.input_patterns[0]) expected_neuron_output = 1.0 self.assertAlmostEqual(neuron_output, expected_neuron_output, 3) neuron_output = self.net.calculate_neuron_output(1, self.input_patterns[0]) expected_neuron_output = -1.0 self.assertAlmostEqual(neuron_output, expected_neuron_output, 3) neuron_output = self.net.calculate_neuron_output(2, self.input_patterns[0]) expected_neuron_output = 1.0 self.assertAlmostEqual(neuron_output, expected_neuron_output, 3)
class HopfieldNetworkCreationTests(unittest.TestCase): def setUp(self): self.net = HopfieldNetwork(10) def test_change_network_weights(self): new_weights = np.ones((10, 10)) self.net.set_weights(new_weights) self.assertTrue(np.array_equal(self.net.get_weights(), new_weights), "The network weights have not been updated") def test_fail_to_change_weights_when_shape_not_same_as_input_vector(self): new_weights = np.ones((5, 5)) self.assertRaises(InvalidWeightsException, self.net.set_weights, new_weights) def test_network_creation(self): self.assertEqual(self.net.get_weights().shape, (10, 10), "The networks weight array has wrong shape")
class HopfieldNetworkCreationTests(unittest.TestCase): def setUp(self): self.net = HopfieldNetwork(10) def test_change_network_weights(self): new_weights = np.ones((10, 10)) self.net.set_weights(new_weights) self.assertTrue(np.array_equal(self.net.get_weights(), new_weights), "The network weights have not been updated") def test_fail_to_change_weights_when_shape_not_same_as_input_vector(self): new_weights = np.ones((5, 5)) self.assertRaises(InvalidWeightsException, self.net.set_weights, new_weights) def test_network_creation(self): self.assertEqual(self.net.get_weights().shape, (10, 10), "The networks weight array has wrong shape")