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

    new_js = js.JS()
    new_js.compile(search_space)
Пример #2
0
def test_js_initialize_chaotic_map():
    search_space = search.SearchSpace(n_agents=10,
                                      n_variables=2,
                                      lower_bound=[0, 0],
                                      upper_bound=[10, 10])

    new_js = js.JS()
    new_js._initialize_chaotic_map(search_space.agents)
Пример #3
0
def test_js_params():
    params = {'eta': 4.0, 'beta': 3.0, 'gamma': 0.1}

    new_js = js.JS(params=params)

    assert new_js.eta == 4.0

    assert new_js.beta == 3.0

    assert new_js.gamma == 0.1
Пример #4
0
def test_js_hyperparams():
    hyperparams = {'eta': 4.0, 'beta': 3.0, 'gamma': 0.1}

    new_js = js.JS(hyperparams=hyperparams)

    assert new_js.eta == 4.0

    assert new_js.beta == 3.0

    assert new_js.gamma == 0.1
Пример #5
0
def test_js_motion_a():
    search_space = search.SearchSpace(n_agents=10,
                                      n_variables=2,
                                      lower_bound=[0, 0],
                                      upper_bound=[10, 10])

    new_js = js.JS()
    new_js.compile(search_space)

    motion = new_js._motion_a(0, 1)

    assert motion[0] != 0
Пример #6
0
def test_js_ocean_current():
    search_space = search.SearchSpace(n_agents=10,
                                      n_variables=2,
                                      lower_bound=[0, 0],
                                      upper_bound=[10, 10])

    new_js = js.JS()
    new_js.compile(search_space)

    trend = new_js._ocean_current(search_space.agents, search_space.best_agent)

    assert trend[0][0] != 0
Пример #7
0
def test_js_params_setter():
    new_js = js.JS()

    try:
        new_js.eta = 'a'
    except:
        new_js.eta = 4.0

    try:
        new_js.eta = -1
    except:
        new_js.eta = 4.0

    assert new_js.eta == 4.0

    try:
        new_js.beta = 'b'
    except:
        new_js.beta = 2.0

    try:
        new_js.beta = 0
    except:
        new_js.beta = 3.0

    assert new_js.beta == 3.0

    try:
        new_js.gamma = 'c'
    except:
        new_js.gamma = 0.1

    try:
        new_js.gamma = -1
    except:
        new_js.gamma = 0.1

    assert new_js.gamma == 0.1
Пример #8
0
def test_js_run():
    def square(x):
        return np.sum(x**2)

    def hook(optimizer, space, function):
        return

    new_function = function.Function(pointer=square)

    new_js = js.JS()

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

    history = new_js.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 js failed to converge.'
Пример #9
0
def test_js_build():
    new_js = js.JS()

    assert new_js.built == True