Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
d7444a2
1
Parent(s):
1adfa85
Remove old _using_test_input function
Browse files- pysr/sr.py +54 -75
pysr/sr.py
CHANGED
@@ -61,61 +61,60 @@ sympy_mappings = {
|
|
61 |
'gamma': lambda x : sympy.gamma(x),
|
62 |
}
|
63 |
|
64 |
-
def pysr(X
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
optimizer_iterations=10,
|
119 |
):
|
120 |
"""Run symbolic regression to fit f(X[i, :]) ~ y[i] for all i.
|
121 |
Note: most default parameters have been tuned over several example
|
@@ -184,7 +183,6 @@ def pysr(X=None, y=None, weights=None,
|
|
184 |
constant parts by evaluation
|
185 |
:param timeout: float, Time in seconds to timeout search
|
186 |
:param equation_file: str, Where to save the files (.csv separated by |)
|
187 |
-
:param test: str, What test to run, if X,y not passed.
|
188 |
:param verbosity: int, What verbosity level to use. 0 means minimal print statements.
|
189 |
:param progress: bool, Whether to use a progress bar instead of printing to stdout.
|
190 |
:param maxsize: int, Max size of an equation.
|
@@ -280,8 +278,6 @@ def pysr(X=None, y=None, weights=None,
|
|
280 |
binary_operators = [binary_operators]
|
281 |
if isinstance(unary_operators, str):
|
282 |
unary_operators = [unary_operators]
|
283 |
-
if X is None:
|
284 |
-
X, y = _using_test_input(X, test, y)
|
285 |
|
286 |
if len(y.shape) == 1 or (len(y.shape) == 2 and y.shape[1] == 1):
|
287 |
multioutput = False
|
@@ -644,23 +640,6 @@ def _create_inline_operators(binary_operators, unary_operators, **kwargs):
|
|
644 |
return def_hyperparams
|
645 |
|
646 |
|
647 |
-
def _using_test_input(X, test, y):
|
648 |
-
if test == 'simple1':
|
649 |
-
eval_str = "np.sign(X[:, 2])*np.abs(X[:, 2])**2.5 + 5*np.cos(X[:, 3]) - 5"
|
650 |
-
elif test == 'simple2':
|
651 |
-
eval_str = "np.sign(X[:, 2])*np.abs(X[:, 2])**3.5 + 1/(np.abs(X[:, 0])+1)"
|
652 |
-
elif test == 'simple3':
|
653 |
-
eval_str = "np.exp(X[:, 0]/2) + 12.0 + np.log(np.abs(X[:, 0])*10 + 1)"
|
654 |
-
elif test == 'simple4':
|
655 |
-
eval_str = "1.0 + 3*X[:, 0]**2 - 0.5*X[:, 0]**3 + 0.1*X[:, 0]**4"
|
656 |
-
elif test == 'simple5':
|
657 |
-
eval_str = "(np.exp(X[:, 3]) + 3)/(np.abs(X[:, 1]) + np.cos(X[:, 0]) + 1.1)"
|
658 |
-
X = np.random.randn(100, 5) * 3
|
659 |
-
y = eval(eval_str)
|
660 |
-
print("Running on", eval_str)
|
661 |
-
return X, y
|
662 |
-
|
663 |
-
|
664 |
def _handle_feature_selection(X, select_k_features, use_custom_variable_names, variable_names, y):
|
665 |
if select_k_features is not None:
|
666 |
selection = run_feature_selection(X, y, select_k_features)
|
|
|
61 |
'gamma': lambda x : sympy.gamma(x),
|
62 |
}
|
63 |
|
64 |
+
def pysr(X, y, weights=None,
|
65 |
+
binary_operators=None,
|
66 |
+
unary_operators=None,
|
67 |
+
procs=4,
|
68 |
+
loss='L2DistLoss()',
|
69 |
+
populations=20,
|
70 |
+
niterations=100,
|
71 |
+
ncyclesperiteration=300,
|
72 |
+
alpha=0.1,
|
73 |
+
annealing=False,
|
74 |
+
fractionReplaced=0.10,
|
75 |
+
fractionReplacedHof=0.10,
|
76 |
+
npop=1000,
|
77 |
+
parsimony=1e-4,
|
78 |
+
migration=True,
|
79 |
+
hofMigration=True,
|
80 |
+
shouldOptimizeConstants=True,
|
81 |
+
topn=10,
|
82 |
+
weightAddNode=1,
|
83 |
+
weightInsertNode=3,
|
84 |
+
weightDeleteNode=3,
|
85 |
+
weightDoNothing=1,
|
86 |
+
weightMutateConstant=10,
|
87 |
+
weightMutateOperator=1,
|
88 |
+
weightRandomize=1,
|
89 |
+
weightSimplify=0.01,
|
90 |
+
perturbationFactor=1.0,
|
91 |
+
timeout=None,
|
92 |
+
extra_sympy_mappings=None,
|
93 |
+
equation_file=None,
|
94 |
+
verbosity=1e9,
|
95 |
+
progress=True,
|
96 |
+
maxsize=20,
|
97 |
+
fast_cycle=False,
|
98 |
+
maxdepth=None,
|
99 |
+
variable_names=None,
|
100 |
+
batching=False,
|
101 |
+
batchSize=50,
|
102 |
+
select_k_features=None,
|
103 |
+
warmupMaxsizeBy=0.0,
|
104 |
+
constraints=None,
|
105 |
+
useFrequency=True,
|
106 |
+
tempdir=None,
|
107 |
+
delete_tempfiles=True,
|
108 |
+
julia_optimization=3,
|
109 |
+
julia_project=None,
|
110 |
+
user_input=True,
|
111 |
+
update=True,
|
112 |
+
temp_equation_file=False,
|
113 |
+
output_jax_format=False,
|
114 |
+
optimizer_algorithm="BFGS",
|
115 |
+
optimizer_nrestarts=3,
|
116 |
+
optimize_probability=1.0,
|
117 |
+
optimizer_iterations=10,
|
|
|
118 |
):
|
119 |
"""Run symbolic regression to fit f(X[i, :]) ~ y[i] for all i.
|
120 |
Note: most default parameters have been tuned over several example
|
|
|
183 |
constant parts by evaluation
|
184 |
:param timeout: float, Time in seconds to timeout search
|
185 |
:param equation_file: str, Where to save the files (.csv separated by |)
|
|
|
186 |
:param verbosity: int, What verbosity level to use. 0 means minimal print statements.
|
187 |
:param progress: bool, Whether to use a progress bar instead of printing to stdout.
|
188 |
:param maxsize: int, Max size of an equation.
|
|
|
278 |
binary_operators = [binary_operators]
|
279 |
if isinstance(unary_operators, str):
|
280 |
unary_operators = [unary_operators]
|
|
|
|
|
281 |
|
282 |
if len(y.shape) == 1 or (len(y.shape) == 2 and y.shape[1] == 1):
|
283 |
multioutput = False
|
|
|
640 |
return def_hyperparams
|
641 |
|
642 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
643 |
def _handle_feature_selection(X, select_k_features, use_custom_variable_names, variable_names, y):
|
644 |
if select_k_features is not None:
|
645 |
selection = run_feature_selection(X, y, select_k_features)
|