1
|
|
|
# Author: Simon Blanke |
2
|
|
|
# Email: [email protected] |
3
|
|
|
# License: MIT License |
4
|
|
|
|
5
|
|
|
import numpy as np |
6
|
|
|
|
7
|
|
|
from hyperactive import Hyperactive |
8
|
|
|
|
9
|
|
|
X, y = np.array([0]), np.array([0]) |
10
|
|
|
memory = False |
11
|
|
|
n_iter = 25 |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
def sphere_function(para, X_train, y_train): |
15
|
|
|
loss = [] |
16
|
|
|
for key in para.keys(): |
17
|
|
|
if key == "iteration": |
18
|
|
|
continue |
19
|
|
|
loss.append(para[key] * para[key]) |
20
|
|
|
|
21
|
|
|
return -np.array(loss).sum() |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
search_config = { |
25
|
|
|
sphere_function: {"x1": np.arange(-3, 3, 0.1), "x2": np.arange(-3, 3, 0.1)} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
def test_start_up_evals(): |
30
|
|
|
for start_up_evals in [1, 100]: |
31
|
|
|
opt = Hyperactive(X, y, memory=memory) |
32
|
|
|
opt.search( |
33
|
|
|
search_config, |
34
|
|
|
n_iter=n_iter, |
35
|
|
|
optimizer={"Bayesian": {"start_up_evals": start_up_evals}}, |
36
|
|
|
) |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
def test_warm_start_smbo(): |
40
|
|
|
opt = Hyperactive(X, y, memory="long") |
41
|
|
|
opt.search( |
42
|
|
|
search_config, n_iter=n_iter, optimizer={"Bayesian": {"warm_start_smbo": True}} |
43
|
|
|
) |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
def test_max_sample_size(): |
47
|
|
|
for max_sample_size in [10, 100, 10000, 10000000000]: |
48
|
|
|
opt = Hyperactive(X, y, memory=memory) |
49
|
|
|
opt.search( |
50
|
|
|
search_config, |
51
|
|
|
n_iter=n_iter, |
52
|
|
|
optimizer={"Bayesian": {"max_sample_size": True}}, |
53
|
|
|
) |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
def test_gpr(): |
57
|
|
|
opt = Hyperactive(X, y, memory=memory) |
58
|
|
|
opt.search( |
59
|
|
|
search_config, n_iter=n_iter, optimizer={"Bayesian": {"gpr": "gp_linear"}} |
60
|
|
|
) |
61
|
|
|
|