예제 #1
0
def test_ihs_hyperparams_setter():
    new_ihs = ihs.IHS()

    try:
        new_ihs.PAR_min = 'a'
    except:
        new_ihs.PAR_min = 0.5

    try:
        new_ihs.PAR_min = -1
    except:
        new_ihs.PAR_min = 0.5

    assert new_ihs.PAR_min == 0.5

    try:
        new_ihs.PAR_max = 'b'
    except:
        new_ihs.PAR_max = 1.0

    try:
        new_ihs.PAR_max = -1
    except:
        new_ihs.PAR_max = 1.0

    try:
        new_ihs.PAR_max = 0
    except:
        new_ihs.PAR_max = 1.0

    assert new_ihs.PAR_max == 1.0

    try:
        new_ihs.bw_min = 'c'
    except:
        new_ihs.bw_min = 1.0

    try:
        new_ihs.bw_min = -1
    except:
        new_ihs.bw_min = 1.0

    assert new_ihs.bw_min == 1.0

    try:
        new_ihs.bw_max = 'd'
    except:
        new_ihs.bw_max = 10.0

    try:
        new_ihs.bw_max = -1
    except:
        new_ihs.bw_max = 10.0

    try:
        new_ihs.bw_max = 0
    except:
        new_ihs.bw_max = 10.0

    assert new_ihs.bw_max == 10.0
예제 #2
0
def test_ihs_hyperparams():
    hyperparams = {
        'PAR_min': 0.5,
        'PAR_max': 1,
        'bw_min': 2,
        'bw_max': 5
    }

    new_ihs = ihs.IHS(hyperparams=hyperparams)

    assert new_ihs.PAR_min == 0.5

    assert new_ihs.PAR_max == 1

    assert new_ihs.bw_min == 2

    assert new_ihs.bw_max == 5
예제 #3
0
def test_ihs_hyperparams_setter():
    new_ihs = ihs.IHS()

    new_ihs.HMCR = 0.7
    assert new_ihs.HMCR == 0.7

    new_ihs.PAR_min = 0.1
    assert new_ihs.PAR_min == 0.1

    new_ihs.PAR_max = 0.5
    assert new_ihs.PAR_max == 0.5

    new_ihs.bw_min = 1
    assert new_ihs.bw_min == 1

    new_ihs.bw_max = 10
    assert new_ihs.bw_max == 10
예제 #4
0
def test_ihs_run():
    def square(x):
        return np.sum(x**2)

    new_function = function.Function(pointer=square)

    new_ihs = ihs.IHS()

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

    history = new_ihs.run(search_space, new_function)

    assert len(history.agents) > 0
    assert len(history.best_agent) > 0
예제 #5
0
def test_ihs_run():
    def square(x):
        return np.sum(x**2)

    def hook(optimizer, space, function):
        return

    new_function = function.Function(pointer=square)

    new_ihs = ihs.IHS()

    search_space = search.SearchSpace(n_agents=20, n_iterations=50,
                                      n_variables=2, lower_bound=[0, 0],
                                      upper_bound=[5, 5])

    history = new_ihs.run(search_space, new_function, pre_evaluation_hook=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 ihs failed to converge.'
예제 #6
0
def test_ihs_rebuild():
    new_ihs = ihs.IHS()

    assert new_ihs.built == True