forked from bayesian-optimization/BayesianOptimization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (48 loc) · 1.88 KB
/
main.py
File metadata and controls
59 lines (48 loc) · 1.88 KB
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
from bayes_opt import BayesianOptimization
from bayes_opt.acquisition import ExpectedImprovement
import numpy as np
def sphere(x, y):
"""sphere function with n amount of inputs
"""
return -(x**2 + y**2)
def branin(x,y):
"""Branin function with 2 inputs"""
return -((y-((5.1/(4*np.pi**2))*x**2)+((5/np.pi)*x)-6)**2+10*(1-(1/(8*np.pi)))*np.cos(x)+10)
def hartmann_3(x,y,z):
"""Hartmann 3 function with 3 inputs"""
alpha = np.array([1.0, 1.2, 3.0, 3.2])
A = np.array([[3.0, 10, 30],
[0.1, 10, 35],
[3.0, 10, 30],
[0.1, 10, 35]])
P = np.array([[0.3689, 0.1170, 0.2673],
[0.4699, 0.4387, 0.7470],
[0.1091, 0.8732, 0.5547],
[0.03815, 0.5743, 0.8828]])
outer = 0
for i in range(4):
inner = 0
for j in range(3):
inner += A[i,j]*(x[j]-P[i,j])**2
outer += alpha[i]*np.exp(-inner)
return -outer
if __name__=='__main__':
# Bounded region of parameter space
pbounds = {'x': (-3, 3), 'y': (-3, 3)}
weights = [1.0, 0.0]
optimizer = BayesianOptimization(
f=[sphere, branin],
pbounds=pbounds,
acquisition_function=ExpectedImprovement(weights=weights,
xi=0.01,
p_decay=30,
p_decay_rate=0.0001,
),
population=False, #Adaptation model is funky and good at start but not good otherwise
save=False) #Additionally try to make py file that plots pop models
optimizer.maximize(
init_points=0,
n_iter=25)
# for i, res in enumerate(optimizer.res):
# print("Iteration {}: \n\t{}".format(i, res))
# #print(f"GP: {optimizer._gp.get_params()}")k