How to use the nashpy.algorithms.vertex_enumeration.vertex_enumeration 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_vertex_enumeration.py View on Github external
def test_three_by_two_vertex_enumeration(self):
        A = np.array([[3, 3], [2, 5], [0, 6]])
        B = np.array([[3, 2], [2, 6], [3, 1]])

        expected_equilibria = sorted(
            [
                (np.array([1, 0, 0]), np.array([1, 0])),
                (np.array([0, 1 / 3, 2 / 3]), np.array([1 / 3, 2 / 3])),
                (np.array([4 / 5, 1 / 5, 0]), np.array([2 / 3, 1 / 3])),
            ],
            key=lambda a: list(np.round(a[0], 4)),
        )

        equilibria = sorted(
            vertex_enumeration(A, B), key=lambda a: list(np.round(a[0], 4))
        )
        for equilibrium, expected_equilibrium in zip(
            equilibria, expected_equilibria
        ):
            for strategy, expected_strategy in zip(
                equilibrium, expected_equilibrium
            ):
                self.assertTrue(all(np.isclose(strategy, expected_strategy)))
github drvinceknight / Nashpy / tests / unit / test_vertex_enumeration.py View on Github external
def test_with_negative_utilities(self):
        A = np.array([[1, -1], [-1, 1]])
        B = -A

        expected_equilibrium = (np.array([0.5, 0.5]), np.array([0.5, 0.5]))
        equilibrium = next(vertex_enumeration(A, B))
        for strategy, expected_strategy in zip(
            equilibrium, expected_equilibrium
        ):
            assert all(np.isclose(strategy, expected_strategy)), strategy