Пример #1
0
def test_abc_run():
    def square(x):
        return np.sum(x**2)

    def hook(optimizer, space, function):
        return

    new_function = function.Function(pointer=square)

    hyperparams = {'n_trials': 1}

    new_abc = abc.ABC(hyperparams=hyperparams)

    search_space = search.SearchSpace(n_agents=10,
                                      n_iterations=100,
                                      n_variables=2,
                                      lower_bound=[0, 0],
                                      upper_bound=[10, 10])

    history = new_abc.run(search_space, new_function, pre_evaluation=hook)

    assert len(history.agents) > 0
    assert len(history.best_agent) > 0

    best_fitness = history.best_agent[-1][1]
    assert best_fitness <= constants.TEST_EPSILON, 'The algorithm abc failed to converge.'
Пример #2
0
def test_abc_hyperparams():
    hyperparams = {
        'n_trials': 5
    }

    new_abc = abc.ABC(hyperparams=hyperparams)

    assert new_abc.n_trials == 5
Пример #3
0
def test_abc_send_onlooker():
    def square(x):
        return np.sum(x**2)

    search_space = search.SearchSpace(n_agents=10,
                                      n_variables=2,
                                      lower_bound=[0, 0],
                                      upper_bound=[10, 10])

    new_abc = abc.ABC()
    new_abc.compile(search_space)

    new_abc._send_onlooker(search_space.agents, square)
Пример #4
0
def test_abc_hyperparams_setter():
    new_abc = abc.ABC()

    try:
        new_abc.n_trials = 0.0
    except:
        new_abc.n_trials = 10

    try:
        new_abc.n_trials = 0
    except:
        new_abc.n_trials = 10

    assert new_abc.n_trials == 10
Пример #5
0
def test_abc_evaluate_location():
    def square(x):
        return np.sum(x**2)

    search_space = search.SearchSpace(n_agents=10,
                                      n_variables=2,
                                      lower_bound=[0, 0],
                                      upper_bound=[10, 10])

    new_abc = abc.ABC()
    new_abc.compile(search_space)

    new_abc._evaluate_location(search_space.agents[0], search_space.agents[1],
                               square, 0)
Пример #6
0
def test_abc_compile():
    search_space = search.SearchSpace(n_agents=10,
                                      n_variables=2,
                                      lower_bound=[0, 0],
                                      upper_bound=[10, 10])

    new_abc = abc.ABC()
    new_abc.compile(search_space)

    try:
        new_abc.trial = 1
    except:
        new_abc.trial = np.array([1])

    assert new_abc.trial == np.array([1])
Пример #7
0
def test_abc_build():
    new_abc = abc.ABC()

    assert new_abc.built == True
Пример #8
0
def test_abc_params():
    params = {"n_trials": 5}

    new_abc = abc.ABC(params=params)

    assert new_abc.n_trials == 5