]> gitweb.michael.orlitzky.com - dunshire.git/blobdiff - test/randomgen.py
Put the MAX_COND at 150 for now... until it causes problems.
[dunshire.git] / test / randomgen.py
index 9fee2f749cbcf8037f2c64d41fe42e17731381a4..76d5f7874b38a7c0d45d2f57355be29053409af2 100644 (file)
@@ -9,9 +9,13 @@ from dunshire.cones import NonnegativeOrthant, IceCream
 from dunshire.games import SymmetricLinearGame
 from dunshire.matrices import (append_col, append_row, identity)
 
-MAX_COND = 100
+MAX_COND = 150
 """
-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.
 """
 
 RANDOM_MAX = 10
@@ -407,16 +411,16 @@ def random_ll_orthant_game():
 
     """
     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
 
@@ -445,16 +449,16 @@ def random_ll_icecream_game():
 
     """
     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
 
@@ -485,16 +489,16 @@ def random_positive_orthant_game():
     """
 
     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
 
@@ -526,21 +530,21 @@ def random_nn_scaling(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)
 
@@ -571,23 +575,23 @@ def random_translation(G):
         >>> 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)