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:
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):
# 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
# 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:
# 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
>>> 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
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)
(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.
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
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)
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)