Spaces:
Running
Running
Commit
·
b2ffe3b
1
Parent(s):
6210be0
Allow specifying precision in LaTeX table
Browse files- pysr/sr.py +26 -24
pysr/sr.py
CHANGED
|
@@ -27,6 +27,11 @@ from .julia_helpers import (
|
|
| 27 |
import_error_string,
|
| 28 |
)
|
| 29 |
from .export_numpy import CallableEquation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
from .deprecated import make_deprecated_kwargs_for_pysr_regressor
|
| 31 |
|
| 32 |
|
|
@@ -1999,7 +2004,7 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1999 |
return ret_outputs
|
| 2000 |
return ret_outputs[0]
|
| 2001 |
|
| 2002 |
-
def latex_table(self, indices=None):
|
| 2003 |
"""Create a LaTeX/booktabs table for all, or some, of the equations.
|
| 2004 |
|
| 2005 |
Parameters
|
|
@@ -2008,10 +2013,13 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 2008 |
If you wish to select a particular subset of equations from
|
| 2009 |
`self.equations_`, give the row numbers here. By default,
|
| 2010 |
all equations will be used.
|
|
|
|
|
|
|
|
|
|
| 2011 |
|
| 2012 |
Returns
|
| 2013 |
-------
|
| 2014 |
-
|
| 2015 |
A string that will render a table in LaTeX of the equations.
|
| 2016 |
"""
|
| 2017 |
if self.nout_ > 1:
|
|
@@ -2020,31 +2028,25 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 2020 |
)
|
| 2021 |
if indices is None:
|
| 2022 |
indices = range(len(self.equations_))
|
| 2023 |
-
|
| 2024 |
-
r"\begin{table}[h]",
|
| 2025 |
-
r"\centering",
|
| 2026 |
-
r"\caption{}",
|
| 2027 |
-
r"\label{}",
|
| 2028 |
-
r"\begin{tabular}{@{}lcc@{}}",
|
| 2029 |
-
r"\toprule",
|
| 2030 |
-
r"Equation & Complexity & Loss \\",
|
| 2031 |
-
r"\midrule",
|
| 2032 |
-
]
|
| 2033 |
for i in indices:
|
| 2034 |
-
|
| 2035 |
-
|
| 2036 |
-
|
| 2037 |
-
|
| 2038 |
-
|
| 2039 |
-
latex_table_pieces += [
|
| 2040 |
" & ".join(row_pieces) + r" \\",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2041 |
]
|
| 2042 |
-
|
| 2043 |
-
|
| 2044 |
-
r"\end{tabular}",
|
| 2045 |
-
r"\end{table}",
|
| 2046 |
-
]
|
| 2047 |
-
return "\n".join(latex_table_pieces)
|
| 2048 |
|
| 2049 |
|
| 2050 |
def _denoise(X, y, Xresampled=None, random_state=None):
|
|
|
|
| 27 |
import_error_string,
|
| 28 |
)
|
| 29 |
from .export_numpy import CallableEquation
|
| 30 |
+
from .export_latex import (
|
| 31 |
+
set_precision_of_constants_in_string,
|
| 32 |
+
generate_top_of_latex_table,
|
| 33 |
+
generate_bottom_of_latex_table,
|
| 34 |
+
)
|
| 35 |
from .deprecated import make_deprecated_kwargs_for_pysr_regressor
|
| 36 |
|
| 37 |
|
|
|
|
| 2004 |
return ret_outputs
|
| 2005 |
return ret_outputs[0]
|
| 2006 |
|
| 2007 |
+
def latex_table(self, indices=None, precision=3):
|
| 2008 |
"""Create a LaTeX/booktabs table for all, or some, of the equations.
|
| 2009 |
|
| 2010 |
Parameters
|
|
|
|
| 2013 |
If you wish to select a particular subset of equations from
|
| 2014 |
`self.equations_`, give the row numbers here. By default,
|
| 2015 |
all equations will be used.
|
| 2016 |
+
precision : int, default=3
|
| 2017 |
+
The number of significant figures shown in the LaTeX
|
| 2018 |
+
representations.
|
| 2019 |
|
| 2020 |
Returns
|
| 2021 |
-------
|
| 2022 |
+
latex_table_str : str
|
| 2023 |
A string that will render a table in LaTeX of the equations.
|
| 2024 |
"""
|
| 2025 |
if self.nout_ > 1:
|
|
|
|
| 2028 |
)
|
| 2029 |
if indices is None:
|
| 2030 |
indices = range(len(self.equations_))
|
| 2031 |
+
latex_table_content = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2032 |
for i in indices:
|
| 2033 |
+
equation = self.latex(i, precision=precision)
|
| 2034 |
+
complexity = str(self.equations_.iloc[i]["complexity"])
|
| 2035 |
+
loss = str(self.equations_.iloc[i]["loss"])
|
| 2036 |
+
row_pieces = ["$" + equation + "$", complexity, loss]
|
| 2037 |
+
latex_table_content.append(
|
|
|
|
| 2038 |
" & ".join(row_pieces) + r" \\",
|
| 2039 |
+
)
|
| 2040 |
+
latex_table_top = generate_top_of_latex_table()
|
| 2041 |
+
latex_table_bottom = generate_bottom_of_latex_table()
|
| 2042 |
+
latex_table_str = "\n".join(
|
| 2043 |
+
[
|
| 2044 |
+
latex_table_top,
|
| 2045 |
+
*latex_table_content,
|
| 2046 |
+
latex_table_bottom,
|
| 2047 |
]
|
| 2048 |
+
)
|
| 2049 |
+
return latex_table_str
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2050 |
|
| 2051 |
|
| 2052 |
def _denoise(X, y, Xresampled=None, random_state=None):
|