from dunshire.games import SymmetricLinearGame
from dunshire.matrices import (append_col, append_row, identity)
-MAX_COND = 250
+MAX_COND = 125
"""
-The maximum condition number of a randomly-generated game.
+The maximum condition number of a randomly-generated game. When the
+condition number of the games gets too high, we start to see
+:class:`PoorScalingException` being thrown. There's no science to
+choosing the upper bound -- it got lowered until those exceptions
+stopped popping up. It's at ``125`` because ``129`` doesn't work.
"""
RANDOM_MAX = 10
"""
G = random_orthant_game()
- L = random_diagonal_matrix(G._K.dimension())
+ L = random_diagonal_matrix(G.dimension())
# Replace the totally-random ``L`` with random Lyapunov-like one.
- G = SymmetricLinearGame(L, G._K, G._e1, G._e2)
+ G = SymmetricLinearGame(L, G.K(), G.e1(), G.e2())
while G.condition() > MAX_COND:
# Try again until the condition number is satisfactory.
G = random_orthant_game()
- L = random_diagonal_matrix(G._K.dimension())
- G = SymmetricLinearGame(L, G._K, G._e1, G._e2)
+ L = random_diagonal_matrix(G.dimension())
+ G = SymmetricLinearGame(L, G.K(), G.e1(), G.e2())
return G
"""
G = random_icecream_game()
- L = random_lyapunov_like_icecream(G._K.dimension())
+ L = random_lyapunov_like_icecream(G.dimension())
# Replace the totally-random ``L`` with random Lyapunov-like one.
- G = SymmetricLinearGame(L, G._K, G._e1, G._e2)
+ G = SymmetricLinearGame(L, G.K(), G.e1(), G.e2())
while G.condition() > MAX_COND:
# Try again until the condition number is satisfactory.
G = random_icecream_game()
- L = random_lyapunov_like_icecream(G._K.dimension())
- G = SymmetricLinearGame(L, G._K, G._e1, G._e2)
+ L = random_lyapunov_like_icecream(G.dimension())
+ G = SymmetricLinearGame(L, G.K(), G.e1(), G.e2())
return G
"""
G = random_orthant_game()
- L = random_nonnegative_matrix(G._K.dimension())
+ L = random_nonnegative_matrix(G.dimension())
# Replace the totally-random ``L`` with the random nonnegative one.
- G = SymmetricLinearGame(L, G._K, G._e1, G._e2)
+ G = SymmetricLinearGame(L, G.K(), G.e1(), G.e2())
while G.condition() > MAX_COND:
# Try again until the condition number is satisfactory.
G = random_orthant_game()
- L = random_nonnegative_matrix(G._K.dimension())
- G = SymmetricLinearGame(L, G._K, G._e1, G._e2)
+ L = random_nonnegative_matrix(G.dimension())
+ G = SymmetricLinearGame(L, G.K(), G.e1(), G.e2())
return G
>>> (alpha, H) = random_nn_scaling(G)
>>> alpha >= 0
True
- >>> G._K == H._K
+ >>> G.K() == H.K()
True
- >>> norm(G._e1 - H._e1) < ABS_TOL
+ >>> norm(G.e1() - H.e1()) < ABS_TOL
True
- >>> norm(G._e2 - H._e2) < ABS_TOL
+ >>> norm(G.e2() - H.e2()) < ABS_TOL
True
"""
alpha = random_nn_scalar()
- H = SymmetricLinearGame(alpha*G._L.trans(), G._K, G._e1, G._e2)
+ H = SymmetricLinearGame(alpha*G.L().trans(), G.K(), G.e1(), G.e2())
while H.condition() > MAX_COND:
# Loop until the condition number of H doesn't suck.
alpha = random_nn_scalar()
- H = SymmetricLinearGame(alpha*G._L.trans(), G._K, G._e1, G._e2)
+ H = SymmetricLinearGame(alpha*G.L().trans(), G.K(), G.e1(), G.e2())
return (alpha, H)
>>> from dunshire.options import ABS_TOL
>>> G = random_orthant_game()
>>> (alpha, H) = random_translation(G)
- >>> G._K == H._K
+ >>> G.K() == H.K()
True
- >>> norm(G._e1 - H._e1) < ABS_TOL
+ >>> norm(G.e1() - H.e1()) < ABS_TOL
True
- >>> norm(G._e2 - H._e2) < ABS_TOL
+ >>> norm(G.e2() - H.e2()) < ABS_TOL
True
"""
alpha = random_scalar()
- tensor_prod = G._e1 * G._e2.trans()
- M = G._L + alpha*tensor_prod
+ tensor_prod = G.e1() * G.e2().trans()
+ M = G.L() + alpha*tensor_prod
- H = SymmetricLinearGame(M.trans(), G._K, G._e1, G._e2)
+ H = SymmetricLinearGame(M.trans(), G.K(), G.e1(), G.e2())
while H.condition() > MAX_COND:
# Loop until the condition number of H doesn't suck.
alpha = random_scalar()
- M = G._L + alpha*tensor_prod
- H = SymmetricLinearGame(M.trans(), G._K, G._e1, G._e2)
+ M = G.L() + alpha*tensor_prod
+ H = SymmetricLinearGame(M.trans(), G.K(), G.e1(), G.e2())
return (alpha, H)