Spaces:
Running
Running
Commit
·
4f5f994
1
Parent(s):
c25614a
Print actual values for hyperparam search
Browse files- benchmarks/hyperparamopt.py +5 -75
- benchmarks/print_best_model.py +16 -1
- benchmarks/space.py +80 -0
benchmarks/hyperparamopt.py
CHANGED
|
@@ -6,6 +6,7 @@ from pysr import PySRRegressor
|
|
| 6 |
import hyperopt
|
| 7 |
from hyperopt import hp, fmin, tpe, Trials
|
| 8 |
from hyperopt.fmin import generate_trials_to_calculate
|
|
|
|
| 9 |
|
| 10 |
# Change the following code to your file
|
| 11 |
################################################################################
|
|
@@ -24,6 +25,8 @@ model = PySRRegressor(
|
|
| 24 |
timeout_in_seconds=30,
|
| 25 |
julia_project=julia_project,
|
| 26 |
procs=procs,
|
|
|
|
|
|
|
| 27 |
)
|
| 28 |
model.fit(np.random.randn(100, 3), np.random.randn(100))
|
| 29 |
|
|
@@ -62,6 +65,8 @@ def run_trial(args):
|
|
| 62 |
args["timeout_in_seconds"] = timeout_in_minutes * 60
|
| 63 |
args["julia_project"] = julia_project
|
| 64 |
args["procs"] = procs
|
|
|
|
|
|
|
| 65 |
|
| 66 |
print(f"Running trial with args: {args}")
|
| 67 |
|
|
@@ -109,81 +114,6 @@ def run_trial(args):
|
|
| 109 |
return dict(status="ok", loss=loss)
|
| 110 |
|
| 111 |
|
| 112 |
-
space = dict(
|
| 113 |
-
# model_selection="best",
|
| 114 |
-
model_selection=hp.choice("model_selection", ["accuracy"]),
|
| 115 |
-
# binary_operators=None,
|
| 116 |
-
binary_operators=hp.choice("binary_operators", [binary_operators]),
|
| 117 |
-
# unary_operators=None,
|
| 118 |
-
unary_operators=hp.choice("unary_operators", [unary_operators]),
|
| 119 |
-
# populations=100,
|
| 120 |
-
populations=hp.qloguniform("populations", np.log(10), np.log(1000), 1),
|
| 121 |
-
# niterations=4,
|
| 122 |
-
niterations=hp.choice(
|
| 123 |
-
"niterations", [10000]
|
| 124 |
-
), # We will quit automatically based on a clock.
|
| 125 |
-
# ncyclesperiteration=100,
|
| 126 |
-
ncyclesperiteration=hp.qloguniform(
|
| 127 |
-
"ncyclesperiteration", np.log(10), np.log(5000), 1
|
| 128 |
-
),
|
| 129 |
-
# alpha=0.1,
|
| 130 |
-
alpha=hp.loguniform("alpha", np.log(0.0001), np.log(1000)),
|
| 131 |
-
# annealing=False,
|
| 132 |
-
annealing=hp.choice("annealing", [False, True]),
|
| 133 |
-
# fractionReplaced=0.01,
|
| 134 |
-
fractionReplaced=hp.loguniform("fractionReplaced", np.log(0.0001), np.log(0.5)),
|
| 135 |
-
# fractionReplacedHof=0.005,
|
| 136 |
-
fractionReplacedHof=hp.loguniform(
|
| 137 |
-
"fractionReplacedHof", np.log(0.0001), np.log(0.5)
|
| 138 |
-
),
|
| 139 |
-
# npop=100,
|
| 140 |
-
npop=hp.qloguniform("npop", np.log(20), np.log(1000), 1),
|
| 141 |
-
# parsimony=1e-4,
|
| 142 |
-
parsimony=hp.loguniform("parsimony", np.log(0.0001), np.log(0.5)),
|
| 143 |
-
# topn=10,
|
| 144 |
-
topn=hp.qloguniform("topn", np.log(2), np.log(50), 1),
|
| 145 |
-
# weightAddNode=1,
|
| 146 |
-
weightAddNode=hp.loguniform("weightAddNode", np.log(0.0001), np.log(100)),
|
| 147 |
-
# weightInsertNode=3,
|
| 148 |
-
weightInsertNode=hp.loguniform("weightInsertNode", np.log(0.0001), np.log(100)),
|
| 149 |
-
# weightDeleteNode=3,
|
| 150 |
-
weightDeleteNode=hp.loguniform("weightDeleteNode", np.log(0.0001), np.log(100)),
|
| 151 |
-
# weightDoNothing=1,
|
| 152 |
-
weightDoNothing=hp.loguniform("weightDoNothing", np.log(0.0001), np.log(100)),
|
| 153 |
-
# weightMutateConstant=10,
|
| 154 |
-
weightMutateConstant=hp.loguniform(
|
| 155 |
-
"weightMutateConstant", np.log(0.0001), np.log(100)
|
| 156 |
-
),
|
| 157 |
-
# weightMutateOperator=1,
|
| 158 |
-
weightMutateOperator=hp.loguniform(
|
| 159 |
-
"weightMutateOperator", np.log(0.0001), np.log(100)
|
| 160 |
-
),
|
| 161 |
-
# weightRandomize=1,
|
| 162 |
-
weightRandomize=hp.loguniform("weightRandomize", np.log(0.0001), np.log(100)),
|
| 163 |
-
# weightSimplify=0.002,
|
| 164 |
-
weightSimplify=hp.choice("weightSimplify", [0.002]), # One of these is fixed.
|
| 165 |
-
# crossoverProbability=0.01,
|
| 166 |
-
crossoverProbability=hp.loguniform(
|
| 167 |
-
"crossoverProbability", np.log(0.00001), np.log(0.2)
|
| 168 |
-
),
|
| 169 |
-
# perturbationFactor=1.0,
|
| 170 |
-
perturbationFactor=hp.loguniform("perturbationFactor", np.log(0.0001), np.log(100)),
|
| 171 |
-
# maxsize=20,
|
| 172 |
-
maxsize=hp.choice("maxsize", [30]),
|
| 173 |
-
# warmupMaxsizeBy=0.0,
|
| 174 |
-
warmupMaxsizeBy=hp.uniform("warmupMaxsizeBy", 0.0, 0.5),
|
| 175 |
-
# useFrequency=True,
|
| 176 |
-
useFrequency=hp.choice("useFrequency", [True, False]),
|
| 177 |
-
# optimizer_nrestarts=3,
|
| 178 |
-
optimizer_nrestarts=hp.quniform("optimizer_nrestarts", 1, 10, 1),
|
| 179 |
-
# optimize_probability=1.0,
|
| 180 |
-
optimize_probability=hp.uniform("optimize_probability", 0.0, 1.0),
|
| 181 |
-
# optimizer_iterations=10,
|
| 182 |
-
optimizer_iterations=hp.quniform("optimizer_iterations", 1, 10, 1),
|
| 183 |
-
# tournament_selection_p=1.0,
|
| 184 |
-
tournament_selection_p=hp.uniform("tournament_selection_p", 0.0, 1.0),
|
| 185 |
-
)
|
| 186 |
-
|
| 187 |
rand_between = lambda lo, hi: (np.random.rand() * (hi - lo) + lo)
|
| 188 |
|
| 189 |
init_vals = [
|
|
|
|
| 6 |
import hyperopt
|
| 7 |
from hyperopt import hp, fmin, tpe, Trials
|
| 8 |
from hyperopt.fmin import generate_trials_to_calculate
|
| 9 |
+
from space import *
|
| 10 |
|
| 11 |
# Change the following code to your file
|
| 12 |
################################################################################
|
|
|
|
| 25 |
timeout_in_seconds=30,
|
| 26 |
julia_project=julia_project,
|
| 27 |
procs=procs,
|
| 28 |
+
update=False,
|
| 29 |
+
temp_equation_file=True,
|
| 30 |
)
|
| 31 |
model.fit(np.random.randn(100, 3), np.random.randn(100))
|
| 32 |
|
|
|
|
| 65 |
args["timeout_in_seconds"] = timeout_in_minutes * 60
|
| 66 |
args["julia_project"] = julia_project
|
| 67 |
args["procs"] = procs
|
| 68 |
+
args["update"] = False
|
| 69 |
+
args["temp_equation_file"] = True
|
| 70 |
|
| 71 |
print(f"Running trial with args: {args}")
|
| 72 |
|
|
|
|
| 114 |
return dict(status="ok", loss=loss)
|
| 115 |
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
rand_between = lambda lo, hi: (np.random.rand() * (hi - lo) + lo)
|
| 118 |
|
| 119 |
init_vals = [
|
benchmarks/print_best_model.py
CHANGED
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
| 4 |
import pickle as pkl
|
| 5 |
import hyperopt
|
| 6 |
from hyperopt import hp, fmin, tpe, Trials
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
# Change the following code to your file
|
|
@@ -87,4 +88,18 @@ for trial in trials:
|
|
| 87 |
clean_trials = sorted(clean_trials, key=lambda x: x[0])
|
| 88 |
|
| 89 |
for trial in clean_trials:
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import pickle as pkl
|
| 5 |
import hyperopt
|
| 6 |
from hyperopt import hp, fmin, tpe, Trials
|
| 7 |
+
from space import space
|
| 8 |
|
| 9 |
|
| 10 |
# Change the following code to your file
|
|
|
|
| 88 |
clean_trials = sorted(clean_trials, key=lambda x: x[0])
|
| 89 |
|
| 90 |
for trial in clean_trials:
|
| 91 |
+
loss, params = trial
|
| 92 |
+
for k, value in params.items():
|
| 93 |
+
value = value[0]
|
| 94 |
+
if isinstance(value, int):
|
| 95 |
+
possible_args = space[k].pos_args[1:]
|
| 96 |
+
try:
|
| 97 |
+
value = possible_args[value].obj
|
| 98 |
+
except AttributeError:
|
| 99 |
+
value = [arg.obj for arg in possible_args[value].pos_args]
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
params[k] = value
|
| 103 |
+
|
| 104 |
+
print(loss, params)
|
| 105 |
+
|
benchmarks/space.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from hyperopt import hp, fmin, tpe, Trials
|
| 3 |
+
|
| 4 |
+
binary_operators = ["*", "/", "+", "-"]
|
| 5 |
+
unary_operators = ["sin", "cos", "exp", "log"]
|
| 6 |
+
|
| 7 |
+
space = dict(
|
| 8 |
+
# model_selection="best",
|
| 9 |
+
model_selection=hp.choice("model_selection", ["accuracy"]),
|
| 10 |
+
# binary_operators=None,
|
| 11 |
+
binary_operators=hp.choice("binary_operators", [binary_operators]),
|
| 12 |
+
# unary_operators=None,
|
| 13 |
+
unary_operators=hp.choice("unary_operators", [unary_operators]),
|
| 14 |
+
# populations=100,
|
| 15 |
+
populations=hp.qloguniform("populations", np.log(10), np.log(1000), 1),
|
| 16 |
+
# niterations=4,
|
| 17 |
+
niterations=hp.choice(
|
| 18 |
+
"niterations", [10000]
|
| 19 |
+
), # We will quit automatically based on a clock.
|
| 20 |
+
# ncyclesperiteration=100,
|
| 21 |
+
ncyclesperiteration=hp.qloguniform(
|
| 22 |
+
"ncyclesperiteration", np.log(10), np.log(5000), 1
|
| 23 |
+
),
|
| 24 |
+
# alpha=0.1,
|
| 25 |
+
alpha=hp.loguniform("alpha", np.log(0.0001), np.log(1000)),
|
| 26 |
+
# annealing=False,
|
| 27 |
+
annealing=hp.choice("annealing", [False, True]),
|
| 28 |
+
# fractionReplaced=0.01,
|
| 29 |
+
fractionReplaced=hp.loguniform("fractionReplaced", np.log(0.0001), np.log(0.5)),
|
| 30 |
+
# fractionReplacedHof=0.005,
|
| 31 |
+
fractionReplacedHof=hp.loguniform(
|
| 32 |
+
"fractionReplacedHof", np.log(0.0001), np.log(0.5)
|
| 33 |
+
),
|
| 34 |
+
# npop=100,
|
| 35 |
+
npop=hp.qloguniform("npop", np.log(20), np.log(1000), 1),
|
| 36 |
+
# parsimony=1e-4,
|
| 37 |
+
parsimony=hp.loguniform("parsimony", np.log(0.0001), np.log(0.5)),
|
| 38 |
+
# topn=10,
|
| 39 |
+
topn=hp.qloguniform("topn", np.log(2), np.log(50), 1),
|
| 40 |
+
# weightAddNode=1,
|
| 41 |
+
weightAddNode=hp.loguniform("weightAddNode", np.log(0.0001), np.log(100)),
|
| 42 |
+
# weightInsertNode=3,
|
| 43 |
+
weightInsertNode=hp.loguniform("weightInsertNode", np.log(0.0001), np.log(100)),
|
| 44 |
+
# weightDeleteNode=3,
|
| 45 |
+
weightDeleteNode=hp.loguniform("weightDeleteNode", np.log(0.0001), np.log(100)),
|
| 46 |
+
# weightDoNothing=1,
|
| 47 |
+
weightDoNothing=hp.loguniform("weightDoNothing", np.log(0.0001), np.log(100)),
|
| 48 |
+
# weightMutateConstant=10,
|
| 49 |
+
weightMutateConstant=hp.loguniform(
|
| 50 |
+
"weightMutateConstant", np.log(0.0001), np.log(100)
|
| 51 |
+
),
|
| 52 |
+
# weightMutateOperator=1,
|
| 53 |
+
weightMutateOperator=hp.loguniform(
|
| 54 |
+
"weightMutateOperator", np.log(0.0001), np.log(100)
|
| 55 |
+
),
|
| 56 |
+
# weightRandomize=1,
|
| 57 |
+
weightRandomize=hp.loguniform("weightRandomize", np.log(0.0001), np.log(100)),
|
| 58 |
+
# weightSimplify=0.002,
|
| 59 |
+
weightSimplify=hp.choice("weightSimplify", [0.002]), # One of these is fixed.
|
| 60 |
+
# crossoverProbability=0.01,
|
| 61 |
+
crossoverProbability=hp.loguniform(
|
| 62 |
+
"crossoverProbability", np.log(0.00001), np.log(0.2)
|
| 63 |
+
),
|
| 64 |
+
# perturbationFactor=1.0,
|
| 65 |
+
perturbationFactor=hp.loguniform("perturbationFactor", np.log(0.0001), np.log(100)),
|
| 66 |
+
# maxsize=20,
|
| 67 |
+
maxsize=hp.choice("maxsize", [30]),
|
| 68 |
+
# warmupMaxsizeBy=0.0,
|
| 69 |
+
warmupMaxsizeBy=hp.uniform("warmupMaxsizeBy", 0.0, 0.5),
|
| 70 |
+
# useFrequency=True,
|
| 71 |
+
useFrequency=hp.choice("useFrequency", [True, False]),
|
| 72 |
+
# optimizer_nrestarts=3,
|
| 73 |
+
optimizer_nrestarts=hp.quniform("optimizer_nrestarts", 1, 10, 1),
|
| 74 |
+
# optimize_probability=1.0,
|
| 75 |
+
optimize_probability=hp.uniform("optimize_probability", 0.0, 1.0),
|
| 76 |
+
# optimizer_iterations=10,
|
| 77 |
+
optimizer_iterations=hp.quniform("optimizer_iterations", 1, 10, 1),
|
| 78 |
+
# tournament_selection_p=1.0,
|
| 79 |
+
tournament_selection_p=hp.uniform("tournament_selection_p", 0.0, 1.0),
|
| 80 |
+
)
|