]> gitweb.michael.orlitzky.com - dunshire.git/commitdiff
Add tests for the orthogonality relationships of a game solution.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 12 Oct 2016 19:37:05 +0000 (15:37 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 12 Oct 2016 19:37:05 +0000 (15:37 -0400)
src/dunshire/games.py

index 3c53343175c11421413eed9cfe0ae26518d9799f..76fbf7deedfec733bf4213bec000bdf449087e75 100644 (file)
@@ -763,3 +763,44 @@ 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)