Spaces:
Running
Running
Merge pull request #176 from MilesCranmer/normal-csv-format
Browse files- pysr/sr.py +5 -5
- pysr/version.py +2 -2
- test/test.py +5 -5
- test/test_jax.py +6 -6
- test/test_torch.py +9 -9
pysr/sr.py
CHANGED
|
@@ -469,7 +469,7 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 469 |
Whether to use a progress bar instead of printing to stdout.
|
| 470 |
|
| 471 |
equation_file : str, default=None
|
| 472 |
-
Where to save the files (
|
| 473 |
|
| 474 |
temp_equation_file : bool, default=False
|
| 475 |
Whether to put the hall of fame file in the temp directory.
|
|
@@ -1969,12 +1969,12 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1969 |
cur_filename = str(self.equation_file_) + f".out{i}" + ".bkup"
|
| 1970 |
if not os.path.exists(cur_filename):
|
| 1971 |
cur_filename = str(self.equation_file_) + f".out{i}"
|
| 1972 |
-
df = pd.read_csv(cur_filename
|
| 1973 |
# Rename Complexity column to complexity:
|
| 1974 |
df.rename(
|
| 1975 |
columns={
|
| 1976 |
"Complexity": "complexity",
|
| 1977 |
-
"
|
| 1978 |
"Equation": "equation",
|
| 1979 |
},
|
| 1980 |
inplace=True,
|
|
@@ -1985,11 +1985,11 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1985 |
filename = str(self.equation_file_) + ".bkup"
|
| 1986 |
if not os.path.exists(filename):
|
| 1987 |
filename = str(self.equation_file_)
|
| 1988 |
-
all_outputs = [pd.read_csv(filename
|
| 1989 |
all_outputs[-1].rename(
|
| 1990 |
columns={
|
| 1991 |
"Complexity": "complexity",
|
| 1992 |
-
"
|
| 1993 |
"Equation": "equation",
|
| 1994 |
},
|
| 1995 |
inplace=True,
|
|
|
|
| 469 |
Whether to use a progress bar instead of printing to stdout.
|
| 470 |
|
| 471 |
equation_file : str, default=None
|
| 472 |
+
Where to save the files (with `.csv` extension).
|
| 473 |
|
| 474 |
temp_equation_file : bool, default=False
|
| 475 |
Whether to put the hall of fame file in the temp directory.
|
|
|
|
| 1969 |
cur_filename = str(self.equation_file_) + f".out{i}" + ".bkup"
|
| 1970 |
if not os.path.exists(cur_filename):
|
| 1971 |
cur_filename = str(self.equation_file_) + f".out{i}"
|
| 1972 |
+
df = pd.read_csv(cur_filename)
|
| 1973 |
# Rename Complexity column to complexity:
|
| 1974 |
df.rename(
|
| 1975 |
columns={
|
| 1976 |
"Complexity": "complexity",
|
| 1977 |
+
"Loss": "loss",
|
| 1978 |
"Equation": "equation",
|
| 1979 |
},
|
| 1980 |
inplace=True,
|
|
|
|
| 1985 |
filename = str(self.equation_file_) + ".bkup"
|
| 1986 |
if not os.path.exists(filename):
|
| 1987 |
filename = str(self.equation_file_)
|
| 1988 |
+
all_outputs = [pd.read_csv(filename)]
|
| 1989 |
all_outputs[-1].rename(
|
| 1990 |
columns={
|
| 1991 |
"Complexity": "complexity",
|
| 1992 |
+
"Loss": "loss",
|
| 1993 |
"Equation": "equation",
|
| 1994 |
},
|
| 1995 |
inplace=True,
|
pysr/version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
__version__ = "0.
|
| 2 |
-
__symbolic_regression_jl_version__ = "0.
|
|
|
|
| 1 |
+
__version__ = "0.10.0"
|
| 2 |
+
__symbolic_regression_jl_version__ = "0.10.0"
|
test/test.py
CHANGED
|
@@ -288,10 +288,10 @@ class TestPipeline(unittest.TestCase):
|
|
| 288 |
def test_load_model(self):
|
| 289 |
"""See if we can load a ran model from the equation file."""
|
| 290 |
csv_file_data = """
|
| 291 |
-
Complexity
|
| 292 |
-
1
|
| 293 |
-
3
|
| 294 |
-
4
|
| 295 |
# Strip the indents:
|
| 296 |
csv_file_data = "\n".join([l.strip() for l in csv_file_data.split("\n")])
|
| 297 |
|
|
@@ -379,7 +379,7 @@ class TestBest(unittest.TestCase):
|
|
| 379 |
self.model.selection_mask_ = None
|
| 380 |
self.model.feature_names_in_ = np.array(["x0", "x1"], dtype=object)
|
| 381 |
equations["complexity loss equation".split(" ")].to_csv(
|
| 382 |
-
"equation_file.csv.bkup"
|
| 383 |
)
|
| 384 |
|
| 385 |
self.model.refresh()
|
|
|
|
| 288 |
def test_load_model(self):
|
| 289 |
"""See if we can load a ran model from the equation file."""
|
| 290 |
csv_file_data = """
|
| 291 |
+
Complexity,Loss,Equation
|
| 292 |
+
1,0.19951081,"1.9762075"
|
| 293 |
+
3,0.12717344,"(f0 + 1.4724599)"
|
| 294 |
+
4,0.104823045,"pow_abs(2.2683423, cos(f3))\""""
|
| 295 |
# Strip the indents:
|
| 296 |
csv_file_data = "\n".join([l.strip() for l in csv_file_data.split("\n")])
|
| 297 |
|
|
|
|
| 379 |
self.model.selection_mask_ = None
|
| 380 |
self.model.feature_names_in_ = np.array(["x0", "x1"], dtype=object)
|
| 381 |
equations["complexity loss equation".split(" ")].to_csv(
|
| 382 |
+
"equation_file.csv.bkup"
|
| 383 |
)
|
| 384 |
|
| 385 |
self.model.refresh()
|
test/test_jax.py
CHANGED
|
@@ -34,13 +34,13 @@ class TestJAX(unittest.TestCase):
|
|
| 34 |
equations = pd.DataFrame(
|
| 35 |
{
|
| 36 |
"Equation": ["1.0", "cos(x1)", "square(cos(x1))"],
|
| 37 |
-
"
|
| 38 |
"Complexity": [1, 2, 3],
|
| 39 |
}
|
| 40 |
)
|
| 41 |
|
| 42 |
-
equations["Complexity
|
| 43 |
-
"equation_file.csv.bkup"
|
| 44 |
)
|
| 45 |
|
| 46 |
model.refresh(checkpoint_file="equation_file.csv")
|
|
@@ -61,13 +61,13 @@ class TestJAX(unittest.TestCase):
|
|
| 61 |
equations = pd.DataFrame(
|
| 62 |
{
|
| 63 |
"Equation": ["1.0", "cos(x1)", "square(cos(x1))"],
|
| 64 |
-
"
|
| 65 |
"Complexity": [1, 2, 3],
|
| 66 |
}
|
| 67 |
)
|
| 68 |
|
| 69 |
-
equations["Complexity
|
| 70 |
-
"equation_file.csv.bkup"
|
| 71 |
)
|
| 72 |
|
| 73 |
model.refresh(checkpoint_file="equation_file.csv")
|
|
|
|
| 34 |
equations = pd.DataFrame(
|
| 35 |
{
|
| 36 |
"Equation": ["1.0", "cos(x1)", "square(cos(x1))"],
|
| 37 |
+
"Loss": [1.0, 0.1, 1e-5],
|
| 38 |
"Complexity": [1, 2, 3],
|
| 39 |
}
|
| 40 |
)
|
| 41 |
|
| 42 |
+
equations["Complexity Loss Equation".split(" ")].to_csv(
|
| 43 |
+
"equation_file.csv.bkup"
|
| 44 |
)
|
| 45 |
|
| 46 |
model.refresh(checkpoint_file="equation_file.csv")
|
|
|
|
| 61 |
equations = pd.DataFrame(
|
| 62 |
{
|
| 63 |
"Equation": ["1.0", "cos(x1)", "square(cos(x1))"],
|
| 64 |
+
"Loss": [1.0, 0.1, 1e-5],
|
| 65 |
"Complexity": [1, 2, 3],
|
| 66 |
}
|
| 67 |
)
|
| 68 |
|
| 69 |
+
equations["Complexity Loss Equation".split(" ")].to_csv(
|
| 70 |
+
"equation_file.csv.bkup"
|
| 71 |
)
|
| 72 |
|
| 73 |
model.refresh(checkpoint_file="equation_file.csv")
|
test/test_torch.py
CHANGED
|
@@ -49,13 +49,13 @@ class TestTorch(unittest.TestCase):
|
|
| 49 |
equations = pd.DataFrame(
|
| 50 |
{
|
| 51 |
"Equation": ["1.0", "cos(x1)", "square(cos(x1))"],
|
| 52 |
-
"
|
| 53 |
"Complexity": [1, 2, 3],
|
| 54 |
}
|
| 55 |
)
|
| 56 |
|
| 57 |
-
equations["Complexity
|
| 58 |
-
"equation_file.csv.bkup"
|
| 59 |
)
|
| 60 |
|
| 61 |
model.refresh(checkpoint_file="equation_file.csv")
|
|
@@ -82,13 +82,13 @@ class TestTorch(unittest.TestCase):
|
|
| 82 |
equations = pd.DataFrame(
|
| 83 |
{
|
| 84 |
"Equation": ["1.0", "cos(x1)", "square(cos(x1))"],
|
| 85 |
-
"
|
| 86 |
"Complexity": [1, 2, 3],
|
| 87 |
}
|
| 88 |
)
|
| 89 |
|
| 90 |
-
equations["Complexity
|
| 91 |
-
"equation_file.csv.bkup"
|
| 92 |
)
|
| 93 |
|
| 94 |
model.refresh(checkpoint_file="equation_file.csv")
|
|
@@ -133,13 +133,13 @@ class TestTorch(unittest.TestCase):
|
|
| 133 |
equations = pd.DataFrame(
|
| 134 |
{
|
| 135 |
"Equation": ["1.0", "mycustomoperator(x1)"],
|
| 136 |
-
"
|
| 137 |
"Complexity": [1, 2],
|
| 138 |
}
|
| 139 |
)
|
| 140 |
|
| 141 |
-
equations["Complexity
|
| 142 |
-
"equation_file_custom_operator.csv.bkup"
|
| 143 |
)
|
| 144 |
|
| 145 |
model.set_params(
|
|
|
|
| 49 |
equations = pd.DataFrame(
|
| 50 |
{
|
| 51 |
"Equation": ["1.0", "cos(x1)", "square(cos(x1))"],
|
| 52 |
+
"Loss": [1.0, 0.1, 1e-5],
|
| 53 |
"Complexity": [1, 2, 3],
|
| 54 |
}
|
| 55 |
)
|
| 56 |
|
| 57 |
+
equations["Complexity Loss Equation".split(" ")].to_csv(
|
| 58 |
+
"equation_file.csv.bkup"
|
| 59 |
)
|
| 60 |
|
| 61 |
model.refresh(checkpoint_file="equation_file.csv")
|
|
|
|
| 82 |
equations = pd.DataFrame(
|
| 83 |
{
|
| 84 |
"Equation": ["1.0", "cos(x1)", "square(cos(x1))"],
|
| 85 |
+
"Loss": [1.0, 0.1, 1e-5],
|
| 86 |
"Complexity": [1, 2, 3],
|
| 87 |
}
|
| 88 |
)
|
| 89 |
|
| 90 |
+
equations["Complexity Loss Equation".split(" ")].to_csv(
|
| 91 |
+
"equation_file.csv.bkup"
|
| 92 |
)
|
| 93 |
|
| 94 |
model.refresh(checkpoint_file="equation_file.csv")
|
|
|
|
| 133 |
equations = pd.DataFrame(
|
| 134 |
{
|
| 135 |
"Equation": ["1.0", "mycustomoperator(x1)"],
|
| 136 |
+
"Loss": [1.0, 0.1],
|
| 137 |
"Complexity": [1, 2],
|
| 138 |
}
|
| 139 |
)
|
| 140 |
|
| 141 |
+
equations["Complexity Loss Equation".split(" ")].to_csv(
|
| 142 |
+
"equation_file_custom_operator.csv.bkup"
|
| 143 |
)
|
| 144 |
|
| 145 |
model.set_params(
|