def mono_between_random(m, n1, n2, seed): #*****************************************************************************80 # ## MONO_BETWEEN_RANDOM: random monomial with total degree between N1 and N2. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 25 October 2014 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, the spatial dimension. # # Input, integer N1, N2, the minimum and maximum degrees. # 0 <= N1 <= N2. # # Input, integer SEED, the random number seed. # # Output integer X[M], the random monomial. # # Output integer RANK, the rank of the monomial. # # Output, integer SEED, the updated random number seed. # from i4_uniform_ab import i4_uniform_ab from mono_unrank_grlex import mono_unrank_grlex from mono_upto_enum import mono_upto_enum n1_copy = max(n1, 0) rank_min = mono_upto_enum(m, n1_copy - 1) + 1 rank_max = mono_upto_enum(m, n2) rank, seed = i4_uniform_ab(rank_min, rank_max, seed) x = mono_unrank_grlex(m, rank) return x, rank, seed
def mono_total_random(m, n, seed): #*****************************************************************************80 # ## MONO_TOTAL_RANDOM: random monomial with total degree equal to N. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 21 November 2013 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, the spatial dimension. # # Input, integer N, the degree. # 0 <= N. # # Input, integer SEED, the random number seed. # # Output, integer X[M], the random monomial. # # Output, integer RANK, the rank of the monomial. # # Output, integer SEED, the random number seed. # from i4_uniform_ab import i4_uniform_ab from mono_unrank_grlex import mono_unrank_grlex from mono_upto_enum import mono_upto_enum rank_min = mono_upto_enum(m, n - 1) + 1 rank_max = mono_upto_enum(m, n) rank, seed = i4_uniform_ab(rank_min, rank_max, seed) x = mono_unrank_grlex(m, rank) return x, rank, seed
def mono_total_random ( m, n, seed ): #*****************************************************************************80 # ## MONO_TOTAL_RANDOM: random monomial with total degree equal to N. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 21 November 2013 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, the spatial dimension. # # Input, integer N, the degree. # 0 <= N. # # Input, integer SEED, the random number seed. # # Output, integer X[M], the random monomial. # # Output, integer RANK, the rank of the monomial. # # Output, integer SEED, the random number seed. # from i4_uniform_ab import i4_uniform_ab from mono_unrank_grlex import mono_unrank_grlex from mono_upto_enum import mono_upto_enum rank_min = mono_upto_enum ( m, n - 1 ) + 1 rank_max = mono_upto_enum ( m, n ) rank, seed = i4_uniform_ab ( rank_min, rank_max, seed ) x = mono_unrank_grlex ( m, rank ) return x, rank, seed
def mono_unrank_grlex_test(): #******************************************************************************/ # ## MONO_UNRANK_GRLEX_TEST tests MONO_UNRANK_GRLEX. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 25 October 2014 # # Author: # # John Burkardt # from i4_uniform_ab import i4_uniform_ab from mono_upto_enum import mono_upto_enum from mono_upto_next_grlex import mono_upto_next_grlex import numpy as np m = 3 print '' print 'MONO_UNRANK_GRLEX' print ' MONO_UNRANK_GRLEX is given a rank, and returns the corresponding' print ' monomial in the sequence of all monomials in M dimensions' print ' in grlex order.' print '' print ' For reference, print a monomial sequence with ranks.' n = 4 rank_max = mono_upto_enum(m, n) print '' print ' Let M = %d' % (m) print ' N = %d' % (n) print '' x = np.zeros(m, dtype=np.int32) i = 1 while (True): print ' %2d ' % (i), for j in range(0, m): print '%2d' % (x[j]), print '' if (x[0] == n): break mono_upto_next_grlex(m, n, x) i = i + 1 print '' print ' Now choose random ranks between 1 and %d' % (rank_max) print '' seed = 123456789 test_num = 5 for test in range(0, test_num): rank, seed = i4_uniform_ab(1, rank_max, seed) x = mono_unrank_grlex(m, rank) print ' %2d ' % (rank), for j in range(0, m): print '%2d' % (x[j]), print '' print '' print 'MONO_UNRANK_GRLEX_TEST' print ' Normal end of execution.' return
def mono_unrank_grlex_test ( ): #******************************************************************************/ # ## MONO_UNRANK_GRLEX_TEST tests MONO_UNRANK_GRLEX. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 25 October 2014 # # Author: # # John Burkardt # from i4_uniform_ab import i4_uniform_ab from mono_upto_enum import mono_upto_enum from mono_upto_next_grlex import mono_upto_next_grlex import numpy as np m = 3 print '' print 'MONO_UNRANK_GRLEX' print ' MONO_UNRANK_GRLEX is given a rank, and returns the corresponding' print ' monomial in the sequence of all monomials in M dimensions' print ' in grlex order.' print '' print ' For reference, print a monomial sequence with ranks.' n = 4 rank_max = mono_upto_enum ( m, n ) print '' print ' Let M = %d' % ( m ) print ' N = %d' % ( n ) print '' x = np.zeros ( m, dtype = np.int32 ) i = 1 while ( True ): print ' %2d ' % ( i ), for j in range ( 0, m ): print '%2d' % ( x[j] ), print '' if ( x[0] == n ): break mono_upto_next_grlex ( m, n, x ) i = i + 1 print '' print ' Now choose random ranks between 1 and %d' % ( rank_max ) print '' seed = 123456789 test_num = 5 for test in range ( 0, test_num ): rank, seed = i4_uniform_ab ( 1, rank_max, seed ) x = mono_unrank_grlex ( m, rank ) print ' %2d ' % ( rank ), for j in range ( 0, m ): print '%2d' % ( x[j] ), print '' print '' print 'MONO_UNRANK_GRLEX_TEST' print ' Normal end of execution.' return