-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparamOptimizer_example.py
48 lines (37 loc) · 1.04 KB
/
paramOptimizer_example.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
"""
Author : Abdullah Al Masud\n
email : [email protected]\n
LICENSE : MIT License
"""
import warnings
import matplotlib.pyplot as plt
import os
import sys
project_dir = os.getcwd()
sys.path.append(project_dir)
from msdlib import msd
# warnings.filterwarnings('ignore')
params = {
'x': list(range(1, 100, 10)),
'y': list(range(0, 15, 2))
}
function = lambda x, y: x**2 - 5*y + 2 - 1/x
######### GRID search #####################
optimizer = msd.paramOptimizer(params, mode='grid')
while True:
param = optimizer.get_param()
score = function(param['x'], param['y'])
end = optimizer.set_score(score)
if end:
break
print(optimizer.best())
######### RANDOM search #####################
optimizer = msd.paramOptimizer(params, mode='random', iteration=15)
while True:
param = optimizer.get_param()
score = function(param['x'], param['y'])
end = optimizer.set_score(score)
if end:
break
print(optimizer.best())
assert optimizer.best()[0]['score'].iloc[0] <= -18, 'best-score is greater than -18'