]> gitweb.michael.orlitzky.com - dunshire.git/blobdiff - src/dunshire/games.py
Add a test for the value of a positive operator on the nonnegative orthant.
[dunshire.git] / src / dunshire / games.py
index 3c53343175c11421413eed9cfe0ae26518d9799f..692a0ae550305c3ae56833d500c263498f070889 100644 (file)
@@ -763,3 +763,62 @@ class SymmetricLinearGameTest(TestCase):
         """
         (L, K, e1, e2) = _random_icecream_params()
         self.assert_opposite_game_works(L, K, e1, e2)
+
+
+    def assert_orthogonality(self, L, K, e1, e2):
+        """
+        Two orthogonality relations hold at an optimal solution, and we
+        check them here.
+        """
+        game = SymmetricLinearGame(L, K, e1, e2)
+        soln = game.solution()
+        x_bar = soln.player1_optimal()
+        y_bar = soln.player2_optimal()
+        value = soln.game_value()
+
+        # Make these matrices so that we can compute with them.
+        L = matrix(L).trans()
+        e1 = matrix(e1, (K.dimension(), 1))
+        e2 = matrix(e2, (K.dimension(), 1))
+
+        ip1 = inner_product(y_bar, L*x_bar - value*e1)
+        self.assert_within_tol(ip1, 0)
+
+        ip2 = inner_product(value*e2 - L.trans()*y_bar, x_bar)
+        self.assert_within_tol(ip2, 0)
+
+
+    def test_orthogonality_orthant(self):
+        """
+        Check the orthgonality relationships that hold for a solution
+        over the nonnegative orthant.
+        """
+        (L, K, e1, e2) = _random_orthant_params()
+        self.assert_orthogonality(L, K, e1, e2)
+
+
+    def test_orthogonality_icecream(self):
+        """
+        Check the orthgonality relationships that hold for a solution
+        over the ice-cream cone.
+        """
+        (L, K, e1, e2) = _random_icecream_params()
+        self.assert_orthogonality(L, K, e1, e2)
+
+
+    def test_positive_operator_value(self):
+        """
+        Test that a positive operator on the nonnegative orthant gives
+        rise to a a game with a nonnegative value.
+
+        This test theoretically applies to the ice-cream cone as well,
+        but we don't know how to make positive operators on that cone.
+        """
+        (L, K, e1, e2) = _random_orthant_params()
+
+        # Make the entries of ``L`` nonnegative... this makes it a
+        # positive operator on ``K``.
+        L = [[abs(entry) for entry in row] for row in L]
+
+        game = SymmetricLinearGame(L, K, e1, e2)
+        self.assertTrue(game.solution().game_value() >= -options.ABS_TOL)