Skip to content

Commit

Permalink
tikz: Add activation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed May 17, 2017
1 parent 2ce3442 commit cb58e0a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tikz/activation-functions/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
SOURCE = activation-functions
DELAY = 80
DENSITY = 300
WIDTH = 512

make:
pdflatex $(SOURCE).tex -output-format=pdf
make clean

clean:
rm -rf $(TARGET) *.class *.html *.log *.aux *.data *.gnuplot

gif:
pdfcrop $(SOURCE).pdf
convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif
make clean

png:
make
make svg
inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png

transparentGif:
convert $(SOURCE).pdf -transparent white result.gif
make clean

svg:
#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
pdf2svg $(SOURCE).pdf $(SOURCE).svg
# Necessary, as pdf2svg does not always create valid svgs:
inkscape $(SOURCE).svg --export-width=$(WIDTH) --export-plain-svg=$(SOURCE)1.svg
rsvg-convert -a -w 720 -f svg $(SOURCE)1.svg -o $(SOURCE).svg
rm $(SOURCE)1.svg
3 changes: 3 additions & 0 deletions tikz/activation-functions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Compiled example
----------------
![Example](activation-functions.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions tikz/activation-functions/activation-functions.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
\documentclass[varwidth=false, border=2pt]{standalone}

\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{xcolor}

\begin{document}
\begin{tikzpicture}
\definecolor{color1}{HTML}{332288}
\definecolor{color2}{HTML}{FDB863}
\definecolor{color3}{HTML}{B2ABD2}
\definecolor{color4}{HTML}{5E3C99}
\begin{axis}[
legend pos=north west,
legend cell align={left},
axis x line=middle,
axis y line=middle,
x tick label style={/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1},
y tick label style={/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1},
grid = major,
width=16cm,
height=8cm,
grid style={dashed, gray!30},
xmin=-2, % start the diagram at this x-coordinate
xmax= 2, % end the diagram at this x-coordinate
ymin=-1, % start the diagram at this y-coordinate
ymax= 2, % end the diagram at this y-coordinate
%axis background/.style={fill=white},
xlabel=x,
ylabel=y,
tick align=outside,
enlargelimits=false]
% plot the stirling-formulae
\addplot[domain=-2:2, color1, ultra thick,samples=500] {1/(1+exp(-x))};
\addplot[domain=-2:2, color2, ultra thick,samples=500] {tanh(x)};
\addplot[domain=-2:2, color4, ultra thick,samples=500] {max(0, x)};
\addplot[domain=-2:2, color4, ultra thick,samples=500, dashed] {ln(exp(x) + 1)};
\addplot[domain=-2:2, color3, ultra thick,samples=500, dotted] {max(x, exp(x) - 1)};
\addlegendentry{$\varphi_1(x)=\frac{1}{1+e^{-x}}$}
\addlegendentry{$\varphi_2(x)=\tanh(x)$}
\addlegendentry{$\varphi_3(x)=\max(0, x)$}
\addlegendentry{$\varphi_4(x)=\log(e^x + 1)$}
\addlegendentry{$\varphi_5(x)=\max(x, e^x - 1)$}
\end{axis}
\end{tikzpicture}
\end{document}

0 comments on commit cb58e0a

Please sign in to comment.