forked from dragonfly/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathin_code_demo_1.py
37 lines (28 loc) · 904 Bytes
/
in_code_demo_1.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
"""
In code demo for discrete euclidean domains
"""
import numpy as np
from dragonfly import load_config, maximise_function
def objective(x):
""" Objective. """
return np.linalg.norm(x[0])
def main():
""" Main function. """
size = 1000
dim = 3
disc_euc_items = list(np.random.random((size, dim)))
domain_vars = [
{'type': 'discrete_euclidean', 'items': disc_euc_items},
]
config_params = {'domain': domain_vars}
config = load_config(config_params)
max_num_evals = 100
# specify optimisation method
# opt_method = 'bo' # Bayesian optimisation
opt_method = 'ea' # evolutionary algorithm
# opt_method = 'rand' # random search
opt_val, opt_pt, history = maximise_function(objective, config.domain, max_num_evals,
config=config, opt_method=opt_method)
print(opt_pt, opt_val)
if __name__ == '__main__':
main()