Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
β’
8df173b
1
Parent(s):
998d3bd
Update hyperparam optimizer script
Browse files
hyperparamopt.py β benchmarks/hyperparamopt.py
RENAMED
@@ -34,58 +34,46 @@ def run_trial(args):
|
|
34 |
"""
|
35 |
|
36 |
print("Running on", args)
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
total_steps = 10*100*1000
|
42 |
-
niterations = args['niterations']
|
43 |
-
npop = args['npop']
|
44 |
-
if niterations == 0 or npop == 0:
|
45 |
-
print("Bad parameters")
|
46 |
-
return {'status': 'ok', 'loss': np.inf}
|
47 |
-
|
48 |
-
args['ncyclesperiteration'] = int(total_steps / (niterations * npop))
|
49 |
args['topn'] = 10
|
50 |
-
args['parsimony'] =
|
|
|
51 |
args['annealing'] = True
|
52 |
|
53 |
if args['npop'] < 20 or args['ncyclesperiteration'] < 3:
|
54 |
print("Bad parameters")
|
55 |
return {'status': 'ok', 'loss': np.inf}
|
56 |
|
57 |
-
|
58 |
args['weightDoNothing'] = 1.0
|
59 |
-
|
60 |
-
maxTime = 30
|
61 |
-
ntrials = 2
|
62 |
-
equation_file = f'.hall_of_fame_{np.random.rand():f}.csv'
|
63 |
|
64 |
with temp_seed(0):
|
65 |
-
X = np.random.randn(100,
|
66 |
|
67 |
-
eval_str = [
|
68 |
-
"np.sign(X[:, 2])*np.abs(X[:, 2])**
|
69 |
"np.exp(X[:, 0]/2) + 12.0 + np.log(np.abs(X[:, 0])*10 + 1)",
|
70 |
-
"
|
71 |
-
"
|
|
|
72 |
|
73 |
print(f"Starting", str(args))
|
74 |
try:
|
75 |
trials = []
|
76 |
-
for i in range(
|
77 |
print(f"Starting test {i}")
|
78 |
for j in range(ntrials):
|
79 |
print(f"Starting trial {j}")
|
80 |
-
|
81 |
-
|
82 |
procs=4,
|
|
|
83 |
binary_operators=["plus", "mult", "pow", "div"],
|
84 |
-
unary_operators=["cos", "exp", "sin", "
|
85 |
-
equation_file=equation_file,
|
86 |
-
timeout=maxTime,
|
87 |
maxsize=25,
|
88 |
-
|
89 |
**args)
|
90 |
if len(trial) == 0: raise ValueError
|
91 |
trials.append(
|
@@ -109,8 +97,6 @@ def run_trial(args):
|
|
109 |
|
110 |
|
111 |
space = {
|
112 |
-
'niterations': hp.qlognormal('niterations', np.log(10), 1.0, 1),
|
113 |
-
'npop': hp.qlognormal('npop', np.log(100), 1.0, 1),
|
114 |
'alpha': hp.lognormal('alpha', np.log(10.0), 1.0),
|
115 |
'fractionReplacedHof': hp.lognormal('fractionReplacedHof', np.log(0.1), 1.0),
|
116 |
'fractionReplaced': hp.lognormal('fractionReplaced', np.log(0.1), 1.0),
|
@@ -126,8 +112,6 @@ space = {
|
|
126 |
|
127 |
################################################################################
|
128 |
|
129 |
-
|
130 |
-
|
131 |
def merge_trials(trials1, trials2_slice):
|
132 |
"""Merge two hyperopt trials objects
|
133 |
|
|
|
34 |
"""
|
35 |
|
36 |
print("Running on", args)
|
37 |
+
args['niterations'] = 100
|
38 |
+
args['npop'] = 100
|
39 |
+
args['ncyclesperiteration'] = 1000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
args['topn'] = 10
|
41 |
+
args['parsimony'] = 0.0
|
42 |
+
args['useFrequency'] = True
|
43 |
args['annealing'] = True
|
44 |
|
45 |
if args['npop'] < 20 or args['ncyclesperiteration'] < 3:
|
46 |
print("Bad parameters")
|
47 |
return {'status': 'ok', 'loss': np.inf}
|
48 |
|
|
|
49 |
args['weightDoNothing'] = 1.0
|
50 |
+
ntrials = 3
|
|
|
|
|
|
|
51 |
|
52 |
with temp_seed(0):
|
53 |
+
X = np.random.randn(100, 10)*3
|
54 |
|
55 |
+
eval_str = [
|
56 |
+
"np.sign(X[:, 2])*np.abs(X[:, 2])**2.5 + 5*np.cos(X[:, 3]) - 5",
|
57 |
"np.exp(X[:, 0]/2) + 12.0 + np.log(np.abs(X[:, 0])*10 + 1)",
|
58 |
+
"(np.exp(X[:, 3]) + 3)/(np.abs(X[:, 1]) + np.cos(X[:, 0]) + 1.1)",
|
59 |
+
"X[:, 0] * np.sin(2*np.pi * (X[:, 1] * X[:, 2] - X[:, 3] / X[:, 4])) + 3.0"
|
60 |
+
]
|
61 |
|
62 |
print(f"Starting", str(args))
|
63 |
try:
|
64 |
trials = []
|
65 |
+
for i in range(len(eval_str)):
|
66 |
print(f"Starting test {i}")
|
67 |
for j in range(ntrials):
|
68 |
print(f"Starting trial {j}")
|
69 |
+
y = eval(eval_str[i])
|
70 |
+
trial = pysr.pysr(X, y,
|
71 |
procs=4,
|
72 |
+
populations=20,
|
73 |
binary_operators=["plus", "mult", "pow", "div"],
|
74 |
+
unary_operators=["cos", "exp", "sin", "logm", "abs"],
|
|
|
|
|
75 |
maxsize=25,
|
76 |
+
constraints={'pow': (-1, 1)},
|
77 |
**args)
|
78 |
if len(trial) == 0: raise ValueError
|
79 |
trials.append(
|
|
|
97 |
|
98 |
|
99 |
space = {
|
|
|
|
|
100 |
'alpha': hp.lognormal('alpha', np.log(10.0), 1.0),
|
101 |
'fractionReplacedHof': hp.lognormal('fractionReplacedHof', np.log(0.1), 1.0),
|
102 |
'fractionReplaced': hp.lognormal('fractionReplaced', np.log(0.1), 1.0),
|
|
|
112 |
|
113 |
################################################################################
|
114 |
|
|
|
|
|
115 |
def merge_trials(trials1, trials2_slice):
|
116 |
"""Merge two hyperopt trials objects
|
117 |
|