Example #1
0
def test_ltm_10():
    path = None
    model_name = "test_ltm_0"

    def objective_function(opt):
        score = -opt["x1"] * opt["x1"]
        return score

    search_space = {
        "x1": list(range(0, 3, 1)),
    }

    memory = LongTermMemory(model_name, path=path)

    hyper = Hyperactive()
    hyper.add_search(
        objective_function, search_space, n_iter=25, long_term_memory=memory
    )
    hyper.run()

    hyper = Hyperactive()
    hyper.add_search(
        objective_function, search_space, n_iter=25, long_term_memory=memory
    )
    hyper.run()

    memory.remove_model_data()
Example #2
0
def test_ltm_list():
    path = "./"
    model_name = "test_ltm_list"

    dict_ = {"x1": [[1, 1, 1], [1, 2, 1], [1, 1, 2]]}
    results1 = pd.DataFrame(dict_)
    print("\n results1 \n", results1)

    memory = LongTermMemory(model_name, path=path)
    memory.save(results1, objective_function)

    results2 = memory.load()

    memory.remove_model_data()
    print("\n results2 \n", results2)

    for list_1 in list(results2.values.flatten()):
        assert_ = False
        for list_2 in list(dict_.values())[0]:
            print("\n list_1 ", list_1)
            print("list_2 ", list_2)
            print(list_1 == list_2)

            if list_1 == list_2:
                assert_ = True
                break

        assert assert_
Example #3
0
def test_ltm_0(objective_function, search_space, path):
    (search_space, compare) = search_space

    print("\n objective_function \n", objective_function)
    print("\n search_space \n", search_space)
    print("\n compare \n", compare)
    print("\n path \n", path)

    model_name = str(objective_function.__name__)

    hyper = Hyperactive()
    hyper.add_search(objective_function,
                     search_space,
                     n_iter=10,
                     initialize={"random": 1})
    hyper.run()
    results1 = hyper.results(objective_function)

    memory = LongTermMemory(model_name, path=path)
    memory.save(results1, objective_function)
    results2 = memory.load()

    print("\n results1 \n", results1)
    print("\n results2 \n", results2)

    memory.remove_model_data()

    compare(results1, results2)
Example #4
0
def test_ltm_1(objective_function, search_space, path):
    (search_space, compare) = search_space

    print("\n objective_function \n", objective_function)
    print("\n search_space \n", search_space)
    print("\n compare \n", compare)
    print("\n path \n", path)

    model_name = str(objective_function.__name__)
    memory = LongTermMemory(model_name, path=path)

    hyper1 = Hyperactive()
    hyper1.add_search(
        objective_function,
        search_space,
        n_iter=10,
        initialize={"random": 1},
        long_term_memory=memory,
    )
    hyper1.run()
    results1 = hyper1.results(objective_function)

    hyper2 = Hyperactive()
    hyper2.add_search(
        objective_function,
        search_space,
        n_iter=10,
        initialize={"random": 1},
        long_term_memory=memory,
    )
    hyper2.run()
    results2 = hyper2.results(objective_function)
    memory.remove_model_data()

    print("\n results1 \n", results1)
    print("\n results2 \n", results2)
Example #5
0
def test_ltm_int():
    path = "./"
    model_name = "test_ltm_int"
    array = np.arange(3 * 10).reshape(10, 3)
    results1 = pd.DataFrame(array, columns=["x1", "x2", "x3"])

    memory = LongTermMemory(model_name, path=path)
    memory.save(results1, objective_function)

    results2 = memory.load()

    memory.remove_model_data()

    assert results1.equals(results2)
Example #6
0
def test_ltm_str():
    path = "./"
    model_name = "test_ltm_str"
    array = ["str1", "str2", "str3"]
    results1 = pd.DataFrame(
        [array, array, array, array, array], columns=["x1", "x2", "x3"]
    )

    memory = LongTermMemory(model_name, path=path)
    memory.save(results1, objective_function)

    results2 = memory.load()

    memory.remove_model_data()

    assert results1.equals(results2)
Example #7
0
def test_ltm_obj():
    path = "./"
    model_name = "test_ltm_obj"

    array = [class1_(), class2_(), class3_()]
    results1 = pd.DataFrame(
        [array, array, array, array, array], columns=["x1", "x2", "x3"]
    )

    memory = LongTermMemory(model_name, path=path)
    memory.save(results1, objective_function)

    results2 = memory.load()

    memory.remove_model_data()

    for obj_1 in list(results2.values.flatten()):
        assert_ = False
        for obj_2 in array:
            if obj_1.name == obj_2.name:
                assert_ = True
                break

        assert assert_
Example #8
0
def test_ltm_func():
    path = "./"
    model_name = "test_ltm_func"

    array = [func1, func2, func3]
    results1 = pd.DataFrame(
        [array, array, array, array, array], columns=["x1", "x2", "x3"]
    )

    memory = LongTermMemory(model_name, path=path)
    memory.save(results1, objective_function)

    results2 = memory.load()

    memory.remove_model_data()

    func_str_list = []
    for func_ in array:
        func_str_list.append(inspect.getsource(func_))

    for func_ in list(results2.values.flatten()):
        func_str_ = inspect.getsource(func_)
        if func_str_ not in func_str_list:
            assert False