]> gitweb.michael.orlitzky.com - dunshire.git/commitdiff
Rename epsilon_scale() to tolerance_scale().
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 13 Nov 2016 19:51:27 +0000 (14:51 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 13 Nov 2016 20:19:27 +0000 (15:19 -0500)
dunshire/games.py
test/symmetric_linear_game_test.py

index 719198b7007896c0eb68df23ab91d6456888fb12..07a70b0a2b651a40c207d5d3bcdfd807d55f92df 100644 (file)
@@ -9,9 +9,9 @@ from .cones import CartesianProduct
 from .errors import GameUnsolvableException, PoorScalingException
 from .matrices import (append_col, append_row, condition_number, identity,
                        inner_product, norm, specnorm)
-from . import options
+from .options import ABS_TOL, FLOAT_FORMAT, DEBUG_FLOAT_FORMAT
 
-printing.options['dformat'] = options.FLOAT_FORMAT
+printing.options['dformat'] = FLOAT_FORMAT
 
 
 class Solution:
@@ -854,13 +854,13 @@ class SymmetricLinearGame:
             self._L_specnorm_value = specnorm(self.L())
         return self._L_specnorm_value
 
-    def epsilon_scale(self, solution):
+    def tolerance_scale(self, solution):
         # Don't return anything smaller than 1... we can't go below
         # out "minimum tolerance."
         norm_p1_opt = norm(solution.player1_optimal())
         norm_p2_opt = norm(solution.player2_optimal())
         scale = self._L_specnorm()*(norm_p1_opt + norm_p2_opt)
-        return max(1, scale)
+        return max(1, scale/2.0)
 
 
     def solution(self):
@@ -1032,7 +1032,7 @@ class SymmetricLinearGame:
                 # Oops, CVXOPT tried to take the square root of a
                 # negative number. Report some details about the game
                 # rather than just the underlying CVXOPT crash.
-                printing.options['dformat'] = options.DEBUG_FLOAT_FORMAT
+                printing.options['dformat'] = DEBUG_FLOAT_FORMAT
                 raise PoorScalingException(self)
             else:
                 raise error
@@ -1057,7 +1057,7 @@ class SymmetricLinearGame:
         # that CVXOPT is convinced the problem is infeasible (and that
         # cannot happen).
         if soln_dict['status'] in ['primal infeasible', 'dual infeasible']:
-            printing.options['dformat'] = options.DEBUG_FLOAT_FORMAT
+            printing.options['dformat'] = DEBUG_FLOAT_FORMAT
             raise GameUnsolvableException(self, soln_dict)
 
         # For the game value, we could use any of:
@@ -1085,14 +1085,14 @@ class SymmetricLinearGame:
         # it) because otherwise CVXOPT might return "unknown" and give
         # us two points in the cone that are nowhere near optimal.
         #
-        if abs(p1_value - p2_value) > self.epsilon_scale(soln)*options.ABS_TOL:
-            printing.options['dformat'] = options.DEBUG_FLOAT_FORMAT
+        if abs(p1_value - p2_value) > self.tolerance_scale(soln)*ABS_TOL:
+            printing.options['dformat'] = DEBUG_FLOAT_FORMAT
             raise GameUnsolvableException(self, soln_dict)
 
         # And we also check that the points it gave us belong to the
         # cone, just in case...
         if (p1_optimal not in self._K) or (p2_optimal not in self._K):
-            printing.options['dformat'] = options.DEBUG_FLOAT_FORMAT
+            printing.options['dformat'] = DEBUG_FLOAT_FORMAT
             raise GameUnsolvableException(self, soln_dict)
 
         return soln
@@ -1126,10 +1126,8 @@ class SymmetricLinearGame:
         >>> e1 = [1]
         >>> e2 = e1
         >>> SLG = SymmetricLinearGame(L, K, e1, e2)
-        >>> actual = SLG.condition()
-        >>> expected = 1.8090169943749477
-        >>> abs(actual - expected) < options.ABS_TOL
-        True
+        >>> SLG.condition()
+        1.809...
 
         """
         return (condition_number(self._G()) + condition_number(self.A()))/2
index 067aaa15e6196e6120b9f613f2982847f08e9c71..b9c29fe68056f52da980443809e881ce6faa28ad 100644 (file)
@@ -141,8 +141,8 @@ class SymmetricLinearGameTest(TestCase): # pylint: disable=R0904
         soln2 = H.solution()
         value1 = soln1.game_value()
         value2 = soln2.game_value()
-        modifier1 = G.epsilon_scale(soln1)
-        modifier2 = H.epsilon_scale(soln2)
+        modifier1 = G.tolerance_scale(soln1)
+        modifier2 = H.tolerance_scale(soln2)
         modifier = max(modifier1, modifier2)
         self.assert_within_tol(alpha*value1, value2, modifier)
 
@@ -182,7 +182,7 @@ class SymmetricLinearGameTest(TestCase): # pylint: disable=R0904
         (alpha, H) = random_translation(G)
         value2 = H.solution().game_value()
 
-        modifier = G.epsilon_scale(soln1)
+        modifier = G.tolerance_scale(soln1)
         self.assert_within_tol(value1 + alpha, value2, modifier)
 
         # Make sure the same optimal pair works.
@@ -225,7 +225,7 @@ class SymmetricLinearGameTest(TestCase): # pylint: disable=R0904
         y_bar = soln1.player2_optimal()
         soln2 = H.solution()
 
-        mod = G.epsilon_scale(soln1)
+        mod = G.tolerance_scale(soln1)
         self.assert_within_tol(-soln1.game_value(), soln2.game_value(), mod)
 
         # Make sure the switched optimal pair works. Since x_bar and
@@ -265,7 +265,7 @@ class SymmetricLinearGameTest(TestCase): # pylint: disable=R0904
         ip1 = inner_product(y_bar, G.L()*x_bar - value*G.e1())
         ip2 = inner_product(value*G.e2() - G.L().trans()*y_bar, x_bar)
 
-        modifier = G.epsilon_scale(soln)
+        modifier = G.tolerance_scale(soln)
         self.assert_within_tol(ip1, 0, modifier)
         self.assert_within_tol(ip2, 0, modifier)
 
@@ -324,7 +324,7 @@ class SymmetricLinearGameTest(TestCase): # pylint: disable=R0904
             self.assertTrue(negative_stable)
 
         dualsoln = G.dual().solution()
-        mod = G.epsilon_scale(soln)
+        mod = G.tolerance_scale(soln)
         self.assert_within_tol(dualsoln.game_value(), soln.game_value(), mod)