-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] LaTeX table generator #156
Conversation
@MilesCranmer Do you want me to review this PR? If you assign it to me then I can have a look at this. |
Thanks! Added |
Fixed. |
This will be a really nice feature to have! Could this functionality be included into the Being able to specifiy the table row order by loss, complexity, or score would also be a nice addition. Similarly, column order would also be useful. Perhaps this could be handled by having The resulting method signature would look something like this: def latex(
self,
indices=None,
format_as_table=False,
precision=3,
columns=["Equations", "Complexity", "Loss", "Score"]
) Where indices could be either an int or a list of ints. As they aren't used anywhere else, is there an advantage to separating |
Thanks @tttc3, that's a great idea! I will implement it and re-upload. |
Updates:
Cheers, |
Re 1: I think this is a fair point, it would probably end up confusing if the methods differed too much. Also, depending on the desire to add other output formats in the future (e.g. txt, CSV, etc...), your current implementation would allow easier generalisation to other table output formats. Re 4: I agree, sorting rows is not particularly arduous in comparison to rearranging columns. |
Great points, thanks! By the way, do you (or @kazewong?) know if there's a way to automatically break equations inside a table? I found this: https://tex.stackexchange.com/a/3785/140440 but it seems to not work inside tables. Since many discovered equations are quite long, it would be nice if |
I think with some engineering you should be able to get away with the methods shown in these two pages: |
Thanks! Okay it looks like this can be done with: \vbox{
\begin{flushleft}
$\displaystyle <equation>$
\end{flushleft}
} This will automatically break it into pieces inside the table. So I guess this can be added for equations that are too long. |
Did some updates to the generated output. This is what it looks like for long equations: \begin{table}[h]
\begin{center}
\begin{tabular}{@{}cccc@{}}
\toprule
Equation & Complexity & Loss & Score \\
\midrule
$y = 5.9560$ & $1$ & $24.388$ & $0.0$ \\
$y = 4.4687 x_{0}$ & $3$ & $4.1362$ & $0.88715$ \\
$y = 2.0248 x_{0}^{2}$ & $5$ & $0.61547$ & $0.95257$ \\
$y = 1.8967 x_{0}^{2} + 0.66315$ & $7$ & $0.41267$ & $0.19987$ \\
\begin{minipage}{0.8\linewidth} \vspace{-1em} \begin{dmath*} y = x_{0} \left(x_{0} \left(0.84477 x_{0} - 1.1845\right) + 3.2887 + \frac{0.19070 - x_{0}}{x_{0}}\right) + 0.59160 \end{dmath*} \end{minipage} & $29$ & $0.0061356$ & $1.7765 \cdot 10^{-12}$ \\
\bottomrule
\end{tabular}
\end{center}
\end{table} What do you think? |
Looks good to me. I have heard anecdotal incompatibility issues with |
I wonder if I should try to align the equations with equation breaks, like shown here: https://tex.stackexchange.com/a/347011/140440? I am not sure how to make a table with this, though. |
I have not used |
Maybe try align left instead of center? Assuming the left hand side is always just y, this should work just fine, right? more specifically, change BTW, 'toprule', |
I think
|
But, in that code, you are manually typing |
This generates a booktabs-style LaTeX table for a subset of equations. Here is an example:
The output of this is:
which renders as:
Leaving
include_score
set toFalse
will leave out the Score column. Precision can be adjusted to have more or less precise constants.One can render only a subset of equations by using
latex_table([1, 4])
which only includes the 1st and 4th equation inmodel.equations_
.Edit: it now renders the
e-13
as\cdot 10^{-13}