Passed
Pull Request — master (#101)
by Simon
01:35
created

objective_function()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
import time
2
import pytest
3
import numpy as np
4
import pandas as pd
5
6
from hyperactive import Hyperactive
7
8
9
def func1():
10
    pass
11
12
13
def func2():
14
    pass
15
16
17
class class1:
18
    def __init__(self):
19
        pass
20
21
22
class class2:
23
    def __init__(self):
24
        pass
25
26
27
def class_f1():
28
    return class1
29
30
31
def class_f2():
32
    return class2
33
34
35
def numpy_f1():
36
    return np.array([0, 1])
37
38
39
def numpy_f2():
40
    return np.array([1, 0])
41
42
43
search_space = {
44
    "x0": list(range(-3, 3)),
45
    "x1": list(np.arange(-1, 1, 0.001)),
46
    "string0": ["str0", "str1"],
47
    "function0": [func1, func2],
48
    "class0": [class_f1, class_f2],
49
    "numpy0": [numpy_f1, numpy_f2],
50
}
51
52
53
def objective_function(opt):
54
    score = -opt["x1"] * opt["x1"]
55
    return score
56
57
58
def test_warm_start_0():
59
    hyper0 = Hyperactive()
60
    hyper0.add_search(objective_function, search_space, n_iter=15)
61
    hyper0.run()
62
63
    best_para0 = hyper0.best_para(objective_function)
64
65
    hyper1 = Hyperactive()
66
    hyper1.add_search(
67
        objective_function,
68
        search_space,
69
        n_iter=15,
70
        initialize={"warm_start": [best_para0]},
71
    )
72
    hyper1.run()
73
74
75
def test_warm_start_1():
76
    hyper0 = Hyperactive(distribution="pathos")
77
    hyper0.add_search(objective_function, search_space, n_iter=15, n_jobs=2)
78
    hyper0.run()
79
80
    best_para0 = hyper0.best_para(objective_function)
81
82
    hyper1 = Hyperactive()
83
    hyper1.add_search(
84
        objective_function,
85
        search_space,
86
        n_iter=15,
87
        initialize={"warm_start": [best_para0]},
88
    )
89
    hyper1.run()
90
91
92
def test_warm_start_2():
93
    hyper0 = Hyperactive()
94
    hyper0.add_search(objective_function, search_space, n_iter=15)
95
    hyper0.run()
96
97
    best_para0 = hyper0.best_para(objective_function)
98
99
    hyper1 = Hyperactive(distribution="pathos")
100
    hyper1.add_search(
101
        objective_function,
102
        search_space,
103
        n_iter=15,
104
        n_jobs=2,
105
        initialize={"warm_start": [best_para0]},
106
    )
107
    hyper1.run()
108
109
110
def test_warm_start_3():
111
    hyper0 = Hyperactive(distribution="pathos")
112
    hyper0.add_search(objective_function, search_space, n_iter=15, n_jobs=2)
113
    hyper0.run()
114
115
    best_para0 = hyper0.best_para(objective_function)
116
117
    hyper1 = Hyperactive(distribution="pathos")
118
    hyper1.add_search(
119
        objective_function,
120
        search_space,
121
        n_iter=15,
122
        n_jobs=2,
123
        initialize={"warm_start": [best_para0]},
124
    )
125
    hyper1.run()
126