Spaces:
Running
Running
File size: 911 Bytes
f257e58 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
"""Functions to help export PySR equations to LaTeX."""
import re
def set_precision_of_constants_in_string(s, precision=3):
"""Set precision of constants in string."""
constants = re.findall(r"\b[-+]?\d*\.\d+|\b[-+]?\d+\.?\d*", s)
for c in constants:
reduced_c = "{:.{precision}g}".format(float(c), precision=precision)
s = s.replace(c, reduced_c)
return s
def generate_top_of_latex_table():
latex_table_pieces = [
r"\begin{table}[h]",
r"\centering",
r"\caption{}",
r"\label{}",
r"\begin{tabular}{@{}lcc@{}}",
r"\toprule",
r"Equation & Complexity & Loss \\",
r"\midrule",
]
return "\n".join(latex_table_pieces)
def generate_bottom_of_latex_table():
latex_table_pieces = [
r"\bottomrule",
r"\end{tabular}",
r"\end{table}",
]
return "\n".join(latex_table_pieces)
|