How to use the nashpy.algorithms.lemke_howson.lemke_howson 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_lemke_howson.py View on Github external
def test_particular_lemke_howson(self):
        A = np.array([[3, 3], [2, 5], [0, 6]])
        B = np.array([[3, 2], [2, 6], [3, 1]])
        for label, output in [
          (0, (np.array([1, 0, 0]), np.array([1, 0]))),
          (1, (np.array([0, 1 / 3,  2 / 3]), np.array([1 / 3, 2 / 3]))),
          (2, (np.array([1, 0, 0]), np.array([1, 0]))),
          (3, (np.array([1, 0, 0]), np.array([1, 0]))),
          (4, (np.array([0, 1 / 3,  2 / 3]), np.array([1 / 3, 2 / 3])))]:
            for eq, expected_eq in zip(lemke_howson(A, B, label), output):
                self.assertTrue(all(np.isclose(eq, expected_eq)))

        A = np.array([[1, -1], [-1, 1]])
        B = - A
        for label in range(4):
            for eq in lemke_howson(A, B, label):
                self.assertTrue(all(np.isclose(eq, np.array([1 / 2, 1 / 2]))),
                                msg=str(eq))
github drvinceknight / Nashpy / tests / unit / test_lemke_howson.py View on Github external
def test_particular_lemke_howson_raises_warning(self):
        """
        This is a degenerate game so the algorithm fails. 
        This was raised in
        https://github.com/drvinceknight/Nashpy/issues/35
        """
        A = np.array([[-1, -1, -1], [0, 0, 0], [-1, -1, -10000]])
        B = np.array([[-1, -1, -1], [0, 0, 0], [-1, -1, -10000]])
        with warnings.catch_warnings(record=True) as w:
            eqs = lemke_howson(A, B, initial_dropped_label=0)
            self.assertEqual(len(eqs[0]), 2)
            self.assertEqual(len(eqs[1]), 4)
            self.assertGreater(len(w), 0)
            self.assertEqual(w[-1].category, RuntimeWarning)
github drvinceknight / Nashpy / tests / unit / test_lemke_howson.py View on Github external
def test_particular_lemke_howson(self):
        A = np.array([[3, 3], [2, 5], [0, 6]])
        B = np.array([[3, 2], [2, 6], [3, 1]])
        for label, output in [
          (0, (np.array([1, 0, 0]), np.array([1, 0]))),
          (1, (np.array([0, 1 / 3,  2 / 3]), np.array([1 / 3, 2 / 3]))),
          (2, (np.array([1, 0, 0]), np.array([1, 0]))),
          (3, (np.array([1, 0, 0]), np.array([1, 0]))),
          (4, (np.array([0, 1 / 3,  2 / 3]), np.array([1 / 3, 2 / 3])))]:
            for eq, expected_eq in zip(lemke_howson(A, B, label), output):
                self.assertTrue(all(np.isclose(eq, expected_eq)))

        A = np.array([[1, -1], [-1, 1]])
        B = - A
        for label in range(4):
            for eq in lemke_howson(A, B, label):
                self.assertTrue(all(np.isclose(eq, np.array([1 / 2, 1 / 2]))),
                                msg=str(eq))