-
Notifications
You must be signed in to change notification settings - Fork 1
/
optimization.py
42 lines (32 loc) · 946 Bytes
/
optimization.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
# %%
from solution import hit_rate
from scipy import optimize as opt
from scipy.optimize import Bounds
from noisyopt import minimizeCompass, minimizeSPSA
h_upper = 2
h_lower = 1
alpha_upper = 90
v0_upper = 20
def objective(x, n=100):
# x in [0,1]^3
# map to correct range
h = h_lower + (h_upper - h_lower) * x[0]
alpha = x[1]*alpha_upper
v0 = x[2]*v0_upper
print(h, alpha, v0)
res = 1-hit_rate(h, alpha, v0, n, False)
print(res)
return res
bounds = [[0, 1], [1e-3, 1], [1e-3, 1]]
x0 = [1., 60.3/90, 7.112/20] # h,alpha,v0
for n in [10000]:
# if n <= 1000:
res = minimizeCompass(lambda x: objective(x, n), x0, bounds=bounds,
paired=False, deltatol=0.01)
# else:
# print('slsqp')
# res = opt.minimize(lambda x: objective(x, n), x0, method='trust-constr',
# options={'verbose': 1.}, bounds=bounds, tol=1e-9)
# %%
print(res)
# %%