X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=test%2Frandomgen.py;h=76d5f7874b38a7c0d45d2f57355be29053409af2;hb=ee3dc9fe4339b2073253b601c2d9e4b0f0900e8c;hp=9510c04767150b967283f62f72d7e7a88f112186;hpb=79d8219c4ac2ce7972247f3e7690e776295fabba;p=dunshire.git diff --git a/test/randomgen.py b/test/randomgen.py index 9510c04..76d5f78 100644 --- a/test/randomgen.py +++ b/test/randomgen.py @@ -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 = 250 +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 @@ -323,8 +327,8 @@ def random_orthant_game(): """ ambient_dim = random_natural() + 1 K = NonnegativeOrthant(ambient_dim) - e1 = [random_nn_scalar() for _ in range(K.dimension())] - e2 = [random_nn_scalar() for _ in range(K.dimension())] + e1 = [0.1 + random_nn_scalar() for _ in range(K.dimension())] + e2 = [0.1 + random_nn_scalar() for _ in range(K.dimension())] L = random_matrix(K.dimension()) G = SymmetricLinearGame(L, K, e1, e2) @@ -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)