Example #1
0
    def test_labelling_of_particular_vertices(self):
        A = np.array([[3, 3], [2, 5], [0, 6]])
        halfspaces = build_halfspaces(A)
        vertices = non_trivial_vertices(halfspaces)
        expected_labels = sorted(
            [set([0, 1]), set([0, 4]), set([1, 2]), set([2, 3])], key=list
        )
        labels_ = sorted((labels(v, halfspaces) for v, l in vertices), key=list)
        for label, expected_label in zip(labels_, expected_labels):
            self.assertTrue(
                np.array_equal(label, expected_label),
                msg="{} != {}".format(label, expected_label),
            )

        B = np.array([[3, 2], [2, 6], [3, 1]])
        halfspaces = build_halfspaces(B.transpose())
        vertices = non_trivial_vertices(halfspaces)
        expected_labels = sorted(
            [
                set([0, 2, 3]),
                set([0, 3, 4]),
                set([0, 1, 2]),
                set([1, 2, 4]),
                set([0, 1, 4]),
            ],
            key=list,
        )

        labels_ = sorted((labels(v, halfspaces) for v, l in vertices), key=list)
        for label, expected_label in zip(labels_, expected_labels):
            self.assertTrue(
                np.array_equal(label, expected_label),
                msg="{} != {}".format(label, expected_label),
            )
Example #2
0
    def test_creation_of_particular_non_trivial_vertices(self):
        """Test that vertices are obtained"""
        A = np.array([[3, 3], [2, 5], [0, 6]])
        halfspaces = build_halfspaces(A)
        vertices_generator = non_trivial_vertices(halfspaces)
        self.assertIsInstance(vertices_generator, GeneratorType)

        expected_vertices = sorted(
            [
                np.array([1 / 3, 0]),
                np.array([0, 1 / 6]),
                np.array([2 / 9, 1 / 9]),
                np.array([1 / 12, 1 / 6]),
            ],
            key=lambda a: list(np.round(a, 5)),
        )

        vertices = sorted(
            (v for v, l in vertices_generator),
            key=lambda a: list(np.round(a, 5)),
        )

        for vertex, expected_vertex in zip(vertices, expected_vertices):
            self.assertTrue(all(np.isclose(vertex, expected_vertex)))

        B = np.array([[3, 2], [2, 6], [3, 1]])
        halfspaces = build_halfspaces(B.transpose())
        vertices_generator = non_trivial_vertices(halfspaces)
        self.assertIsInstance(vertices_generator, GeneratorType)

        expected_vertices = sorted(
            [
                np.array([0, 0, 1 / 3]),
                np.array([0, 1 / 8, 1 / 4]),
                np.array([0, 1 / 6, 0]),
                np.array([2 / 7, 1 / 14, 0]),
                np.array([1 / 3, 0, 0]),
            ],
            key=lambda a: list(np.round(a, 5)),
        )

        vertices = sorted(
            (v for v, l in vertices_generator),
            key=lambda a: list(np.round(a, 5)),
        )

        for vertex, expected_vertex in zip(vertices, expected_vertices):
            self.assertTrue(
                all(np.isclose(vertex, expected_vertex)),
                msg="{} != {}".format(vertex, expected_vertex),
            )
Example #3
0
 def test_creation_of_non_trivial_vertices(self, A):
     """Test that can create a bi matrix game"""
     halfspaces = build_halfspaces(A)
     vertices_generator = non_trivial_vertices(halfspaces)
     number_of_strategies, dimension = A.shape
     self.assertIsInstance(vertices_generator, GeneratorType)
     for vertex, labels_set in vertices_generator:
         self.assertEqual(len(vertex), dimension)
         for label in labels_set:
             self.assertGreaterEqual(label, 0)
             self.assertLessEqual(label, number_of_strategies + dimension)