Spaces:
Running
Running
Merge pull request #399 from MilesCranmer/warn-on-power-law
Browse files- pysr/sr.py +12 -3
- pysr/test/test.py +6 -0
- pysr/version.py +1 -1
pysr/sr.py
CHANGED
@@ -104,6 +104,16 @@ def _process_constraints(binary_operators, unary_operators, constraints):
|
|
104 |
constraints[op] = -1
|
105 |
for op in binary_operators:
|
106 |
if op not in constraints:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
constraints[op] = (-1, -1)
|
108 |
if op in ["plus", "sub", "+", "-"]:
|
109 |
if constraints[op][0] != constraints[op][1]:
|
@@ -1264,14 +1274,13 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
1264 |
# Ensure instance parameters are allowable values:
|
1265 |
if self.tournament_selection_n > self.population_size:
|
1266 |
raise ValueError(
|
1267 |
-
"tournament_selection_n parameter must be smaller than population_size
|
1268 |
)
|
1269 |
|
1270 |
if self.maxsize > 40:
|
1271 |
warnings.warn(
|
1272 |
"Note: Using a large maxsize for the equation search will be "
|
1273 |
-
"exponentially slower and use significant memory.
|
1274 |
-
"turning `use_frequency` to False, and perhaps use `warmup_maxsize_by`."
|
1275 |
)
|
1276 |
elif self.maxsize < 7:
|
1277 |
raise ValueError("PySR requires a maxsize of at least 7")
|
|
|
104 |
constraints[op] = -1
|
105 |
for op in binary_operators:
|
106 |
if op not in constraints:
|
107 |
+
if op in ["^", "pow"]:
|
108 |
+
# Warn user that they should set up constraints
|
109 |
+
warnings.warn(
|
110 |
+
"You are using the `^` operator, but have not set up `constraints` for it. "
|
111 |
+
"This may lead to overly complex expressions. "
|
112 |
+
"One typical constraint is to use `constraints={..., '^': (-1, 1)}`, which "
|
113 |
+
"will allow arbitrary-complexity base (-1) but only powers such as "
|
114 |
+
"a constant or variable (1). "
|
115 |
+
"For more tips, please see https://astroautomata.com/PySR/tuning/"
|
116 |
+
)
|
117 |
constraints[op] = (-1, -1)
|
118 |
if op in ["plus", "sub", "+", "-"]:
|
119 |
if constraints[op][0] != constraints[op][1]:
|
|
|
1274 |
# Ensure instance parameters are allowable values:
|
1275 |
if self.tournament_selection_n > self.population_size:
|
1276 |
raise ValueError(
|
1277 |
+
"`tournament_selection_n` parameter must be smaller than `population_size`."
|
1278 |
)
|
1279 |
|
1280 |
if self.maxsize > 40:
|
1281 |
warnings.warn(
|
1282 |
"Note: Using a large maxsize for the equation search will be "
|
1283 |
+
"exponentially slower and use significant memory."
|
|
|
1284 |
)
|
1285 |
elif self.maxsize < 7:
|
1286 |
raise ValueError("PySR requires a maxsize of at least 7")
|
pysr/test/test.py
CHANGED
@@ -20,6 +20,7 @@ from ..sr import (
|
|
20 |
_csv_filename_to_pkl_filename,
|
21 |
idx_model_selection,
|
22 |
_check_assertions,
|
|
|
23 |
)
|
24 |
from ..export_latex import to_latex
|
25 |
|
@@ -553,6 +554,11 @@ class TestMiscellaneous(unittest.TestCase):
|
|
553 |
# The correct value should be set:
|
554 |
self.assertEqual(model.fraction_replaced, 0.2)
|
555 |
|
|
|
|
|
|
|
|
|
|
|
556 |
def test_size_warning(self):
|
557 |
"""Ensure that a warning is given for a large input size."""
|
558 |
model = PySRRegressor()
|
|
|
20 |
_csv_filename_to_pkl_filename,
|
21 |
idx_model_selection,
|
22 |
_check_assertions,
|
23 |
+
_process_constraints,
|
24 |
)
|
25 |
from ..export_latex import to_latex
|
26 |
|
|
|
554 |
# The correct value should be set:
|
555 |
self.assertEqual(model.fraction_replaced, 0.2)
|
556 |
|
557 |
+
def test_power_law_warning(self):
|
558 |
+
"""Ensure that a warning is given for a power law operator."""
|
559 |
+
with self.assertWarns(UserWarning):
|
560 |
+
_process_constraints(["^"], [], {})
|
561 |
+
|
562 |
def test_size_warning(self):
|
563 |
"""Ensure that a warning is given for a large input size."""
|
564 |
model = PySRRegressor()
|
pysr/version.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
__version__ = "0.15.
|
2 |
__symbolic_regression_jl_version__ = "0.21.5"
|
|
|
1 |
+
__version__ = "0.15.4"
|
2 |
__symbolic_regression_jl_version__ = "0.21.5"
|