X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=test%2Frandomgen.py;h=9fee2f749cbcf8037f2c64d41fe42e17731381a4;hb=10dfe7d7edb69701dd8f4f955f3f325706d77e47;hp=395408c6626ec4ee48dcb95e3b2e684daea88f4a;hpb=17055c563e53d29a6e72195b335e0c00f846cf78;p=dunshire.git diff --git a/test/randomgen.py b/test/randomgen.py index 395408c..9fee2f7 100644 --- a/test/randomgen.py +++ b/test/randomgen.py @@ -9,7 +9,7 @@ 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 = 100 """ The maximum condition number of a randomly-generated game. """ @@ -314,11 +314,17 @@ def random_orthant_game(): SymmetricLinearGame A random game over some nonnegative orthant. + Examples + -------- + + >>> 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) @@ -343,6 +349,12 @@ def random_icecream_game(): SymmetricLinearGame A random game over some ice-cream cone. + Examples + -------- + + >>> random_icecream_game() + + """ # Use a minimum dimension of two to avoid divide-by-zero in # the fudge factor we make up later. @@ -387,6 +399,12 @@ def random_ll_orthant_game(): A random game over some nonnegative orthant whose ``payoff`` method is based on a Lyapunov-like ``L`` operator. + Examples + -------- + + >>> random_ll_orthant_game() + + """ G = random_orthant_game() L = random_diagonal_matrix(G._K.dimension()) @@ -419,6 +437,12 @@ def random_ll_icecream_game(): A random game over some ice-cream cone whose ``payoff`` method is based on a Lyapunov-like ``L`` operator. + Examples + -------- + + >>> random_ll_icecream_game() + + """ G = random_icecream_game() L = random_lyapunov_like_icecream(G._K.dimension()) @@ -452,6 +476,12 @@ def random_positive_orthant_game(): A random game over some nonnegative orthant whose ``payoff`` method is based on a positive ``L`` operator. + Examples + -------- + + >>> random_positive_orthant_game() + + """ G = random_orthant_game() @@ -487,6 +517,22 @@ def random_nn_scaling(G): (float, SymmetricLinearGame) A pair containing the both the scaling factor and the new scaled game. + Examples + -------- + + >>> from dunshire.matrices import norm + >>> from dunshire.options import ABS_TOL + >>> G = random_orthant_game() + >>> (alpha, H) = random_nn_scaling(G) + >>> alpha >= 0 + True + >>> G._K == H._K + True + >>> norm(G._e1 - H._e1) < ABS_TOL + True + >>> norm(G._e2 - H._e2) < ABS_TOL + True + """ alpha = random_nn_scalar() H = SymmetricLinearGame(alpha*G._L.trans(), G._K, G._e1, G._e2) @@ -518,6 +564,20 @@ def random_translation(G): A pair containing the both the translation distance and the new scaled game. + Examples + -------- + + >>> from dunshire.matrices import norm + >>> from dunshire.options import ABS_TOL + >>> G = random_orthant_game() + >>> (alpha, H) = random_translation(G) + >>> G._K == H._K + True + >>> norm(G._e1 - H._e1) < ABS_TOL + True + >>> norm(G._e2 - H._e2) < ABS_TOL + True + """ alpha = random_scalar() tensor_prod = G._e1 * G._e2.trans()