From: Michael Orlitzky Date: Wed, 12 Oct 2016 19:37:05 +0000 (-0400) Subject: Add tests for the orthogonality relationships of a game solution. X-Git-Tag: 0.1.0~156 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=9da611019b85e58ecab8450f9a9043c6f4a184d1;p=dunshire.git Add tests for the orthogonality relationships of a game solution. --- diff --git a/src/dunshire/games.py b/src/dunshire/games.py index 3c53343..76fbf7d 100644 --- a/src/dunshire/games.py +++ b/src/dunshire/games.py @@ -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)