Esempio n. 1
0
def test_sos_update():
    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_sos = sos.SOS()

    new_sos.update(search_space, square)
Esempio n. 2
0
def test_sos_parasitism():
    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_sos = sos.SOS()

    new_sos._parasitism(search_space.agents[0], search_space.agents[1], square)
Esempio n. 3
0
def test_sos_run():
    def square(x):
        return np.sum(x**2)

    def hook(optimizer, space, function):
        return

    new_function = function.Function(pointer=square)

    new_sos = sos.SOS()

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

    history = new_sos.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 sos failed to converge.'
Esempio n. 4
0
def test_sos_build():
    new_sos = sos.SOS()

    assert new_sos.built == True