Skip to content

Commit

Permalink
Update latex-math
Browse files Browse the repository at this point in the history
  • Loading branch information
ludwigbothmann authored and github-actions[bot] committed Jan 14, 2025
1 parent 007b6cd commit 1dccd14
Show file tree
Hide file tree
Showing 10 changed files with 765 additions and 20 deletions.
34 changes: 34 additions & 0 deletions latex-math/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
MATHRMD=latex-math.Rmd
MATHPDF=${MATHRMD:%.Rmd=%.pdf}

TEXFILES=$(shell find . -iname "basic-*tex" -o -iname "ml-*tex")

MATHCOMBINED=latex-math-combined.tex


.PHONY: all pdf combined help
all: $(MATHPDF) $(MATHCOMBINED)
pdf: $(MATHPDF)
combined: $(MATHCOMBINED)
help:
@echo "Usage: make <target>:\n"
@echo " pdf: render $(MATHRMD) to $(MATHPDF)"
@echo " combined: create the combined tex file $(MATHCOMBINED)"
@echo " clean: remove $(MATHPDF) and $(MATHCOMBINED)"
@echo " all: render $(MATHRMD) to $(MATHPDF) and create the combined tex file $(MATHCOMBINED)"
@echo " help: show this message"

$(MATHPDF): $(MATHRMD) $(TEXFILES)
@echo rendering $<;
Rscript -e "rmarkdown::render('latex-math.Rmd')"

$(MATHCOMBINED): $(TEXFILES)
@echo creating $@ from $(TEXFILES);
Rscript --quiet create-latex-math-combined.R

.PHONY: clean
clean:
@echo Removing $(MATHPDF) if it exists;
latexmk -C
test -f $(MATHPDF) && rm $(MATHPDF)
test -f combined-latex-and-math.tex && rm combined-latex-and-math.tex
47 changes: 36 additions & 11 deletions latex-math/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@
The notation and shortcuts used in latex-files of lectures, papers, ... of the Chair of Statistical Learning and Data Science is defined and maintained in this repository.
Notation & shortcuts are split into multiple files depending on subject and can be integrated as needed.

+ `basic-math`: basic mathematical notation such as mathematical spaces, sums & products, linear algebra, basic probability and statistics
+ `basic-ml`: basic machine learning notation such as notation for data (x, y), prediction functions, likelihood, loss functions, generalization error
+ `ml-nn`: neural networks
+ `ml-svm`: support vector machines
+ `ml-trees`: decision trees
+ `ml-interpretable`: IML / xAI

