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

    new_mfo.update(search_space, 1, 10)
예제 #2
0
def test_mfo_hyperparams_setter():
    new_mfo = mfo.MFO()

    try:
        new_mfo.b = 'a'
    except:
        new_mfo.b = 1

    try:
        new_mfo.b = -1
    except:
        new_mfo.b = 1

    assert new_mfo.b == 1
예제 #3
0
def test_mfo_params_setter():
    new_mfo = mfo.MFO()

    try:
        new_mfo.b = "a"
    except:
        new_mfo.b = 1

    try:
        new_mfo.b = -1
    except:
        new_mfo.b = 1

    assert new_mfo.b == 1
예제 #4
0
def test_mfo_run():
    def square(x):
        return np.sum(x**2)

    def hook(optimizer, space, function):
        return

    new_function = function.Function(pointer=square)

    new_mfo = mfo.MFO()

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

    history = new_mfo.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 mfo failed to converge.'
예제 #5
0
def test_mfo_build():
    new_mfo = mfo.MFO()

    assert new_mfo.built == True
예제 #6
0
def test_mfo_hyperparams():
    hyperparams = {'b': 1}

    new_mfo = mfo.MFO(hyperparams=hyperparams)

    assert new_mfo.b == 1
예제 #7
0
def test_mfo_params():
    params = {"b": 1}

    new_mfo = mfo.MFO(params=params)

    assert new_mfo.b == 1