Beispiel #1
0
def test_optimal_sample_with_groups(setup_param_groups_prime):
    '''
    Tests that the combinatorial optimisation approach matches
    that of the brute force approach
    '''
    param_file = setup_param_groups_prime
    problem = read_param_file(param_file)

    N = 10
    num_levels = 8
    k_choices = 4
    num_params = problem['num_vars']

    sample = _sample_oat(problem,
                         N,
                         num_levels)

    strategy = GlobalOptimisation()
    actual = strategy.return_max_combo(sample,
                                       N,
                                       num_params,
                                       k_choices)

    brute_strategy = BruteForce()
    desired = brute_strategy.brute_force_most_distant(sample,
                                                      N,
                                                      num_params,
                                                      k_choices)

    assert_equal(actual, desired)
Beispiel #2
0
def test_raise_error_if_k_gt_N(setup_function):
    """Check that an error is raised if `k_choices` is greater than
    (or equal to) `N`
    """
    N = 4
    param_file = setup_function
    problem = read_param_file(param_file)
    num_levels = 4
    k_choices = 6

    morris_sample = _sample_oat(problem, N, num_levels)

    with raises(ValueError):
        _compute_optimised_trajectories(problem,
                                        morris_sample,
                                        N,
                                        k_choices,
                                        local_optimization=False)
Beispiel #3
0
def test_optimal_combinations(setup_function):

    N = 6
    param_file = setup_function
    problem = read_param_file(param_file)
    num_params = problem['num_vars']
    num_levels = 10
    grid_jump = num_levels / 2
    k_choices = 4

    morris_sample = _sample_oat(problem, N, num_levels, grid_jump)

    global_strategy = GlobalOptimisation()
    actual = global_strategy.return_max_combo(morris_sample, N, num_params,
                                              k_choices)

    brute_strategy = BruteForce()
    desired = brute_strategy.brute_force_most_distant(morris_sample, N,
                                                      num_params, k_choices)
    assert_equal(actual, desired)
Beispiel #4
0
def test_optimal_combinations(setup_function):

    N = 6
    param_file = setup_function
    problem = read_param_file(param_file)
    num_params = problem['num_vars']
    num_levels = 10
    k_choices = 4

    morris_sample = _sample_oat(problem, N, num_levels)

    global_strategy = GlobalOptimisation()
    actual = global_strategy.return_max_combo(morris_sample,
                                              N,
                                              num_params,
                                              k_choices)

    brute_strategy = BruteForce()
    desired = brute_strategy.brute_force_most_distant(morris_sample,
                                                      N,
                                                      num_params,
                                                      k_choices)
    assert_equal(actual, desired)
Beispiel #5
0
def test_size_of_trajectories_with_groups(setup_param_groups_prime):
    '''
    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 = setup_param_groups_prime
    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
    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)

    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)

    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)