:warning: **Important Usage Note**: If you encounter these files within a lecture or project repository, do not make any changes locally. Go to [slds-lmu/latex-math](https://github.com/slds-lmu/latex-math) and make your changes either directly or via pull request.
- `basic-math`: Basic mathematical notation such as mathematical spaces, sums & products, linear algebra, basic probability and statistics
- `basic-ml`: Basic machine learning notation such as notation for data (x, y), prediction functions, likelihood, loss functions, generalization error
- `ml-ensembles`: Ensemble methods
- `ml-eval`: Evaluation metrics, resampling
- `ml-feature-sel`: Feature selection
- `ml-gp`: Gaussian processes
- `ml-hpo`: Hyperparameter optimization
- `ml-infotheory`: Information theory
- `ml-interpretable`: IML / xAI
- `ml-mbo`: Model-based optimization / Bayesian optimization
- `ml-multitarget`: Multi-target learning
- `ml-nn`: Neural networks
- `ml-online`:
- `ml-regu`: Regularization
- `ml-survival`: Survival analysis
- `ml-svm`: Support vector machines
- `ml-trees`: Decision trees


:warning: **Important Usage Note**: If you encounter these files within a lecture or project repository, do not make any changes locally.
Go to [slds-lmu/latex-math](https://github.com/slds-lmu/latex-math) and make your changes either directly or via pull request.
Any local changes are assumed to be spurious and *will be overridden* with upstream `slds-lmu/latex-math`.

## Using the notation
Expand All @@ -31,22 +44,34 @@ Note that some of the macros defined here may use additional Latex packages -- a
\usepackage{mathtools}
\usepackage{bm} % basic-ml, ml-gp
\usepackage{siunitx} % basic-ml
\usepackage{dsfont} % basic-math
\usepackage{dsfont} % basic-math, not package is called `doublestroke` when installing via tlmgr
\usepackage{xspace} % ml-mbo
\usepackage{xifthen} % ml-interpretable
```

See `latex-math.pdf` for all currently defined commands & definitions.

Note that the file `preamble.tex` contains packages required for `latex-math.Rmd` to be rendered, which are not necessarily all packages you would need in a fresh LaTeX project, since RMarkdown by default includes various required packages already.

## Updating / adding files

- A new shortcut / notation that falls into the scope of one of the existing files should be added in the respective file with a short description.
- Multiple shortcuts / notations belonging to another major subject should be summarized in a new .tex file.
- **ALWAYS** check if a command is already contained in one of the files - overwriting a command might result in compiling errors.
- **ALWAYS recompile `latex-math.Rmd` if you add new commands so it is kept up-to-date and to check that you have committed all the changes your notation requires to work.**
- If you add a new file, make sure it is added as an `include` in the header of `latex-math.Rmd` such that it is included in the rendered preview

To ensure recompilation is not forgotten, please install the pre-commit hook:
## Building

Use the included `Makefile` to render `latex-math.pdf` and to create the combined .tex file `latex-math-combined.tex`:

```sh
cp service/pre-commit-check-pdf .git/hooks/pre-commit
Usage: make <target>:

pdf: render latex-math.Rmd to latex-math.pdf
combined: create the combined tex file latex-math-combined.tex
clean: remove latex-math.pdf and latex-math-combined.tex
all: render latex-math.Rmd to latex-math.pdf and create the combined tex file latex-math-combined.tex
help: show this message
```

8 changes: 4 additions & 4 deletions latex-math/basic-math.tex
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

% basic math stuff
\newcommand{\xt}{\tilde x} % x tilde
\DeclareMathOperator*{\argmax}{arg\,max} % argmax
\DeclareMathOperator*{\argmin}{arg\,min} % argmin
\newcommand{\argminlim}{\mathop{\mathrm{arg\,min}}\limits} % argmax with limits
\newcommand{\argmaxlim}{\mathop{\mathrm{arg\,max}}\limits} % argmin with limits
\newcommand{\argmin}{\mathop{\mathrm{arg\,min}}} % argmin
\newcommand{\argmax}{\mathop{\mathrm{arg\,max}}} % argmax
\newcommand{\argminlim}{\argmin\limits} % argmin with limits
\newcommand{\argmaxlim}{\argmax\limits} % argmax with limits
\newcommand{\sign}{\operatorname{sign}} % sign, signum
\newcommand{\I}{\mathbb{I}} % I, indicator
\newcommand{\order}{\mathcal{O}} % O, order
Expand Down
6 changes: 5 additions & 1 deletion latex-math/basic-ml.tex
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@

% prior probabilities
\newcommand{\pik}[1][k]{\pi_{#1}} % pi_k, prior
\newcommand{\pih}{\hat{\pi}} % pi hat, estimated prior (binary classification)
\newcommand{\pikh}[1][k]{\hat{\pi}_{#1}} % pi_k hat, estimated prior
\newcommand{\lpik}[1][k]{\log \pi_{#1}} % log pi_k, log of the prior
\newcommand{\pit}{\pi(\thetav)} % Prior probability of parameter theta

Expand All @@ -136,7 +138,9 @@

% probababilistic
\newcommand{\bayesrulek}[1][k]{\frac{\P(\xv | y= #1) \P(y= #1)}{\P(\xv)}} % Bayes rule
\newcommand{\muk}{\bm{\mu_k}} % mean vector of class-k Gaussian (discr analysis)
\newcommand{\muv}{\bm{\mu}} % expectation vector of Gaussian
\newcommand{\muk}[1][k]{\bm{\mu_{#1}}} % mean vector of class-k Gaussian (discr analysis)
\newcommand{\mukh}[1][k]{\bm{\hat{\mu}_{#1}}} % estimated mean vector of class-k Gaussian (discr analysis)

% residual and margin
\newcommand{\eps}{\epsilon} % residual, stochastic
Expand Down
17 changes: 17 additions & 0 deletions latex-math/create-latex-math-combined.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Find all .tex files starting with `basic-` or `ml-`
# !! If new file prefixes are added, they must be added to the regex pattern
texfiles <- list.files(pattern = "(ml|basic)-.*\\.tex")

combined <- vapply(seq_along(texfiles), \(i) {
lines <- readLines(texfiles[[i]])
chunk <- paste(lines, collapse = "\n")
chunk <- paste0(chunk, "\n")

paste(
sprintf("%% ------------- %s -------------", basename(texfiles[[i]])),
chunk,
sep = "\n\n"
)
}, character(1))

writeLines(combined, "latex-math-combined.tex")
Loading

0 comments on commit 1dccd14

Please sign in to comment.