def test_setup_one_by_one(self): left = [[-1]] right = [[1]] for process in self.processors: perceptron = Perceptron(1) self.assertTrue(perceptron.setup()) self.assertTrue(perceptron.setup(left=process(left))) self.assertTrue(perceptron.setup(right=process(right)))
def test_classify_line_zero_one_by_one(self): left = [[-1]] right = [[1]] left_test = [[-5], [-10]] right_test = [[5], [10]] for process in self.processors: perceptron = Perceptron(1) self.assertTrue(perceptron.setup()) self.assertTrue(perceptron.setup(left=process(left))) self.assertTrue(perceptron.setup(right=process(right))) for l in process(left_test): self.assertEqual(perceptron.classify_vertex(l), -1) for r in process(right_test): self.assertEqual(perceptron.classify_vertex(r), 1)
def test_unclassifiable_setup(self): left = [[-1], [1]] right = [[0]] for process in self.processors: perceptron = Perceptron(1, 0.5, 2) self.assertFalse(perceptron.setup(process(left), process(right)))
def test_wrong_setup_without_offset(self): left = [[-2]] right = [[-1]] for process in self.processors: perceptron = Perceptron(1, 0.5, 2) self.assertFalse(perceptron.setup(process(left), process(right)))
def test_setup_plane(self): left = [[-1, 1], [-2, 1]] right = [[1, 1], [2, 1]] for process in self.processors: perceptron = Perceptron(2) self.assertTrue(perceptron.setup(process(left), process(right)))
def test_classify_line_offset(self): left = [[-3, 1], [-2, 1]] right = [[-1, 1], [10, 1]] left_test = [[-3, 1], [-20, 1]] right_test = [[-1, 1], [0, 1]] for process in self.processors: perceptron = Perceptron(2) self.assertTrue(perceptron.setup(process(left), process(right))) for l in process(left + left_test): self.assertEqual(perceptron.classify_vertex(l), -1) for r in process(right + right_test): self.assertEqual(perceptron.classify_vertex(r), 1)