def test_catch_inputs_not_in_zero_one_range(): input_1 = [[0, 1 / 3.], [0, 1.], [2 / 3., 1.]] input_2 = [[0, 1 / 3.], [2 / 3., 1 / 3.], [2 / 3., 1.]] input_3 = [[2 / 3., 0], [2 / 3., 2 / 3.], [0, 2 / 3.]] input_4 = [[1 / 3., 1.], [1., 1.], [1, 1 / 3.]] input_5 = [[1 / 3., 1.], [1 / 3., 1 / 3.], [1, 1 / 3.]] input_6 = [[1 / 3., 2 / 3.], [1 / 3., 0], [1., 0]] input_sample = np.concatenate( [input_1, input_2, input_3, input_4, input_5, input_6]) problem = {'num_vars': 2, 'groups': None} k_choices = 4 N = 10 input_sample *= 10 compute_optimised_trajectories(problem, input_sample, N, k_choices)
def test_raise_error_if_k_gt_N(): """ Check that an error is raised if `k_choices` is greater than (or equal to) `N` """ N = 4 param_file = "SALib/tests/test_params.txt" problem = read_param_file(param_file) num_levels = 4 grid_jump = num_levels / 2 k_choices = 6 morris_sample = sample_oat(problem, N, num_levels, grid_jump) compute_optimised_trajectories(problem, morris_sample, N, k_choices)
def test_raise_error_if_k_gt_N(): """ Check that an error is raised if `k_choices` is greater than (or equal to) `N` """ N = 4 param_file = "SALib/tests/test_params.txt" problem = read_param_file(param_file) num_levels = 4 grid_jump = num_levels / 2 k_choices = 6 morris_sample = sample_oat(problem, N, num_levels, grid_jump) compute_optimised_trajectories(problem, morris_sample, N, k_choices)
def test_find_optimum_trajectories(): input_1 = [[0, 1 / 3.], [0, 1.], [2 / 3., 1.]] input_2 = [[0, 1 / 3.], [2 / 3., 1 / 3.], [2 / 3., 1.]] input_3 = [[2 / 3., 0], [2 / 3., 2 / 3.], [0, 2 / 3.]] input_4 = [[1 / 3., 1.], [1., 1.], [1, 1 / 3.]] input_5 = [[1 / 3., 1.], [1 / 3., 1 / 3.], [1, 1 / 3.]] input_6 = [[1 / 3., 2 / 3.], [1 / 3., 0], [1., 0]] input_sample = np.concatenate( [input_1, input_2, input_3, input_4, input_5, input_6]) N = 6 problem = {'num_vars': 2, 'groups': None} k_choices = 4 output = compute_optimised_trajectories(problem, input_sample, N, k_choices) expected = np.concatenate([input_1, input_3, input_4, input_6]) np.testing.assert_equal(output, expected)
def test_size_of_trajectories_with_groups(): ''' Tests that the number of trajectories produced is computed correctly (i.e. that the size of the trajectories is a function of the number of groups, rather than the number of variables when groups are used. There are seven variables and three groups. With N=10: 1. the sample ignoring groups (i.e. the call to `sample_oat') should be of size N*(D+1)-by-D. 2. the sample with groups should be of size N*(G+1)-by-D When k=4: 3. the optimal sample ignoring groups should be of size k*(D+1)-by-D 4. the optimal sample with groups should be of size k*(G+1)-by-D ''' param_file = "SALib/tests/test_param_file_w_groups_prime.txt" group_problem = read_param_file(param_file) no_group_problem = read_param_file(param_file) no_group_problem['groups'] = None N = 11 num_levels = 8 grid_jump = 4 k_choices = 4 num_params = group_problem['num_vars'] num_groups = 3 # Test 1. dimensions of sample ignoring groups sample = sample_oat(no_group_problem, N, num_levels, grid_jump) size_x, size_y = sample.shape assert_equal(size_x, N * (num_params + 1)) assert_equal(size_y, num_params) # Test 2. dimensions of sample with groups group_sample = sample_groups(group_problem, N, num_levels, grid_jump) size_x, size_y = group_sample.shape assert_equal(size_x, N * (num_groups + 1)) assert_equal(size_y, num_params) # Test 3. dimensions of optimal sample without groups optimal_sample_without_groups = compute_optimised_trajectories(no_group_problem, sample, N, k_choices) size_x, size_y = optimal_sample_without_groups.shape assert_equal(size_x, k_choices * (num_params + 1)) assert_equal(size_y, num_params) # Test 4. dimensions of optimal sample with groups optimal_sample_with_groups = compute_optimised_trajectories(group_problem, group_sample, N, k_choices) size_x, size_y = optimal_sample_with_groups.shape assert_equal(size_x, k_choices * (num_groups + 1)) assert_equal(size_y, num_params)
def test_size_of_trajectories_with_groups(): ''' Tests that the number of trajectories produced is computed correctly (i.e. that the size of the trajectories is a function of the number of groups, rather than the number of variables when groups are used. There are seven variables and three groups. With N=10: 1. the sample ignoring groups (i.e. the call to `sample_oat') should be of size N*(D+1)-by-D. 2. the sample with groups should be of size N*(G+1)-by-D When k=4: 3. the optimal sample ignoring groups should be of size k*(D+1)-by-D 4. the optimal sample with groups should be of size k*(G+1)-by-D ''' param_file = "SALib/tests/test_param_file_w_groups_prime.txt" group_problem = read_param_file(param_file) no_group_problem = read_param_file(param_file) no_group_problem['groups'] = None N = 11 num_levels = 8 grid_jump = 4 k_choices = 4 num_params = group_problem['num_vars'] num_groups = 3 # Test 1. dimensions of sample ignoring groups sample = sample_oat(no_group_problem, N, num_levels, grid_jump) size_x, size_y = sample.shape assert_equal(size_x, N * (num_params + 1)) assert_equal(size_y, num_params) # Test 2. dimensions of sample with groups group_sample = sample_groups(group_problem, N, num_levels, grid_jump) size_x, size_y = group_sample.shape assert_equal(size_x, N * (num_groups + 1)) assert_equal(size_y, num_params) # Test 3. dimensions of optimal sample without groups optimal_sample_without_groups = compute_optimised_trajectories( no_group_problem, sample, N, k_choices) size_x, size_y = optimal_sample_without_groups.shape assert_equal(size_x, k_choices * (num_params + 1)) assert_equal(size_y, num_params) # Test 4. dimensions of optimal sample with groups optimal_sample_with_groups = compute_optimised_trajectories( group_problem, group_sample, N, k_choices) size_x, size_y = optimal_sample_with_groups.shape assert_equal(size_x, k_choices * (num_groups + 1)) assert_equal(size_y, num_params)