How to use the nashpy.polytope.polytope.non_trivial_vertices function in nashpy

To help you get started, we’ve selected a few nashpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github drvinceknight / Nashpy / tests / unit / test_polytope.py View on Github external
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 in vertices_generator:
            self.assertEqual(len(vertex), dimension)
            for label in labels:
                self.assertGreaterEqual(label, 0)
                self.assertLessEqual(label, number_of_strategies + dimension)
github drvinceknight / Nashpy / tests / unit / test_polytope.py View on Github external
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)
github drvinceknight / Nashpy / tests / unit / test_polytope.py View on Github external
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())