Пример #1
0
def test_boa_update():
    search_space = search.SearchSpace(n_agents=10, n_variables=2,
                                      lower_bound=[0, 0], upper_bound=[10, 10])

    new_boa = boa.BOA()
    new_boa.compile(search_space)

    new_boa.update(search_space)
Пример #2
0
def test_boa_local_movement():
    search_space = search.SearchSpace(n_agents=10, n_variables=2,
                                      lower_bound=[0, 0], upper_bound=[10, 10])

    new_boa = boa.BOA()
    new_boa.compile(search_space)

    new_boa._local_movement(search_space.agents[0].position, search_space.agents[1].position,
                            search_space.agents[2].position, new_boa.fragrance[0], 0.5)
Пример #3
0
def test_boa_params():
    params = {"c": 0.01, "a": 0.1, "p": 0.8}

    new_boa = boa.BOA(params=params)

    assert new_boa.c == 0.01

    assert new_boa.a == 0.1

    assert new_boa.p == 0.8
Пример #4
0
def test_boa_hyperparams():
    hyperparams = {'c': 0.01, 'a': 0.1, 'p': 0.8}

    new_boa = boa.BOA(hyperparams=hyperparams)

    assert new_boa.c == 0.01

    assert new_boa.a == 0.1

    assert new_boa.p == 0.8
Пример #5
0
def test_boa_compile():
    search_space = search.SearchSpace(n_agents=10, n_variables=2,
                                      lower_bound=[0, 0], upper_bound=[10, 10])

    new_boa = boa.BOA()
    new_boa.compile(search_space)

    try:
        new_boa.fragrance = 1
    except:
        new_boa.fragrance = np.array([1])

    assert new_boa.fragrance == np.array([1])
Пример #6
0
def test_boa_params():
    params = {
        'c': 0.01,
        'a': 0.1,
        'p': 0.8
    }

    new_boa = boa.BOA(params=params)

    assert new_boa.c == 0.01

    assert new_boa.a == 0.1

    assert new_boa.p == 0.8
Пример #7
0
def test_boa_params_setter():
    new_boa = boa.BOA()

    try:
        new_boa.c = 'a'
    except:
        new_boa.c = 0.01

    try:
        new_boa.c = -1
    except:
        new_boa.c = 0.01

    assert new_boa.c == 0.01

    try:
        new_boa.a = 'b'
    except:
        new_boa.a = 0.1

    try:
        new_boa.a = -1
    except:
        new_boa.a = 0.1

    assert new_boa.a == 0.1

    try:
        new_boa.p = 'c'
    except:
        new_boa.p = 0.8

    try:
        new_boa.p = -1
    except:
        new_boa.p = 0.8

    assert new_boa.p == 0.8
Пример #8
0
def test_boa_params_setter():
    new_boa = boa.BOA()

    try:
        new_boa.c = "a"
    except:
        new_boa.c = 0.01

    try:
        new_boa.c = -1
    except:
        new_boa.c = 0.01

    assert new_boa.c == 0.01

    try:
        new_boa.a = "b"
    except:
        new_boa.a = 0.1

    try:
        new_boa.a = -1
    except:
        new_boa.a = 0.1

    assert new_boa.a == 0.1

    try:
        new_boa.p = "c"
    except:
        new_boa.p = 0.8

    try:
        new_boa.p = -1
    except:
        new_boa.p = 0.8

    assert new_boa.p == 0.8
Пример #9
0
def test_boa_run():
    def square(x):
        return np.sum(x**2)

    def hook(optimizer, space, function):
        return

    new_function = function.Function(pointer=square)

    new_boa = boa.BOA()

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

    history = new_boa.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 boa failed to converge.'
Пример #10
0
def test_boa_build():
    new_boa = boa.BOA()

    assert new_boa.built == True