Skip to content

Commit

Permalink
Combine builtin variable names test with noisy data test
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Mar 22, 2024
1 parent afdb8dd commit 35f862e
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions pysr/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_warm_start_set_at_init(self):
regressor = PySRRegressor(warm_start=True, max_evals=10)
regressor.fit(self.X, y)

def test_noisy(self):
def test_noisy_builtin_variable_names(self):
y = self.X[:, [0, 1]] ** 2 + self.rstate.randn(self.X.shape[0], 1) * 0.05
model = PySRRegressor(
# Test that passing a single operator works:
Expand All @@ -289,9 +289,12 @@ def test_noisy(self):
model.set_params(model_selection="best")
# Also try without a temp equation file:
model.set_params(temp_equation_file=False)
model.fit(self.X, y)
# We also test builtin variable names
model.fit(self.X, y, variable_names=["exec", "hash", "x3", "x4", "x5"])
self.assertLessEqual(model.get_best()[1]["loss"], 1e-2)
self.assertLessEqual(model.get_best()[1]["loss"], 1e-2)
self.assertIn("exec", model.latex()[1])
self.assertIn("hash", model.latex()[1])

def test_pandas_resample_with_nested_constraints(self):
X = pd.DataFrame(
Expand Down Expand Up @@ -654,19 +657,6 @@ def test_bad_variable_names_fail(self):
model.fit(X, y, variable_names=["f{c}"])
self.assertIn("Invalid variable name", str(cm.exception))

def test_python_built_in_python_funcs_as_variable_names(self):
model = PySRRegressor()
X = np.random.randn(100, 2)
y = np.random.randn(100)

# Should not throw an error
try:
model.fit(X, y, variable_names=["exec", "hash"])
except Exception:
self.fail(
"Should not have thrown when a variable name is a builtin_function_or_method"
)

def test_bad_kwargs(self):
bad_kwargs = [
dict(
Expand Down

0 comments on commit 35f862e

Please sign in to comment.