Spaces:
Running
Running
Implement regexp replacement of complex equations
Browse files- pysr/sr.py +14 -0
pysr/sr.py
CHANGED
|
@@ -2017,6 +2017,17 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 2017 |
|
| 2018 |
def _read_equation_file(self):
|
| 2019 |
"""Read the hall of fame file created by `SymbolicRegression.jl`."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2020 |
try:
|
| 2021 |
if self.nout_ > 1:
|
| 2022 |
all_outputs = []
|
|
@@ -2034,6 +2045,7 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 2034 |
},
|
| 2035 |
inplace=True,
|
| 2036 |
)
|
|
|
|
| 2037 |
|
| 2038 |
all_outputs.append(df)
|
| 2039 |
else:
|
|
@@ -2049,6 +2061,8 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 2049 |
},
|
| 2050 |
inplace=True,
|
| 2051 |
)
|
|
|
|
|
|
|
| 2052 |
except FileNotFoundError:
|
| 2053 |
raise RuntimeError(
|
| 2054 |
"Couldn't find equation file! The equation search likely exited "
|
|
|
|
| 2017 |
|
| 2018 |
def _read_equation_file(self):
|
| 2019 |
"""Read the hall of fame file created by `SymbolicRegression.jl`."""
|
| 2020 |
+
regexp_im = re.compile(r"\b(\d+\.\d+)im\b")
|
| 2021 |
+
regexp_im_sci = re.compile(r"\b(\d+\.\d+)[eEfF]([+-]?\d+)im\b")
|
| 2022 |
+
regexp_sci = re.compile(r"\b(\d+\.\d+)[eEfF]([+-]?\d+)\b")
|
| 2023 |
+
|
| 2024 |
+
def _replace_im(df):
|
| 2025 |
+
df["equation"] = df["equation"].apply(lambda x: regexp_im.sub(r"\1j", x))
|
| 2026 |
+
df["equation"] = df["equation"].apply(
|
| 2027 |
+
lambda x: regexp_im_sci.sub(r"\1e\2j", x)
|
| 2028 |
+
)
|
| 2029 |
+
df["equation"] = df["equation"].apply(lambda x: regexp_sci.sub(r"\1e\2", x))
|
| 2030 |
+
|
| 2031 |
try:
|
| 2032 |
if self.nout_ > 1:
|
| 2033 |
all_outputs = []
|
|
|
|
| 2045 |
},
|
| 2046 |
inplace=True,
|
| 2047 |
)
|
| 2048 |
+
_replace_im(df)
|
| 2049 |
|
| 2050 |
all_outputs.append(df)
|
| 2051 |
else:
|
|
|
|
| 2061 |
},
|
| 2062 |
inplace=True,
|
| 2063 |
)
|
| 2064 |
+
_replace_im(all_outputs[-1])
|
| 2065 |
+
|
| 2066 |
except FileNotFoundError:
|
| 2067 |
raise RuntimeError(
|
| 2068 |
"Couldn't find equation file! The equation search likely exited "
|