-
Notifications
You must be signed in to change notification settings - Fork 18
/
axcube.py
69 lines (52 loc) · 2.2 KB
/
axcube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from funcy import print_durations
from humpday.inclusion.axplatforminclusion import using_axplatform
if using_axplatform:
from ax import optimize
from logging import CRITICAL
from ax.utils.common.logger import get_logger
rt = get_logger('ax')
rt.setLevel(CRITICAL)
import warnings
warnings.filterwarnings("ignore")
# Your code here
def ax_cube(objective, n_trials, n_dim, with_count=False, method=None):
global feval_count
feval_count = 0
rt = get_logger('ax')
rt.setLevel(CRITICAL)
def evaluation_func(prms):
global feval_count
feval_count += 1
return objective([prms["u" + str(i)] for i in range(n_dim)])
parameters = [{
"name": "u" + str(i),
"type": "range",
"bounds": [0.0, 1.0],
} for i in range(n_dim)]
best_parameters, best_values, experiment, model = optimize(parameters=parameters,
evaluation_function=evaluation_func,
minimize=True,
total_trials=n_trials)
best_x = [ best_parameters['u'+str(i)] for i in range(n_dim) ]
best_val = best_values[0]['objective']
return (best_val, best_x, feval_count) if with_count else (best_val, best_x)
def ax_default_cube(objective, n_trials, n_dim, with_count=False):
return ax_cube(objective=objective, n_trials=n_trials, n_dim=n_dim, with_count=with_count)
AX_OPTIMIZERS = [ ax_default_cube ]
AX_TOP_OPTIMIZERS = [ax_default_cube]
else:
AX_OPTIMIZERS = []
AX_TOP_OPTIMIZERS = []
if __name__=='__main__':
if using_axplatform:
print(AX_OPTIMIZERS)
from humpday.objectives.classic import CLASSIC_OBJECTIVES
def demo():
for objective in CLASSIC_OBJECTIVES:
print(' ')
print(objective.__name__)
for optimizer in AX_OPTIMIZERS:
print(optimizer(objective, n_trials=25, n_dim=3, with_count=True))
demo()
else:
print('pip install ax-platform')