예제 #1
0
def test_sso_update():
    search_space = search.SearchSpace(
        n_agents=10, n_variables=2, lower_bound=[0, 0], upper_bound=[10, 10]
    )

    new_sso = sso.SSO()
    new_sso.compile(search_space)

    new_sso.update(search_space)
예제 #2
0
def test_sso_params():
    params = {"C_w": 0.1, "C_p": 0.4, "C_g": 0.9}

    new_sso = sso.SSO(params=params)

    assert new_sso.C_w == 0.1

    assert new_sso.C_p == 0.4

    assert new_sso.C_g == 0.9
예제 #3
0
def test_sso_params():
    params = {'C_w': 0.1, 'C_p': 0.4, 'C_g': 0.9}

    new_sso = sso.SSO(params=params)

    assert new_sso.C_w == 0.1

    assert new_sso.C_p == 0.4

    assert new_sso.C_g == 0.9
예제 #4
0
def test_sso_hyperparams():
    hyperparams = {'C_w': 0.1, 'C_p': 0.4, 'C_g': 0.9}

    new_sso = sso.SSO(hyperparams=hyperparams)

    assert new_sso.C_w == 0.1

    assert new_sso.C_p == 0.4

    assert new_sso.C_g == 0.9
예제 #5
0
def test_sso_evaluate():
    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_sso = sso.SSO()
    new_sso.compile(search_space)

    new_sso.evaluate(search_space, square)
예제 #6
0
def test_sso_compile():
    search_space = search.SearchSpace(
        n_agents=10, n_variables=2, lower_bound=[0, 0], upper_bound=[10, 10]
    )

    new_sso = sso.SSO()
    new_sso.compile(search_space)

    try:
        new_sso.local_position = 1
    except:
        new_sso.local_position = np.array([1])

    assert new_sso.local_position == np.array([1])
예제 #7
0
def test_sso_params_setter():
    new_sso = sso.SSO()

    try:
        new_sso.C_w = "a"
    except:
        new_sso.C_w = 0.1

    try:
        new_sso.C_w = -1
    except:
        new_sso.C_w = 0.1

    assert new_sso.C_w == 0.1

    try:
        new_sso.C_p = "b"
    except:
        new_sso.C_p = 0.4

    try:
        new_sso.C_p = 0.05
    except:
        new_sso.C_p = 0.4

    assert new_sso.C_p == 0.4

    try:
        new_sso.C_g = "c"
    except:
        new_sso.C_g = 0.9

    try:
        new_sso.C_g = 0.35
    except:
        new_sso.C_g = 0.9

    assert new_sso.C_g == 0.9
예제 #8
0
def test_sso_params_setter():
    new_sso = sso.SSO()

    try:
        new_sso.C_w = 'a'
    except:
        new_sso.C_w = 0.1

    try:
        new_sso.C_w = -1
    except:
        new_sso.C_w = 0.1

    assert new_sso.C_w == 0.1

    try:
        new_sso.C_p = 'b'
    except:
        new_sso.C_p = 0.4

    try:
        new_sso.C_p = 0.05
    except:
        new_sso.C_p = 0.4

    assert new_sso.C_p == 0.4

    try:
        new_sso.C_g = 'c'
    except:
        new_sso.C_g = 0.9

    try:
        new_sso.C_g = 0.35
    except:
        new_sso.C_g = 0.9

    assert new_sso.C_g == 0.9
예제 #9
0
def test_sso_run():
    def square(x):
        return np.sum(x**2)

    def hook(optimizer, space, function):
        return

    new_function = function.Function(pointer=square)

    new_sso = sso.SSO()

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

    history = new_sso.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 sso failed to converge.'
예제 #10
0
def test_sso_build():
    new_sso = sso.SSO()

    assert new_sso.built == True