def sobol_test04 ( ): #*****************************************************************************80 # ## SOBOL_TEST04 tests I4_SOBOL. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 22 February 2011 # # Author: # # Original MATLAB version by John Burkardt. # PYTHON version by Corrado Chisari # # Origin: # # MATLAB file sobol_test04.m, Copyright (c) 14 December 2009 John Burkardt # print('\nSOBOL_TEST04') print(' I4_SOBOL returns the next element') print(' of a Sobol sequence.') print('\n In this test, we call I4_SOBOL repeatedly.\n') dim_max = 4 for dim_num in range( 2, dim_max+1): seed = 0 qs = prime_ge ( dim_num ) print('\n Using dimension DIM_NUM = %d'%dim_num) print('\n Seed Seed I4_SOBOL') print(' In Out\n') for i in range( 0, 111): [ r, seed_out ] = i4_sobol ( dim_num, seed ) if ( i <= 11 or 95 <= i ): out='%6d %6d '%(seed, seed_out ) for j in range (0, dim_num): out+='%10f '%r[j] print(out) elif ( i == 12 ): print('......................') seed = seed_out return
def sobol_test04(): # *****************************************************************************80 # ## SOBOL_TEST04 tests I4_SOBOL. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 February 2011 # # Author: # # Original MATLAB version by John Burkardt. # PYTHON version by Corrado Chisari # print("\nSOBOL_TEST04") print(" I4_SOBOL returns the next element") print(" of a Sobol sequence.") print("\n In this test, we call I4_SOBOL repeatedly.\n") dim_max = 4 for dim_num in range(2, dim_max + 1): seed = 0 qs = prime_ge(dim_num) print("\n Using dimension DIM_NUM = %d" % dim_num) print("\n Seed Seed I4_SOBOL") print(" In Out\n") for i in range(0, 111): [r, seed_out] = i4_sobol(dim_num, seed) if i <= 11 or 95 <= i: out = "%6d %6d " % (seed, seed_out) for j in range(0, dim_num): out += "%10f " % r[j] print(out) elif i == 12: print("......................") seed = seed_out return
def sobol_test05 ( ): #*****************************************************************************80 # ## SOBOL_TEST05 tests I4_SOBOL. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 22 February 2011 # # Author: # # Original MATLAB version by John Burkardt. # Python version by Corrado Chisari # # Origin: # # MATLAB file sobol_test05.m, Copyright (c) 14 December 2009 John Burkardt # print('') print('SOBOL_TEST05') print(' I4_SOBOL computes the next element of a Sobol sequence.') print('') print(' In this test, we demonstrate how the SEED can be') print(' manipulated to skip ahead in the sequence, or') print(' to come back to any part of the sequence.') print('') dim_num = 3 print('') print(' Using dimension DIM_NUM = %d\n'%dim_num) seed = 0 print('') print(' Seed Seed I4_SOBOL') print(' In Out') print('') for i in range( 0, 10+1): [ r, seed_out ] = i4_sobol ( dim_num, seed ) out= '%6d %6d '%( seed, seed_out ) for j in range( 1, dim_num+1): out+= '%10f '% r[j-1] print(out) seed = seed_out print('') print(' Jump ahead by increasing SEED:') print('') seed = 100 print('') print(' Seed Seed I4_SOBOL') print(' In Out') print('') for i in range( 1, 6): [ r, seed_out ] = i4_sobol ( dim_num, seed ) out='%6d %6d '%( seed, seed_out) for j in range( 1, dim_num+1): out+= '%10f '% r[j-1] print(out) seed = seed_out print('') print(' Jump back by decreasing SEED:') print('') seed = 3 print('') print(' Seed Seed I4_SOBOL') print(' In Out') print('') for i in range( 0, 11): [ r, seed_out ] = i4_sobol ( dim_num, seed ) out='%6d %6d '%( seed, seed_out) for j in range( 1, dim_num+1): out+= '%10f '% r[j-1] print(out) seed = seed_out print('') print(' Jump back by decreasing SEED:') print('') seed = 98 print('') print(' Seed Seed I4_SOBOL') print(' In Out') print('') for i in range( 1, 6): [ r, seed_out ] = i4_sobol ( dim_num, seed ) out= '%6d %6d '%( seed, seed_out ) for j in range( 1, dim_num+1): out+= '%10f '%r[j-1] print(out) seed = seed_out return
# relax module imports. from extern.sobol.sobol_lib import i4_sobol # Some variables. DIM = 3 OFFSET = 0.5 * ones(DIM) # Loop over different number of points. for exponent in range(7): # The number of points. N = int(10**exponent) # Initialise a vector. ave_pos = zeros(DIM, float64) # Print out. print("\nN = %s" % N) # Loop over the points. for i in range(N): # The raw point. point, seed = i4_sobol(DIM, i) # Sum the point, minus the offset. ave_pos += point - OFFSET # The average vector length. ave_pos = ave_pos / float(N) r = norm(ave_pos) print("Average vector length: %s" % r)
def sobol_test05(): # *****************************************************************************80 # ## SOBOL_TEST05 tests I4_SOBOL. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 February 2011 # # Author: # # Original MATLAB version by John Burkardt. # PYTHON version by Corrado Chisari # print("") print("SOBOL_TEST05") print(" I4_SOBOL computes the next element of a Sobol sequence.") print("") print(" In this test, we demonstrate how the SEED can be") print(" manipulated to skip ahead in the sequence, or") print(" to come back to any part of the sequence.") print("") dim_num = 3 print("") print(" Using dimension DIM_NUM = %d\n" % dim_num) seed = 0 print("") print(" Seed Seed I4_SOBOL") print(" In Out") print("") for i in range(0, 10 + 1): [r, seed_out] = i4_sobol(dim_num, seed) out = "%6d %6d " % (seed, seed_out) for j in range(1, dim_num + 1): out += "%10f " % r[j - 1] print(out) seed = seed_out print("") print(" Jump ahead by increasing SEED:") print("") seed = 100 print("") print(" Seed Seed I4_SOBOL") print(" In Out") print("") for i in range(1, 6): [r, seed_out] = i4_sobol(dim_num, seed) out = "%6d %6d " % (seed, seed_out) for j in range(1, dim_num + 1): out += "%10f " % r[j - 1] print(out) seed = seed_out print("") print(" Jump back by decreasing SEED:") print("") seed = 3 print("") print(" Seed Seed I4_SOBOL") print(" In Out") print("") for i in range(0, 11): [r, seed_out] = i4_sobol(dim_num, seed) out = "%6d %6d " % (seed, seed_out) for j in range(1, dim_num + 1): out += "%10f " % r[j - 1] print(out) seed = seed_out print("") print(" Jump back by decreasing SEED:") print("") seed = 98 print("") print(" Seed Seed I4_SOBOL") print(" In Out") print("") for i in range(1, 6): [r, seed_out] = i4_sobol(dim_num, seed) out = "%6d %6d " % (seed, seed_out) for j in range(1, dim_num + 1): out += "%10f " % r[j - 1] print(out) seed = seed_out return
from extern.sobol.sobol_lib import i4_sobol # Some variables. DIM = 3 OFFSET = 0.5 * ones(DIM) # Loop over different number of points. for exponent in range(7): # The number of points. N = int(10**exponent) # Initialise a vector. ave_pos = zeros(DIM, float64) # Print out. print("\nN = %s" % N) # Loop over the points. for i in range(N): # The raw point. point, seed = i4_sobol(DIM, i) # Sum the point, minus the offset. ave_pos += point - OFFSET # The average vector length. ave_pos = ave_pos / float(N) r = norm(ave_pos) print("Average vector length: %s" % r)