def fixed_level_quadrature_latin_hypercube( I, max_order ): num_dims, num_pts = I.shape I = I % max_order I = unique_matrix_rows( I.T ).T while ( I.shape[1] != num_pts ): I = numpy.hstack( ( I, numpy.random.randint( 0, max_order, ( num_dims, num_pts - I.shape[1] ) ) ) ) I = unique_matrix_rows( I.T ).T pts = numpy.empty( ( num_dims, num_pts ), numpy.double ) x, w = gauss_legendre_pts_wts_1D( max_order, 0., 1. ) for dim in xrange( num_dims ): pts[dim,:] = x[I[dim,:]] return pts
def test_index_generation( self ): num_dims = 2 order = 3 indices = PolyIndexVector() get_hyperbolic_indices( num_dims, order, 1., indices ) true_indices = [[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [0, 2], [1, 2], [2, 1], [3, 0], [0, 3]] indices_list = [] for i in xrange( indices.size() ): indices_list.append( indices[i].uncompressed_data( num_dims ) ) indices = unique_matrix_rows( numpy.array( indices_list )) true_indices = unique_matrix_rows( numpy.array( true_indices ) ) assert numpy.allclose( true_indices, indices ) num_dims = 3 order = 2 indices = PolyIndexVector() get_hyperbolic_indices( num_dims, order, 1., indices ) true_indices = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1], [2, 0, 0], [1, 1, 0], [0, 2, 0], [1, 0, 1], [0, 1, 1], [0, 0, 2]] indices_list = [] for i in xrange( indices.size() ): indices_list.append( indices[i].uncompressed_data( num_dims ) ) indices = unique_matrix_rows( numpy.array( indices_list )) true_indices = unique_matrix_rows( numpy.array( true_indices ) ) assert numpy.allclose( true_indices, indices ) num_dims = 2 order = 3 indices = PolyIndexVector() get_hyperbolic_indices( num_dims, order, .5, indices ) true_indices = [[0, 0], [1, 0], [2, 0], [3, 0], [0, 1], [0, 2], [0, 3]] indices_list = [] for i in xrange( indices.size() ): indices_list.append( indices[i].uncompressed_data( num_dims ) ) indices = unique_matrix_rows( numpy.array( indices_list )) true_indices = unique_matrix_rows( numpy.array( true_indices ) ) assert numpy.allclose( true_indices, indices ) num_dims = 2 order = 6 indices = PolyIndexVector() get_hyperbolic_indices( num_dims, order, .5, indices ) true_indices = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [1, 1], [2, 1], [1, 2], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6]] indices_list = [] for i in xrange( indices.size() ): indices_list.append( indices[i].uncompressed_data( num_dims ) ) indices = unique_matrix_rows( numpy.array( indices_list )) true_indices = unique_matrix_rows( numpy.array( true_indices ) ) assert numpy.allclose( true_indices, indices )
def test_index_generator( self ): index_generator = IndexGenerator() # num_dims = 2, max_level = 3 index_norm_order = 1 num_dims = 2 max_level = 3 index_generator.set_parameters( num_dims, max_level, index_norm_order = 1, priority_weight = 1. ) index_generator.build_isotropic_index_set() indices = index_generator.get_all_indices() true_indices = [[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [0, 2], [1, 2], [2, 1], [3, 0], [0, 3]] indices_list = [] for i, index in enumerate( indices ): indices_list.append( index.uncompressed_data( num_dims ) ) indices = unique_matrix_rows( numpy.array( indices_list )) true_indices = unique_matrix_rows( numpy.array( true_indices ) ) assert numpy.allclose( true_indices, indices ) # num_dims = 3, max_level = 2 index_norm_order = 1 num_dims = 3 max_level = 2 index_generator.set_parameters( num_dims, max_level, index_norm_order = 1, priority_weight = 1. ) index_generator.build_isotropic_index_set() indices = index_generator.get_all_indices() true_indices = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1], [2, 0, 0], [1, 1, 0], [0, 2, 0], [1, 0, 1], [0, 1, 1], [0, 0, 2]] indices_list = [] for i, index in enumerate( indices ): indices_list.append( index.uncompressed_data( num_dims ) ) indices = unique_matrix_rows( numpy.array( indices_list )) true_indices = unique_matrix_rows( numpy.array( true_indices ) ) assert numpy.allclose( true_indices, indices ) # num_dims = 2, max_level = 3 index_norm_order = 0.5 num_dims = 2 max_level = 3 index_generator = IndexGenerator() index_generator.set_parameters( num_dims, max_level, index_norm_order = 0.5, priority_weight = 1. ) index_generator.build_isotropic_index_set() indices = index_generator.get_all_indices() true_indices = [[0, 0], [1, 0], [2, 0], [3, 0], [0, 1], [0, 2], [0, 3]] indices_list = [] for i, index in enumerate( indices ): indices_list.append( index.uncompressed_data( num_dims ) ) indices = unique_matrix_rows( numpy.array( indices_list ) ) true_indices = unique_matrix_rows( numpy.array( true_indices ) ) assert numpy.allclose( true_indices, indices ) # num_dims = 2, max_level = 6 index_norm_order = 0.5 num_dims = 2 max_level = 6 index_generator = IndexGenerator() index_generator.set_parameters( num_dims, max_level, index_norm_order = 0.5, priority_weight = 1. ) index_generator.build_isotropic_index_set() indices = index_generator.get_all_indices() true_indices = [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [1, 1], [2, 1], [1, 2], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6]] indices_list = [] for i, index in enumerate( indices ): indices_list.append( index.uncompressed_data( num_dims ) ) indices = unique_matrix_rows( numpy.array( indices_list ) ) true_indices = unique_matrix_rows( numpy.array( true_indices ) ) assert numpy.allclose( true_indices, indices )
from math_tools_cpp import compute_hyperbolic_level_subdim_indices as compute_hyperbolic_level_subdim_indices_cpp print "b", compute_hyperbolic_level_subdim_indices_cpp(num_dims, level, 2, p) num_dims = 10 level = 9 p = 0.4 import time t0 = time.time() indices = compute_hyperbolic_indices(num_dims, level, p) numpy.set_printoptions(threshold=numpy.nan) print indices.shape from utilities.math_utils import unique_matrix_rows print unique_matrix_rows(indices).shape eps = 100 * numpy.finfo(numpy.double).eps count = numpy.zeros(3) count1 = numpy.zeros(2) for i in xrange(indices.shape[0]): if numpy.count_nonzero(indices[i, :]) == 1: count[0] += 1 if numpy.count_nonzero(indices[i, :]) == 2: count[1] += 1 if numpy.count_nonzero(indices[i, :]) == 3: count[2] += 1 if indices[i, :].sum() == 2 and numpy.count_nonzero(indices[i, :]) == 2: count1[0] += 1 if indices[i, :].sum() == 3 and numpy.count_nonzero(indices[i, :]) == 2: count1[1] += 1