| Download
📚 The CoCalc Library - books, templates and other resources
Path: cocalc-examples / martinthoma-latex-examples / tikz / activation-functions / activation-functions.tex
Views: 96515License: OTHER
\documentclass[varwidth=false, border=2pt]{standalone}12\usepackage{pgfplots}3\usepackage{tikz}4\usepackage{xcolor}56\begin{document}7\begin{tikzpicture}8\definecolor{color1}{HTML}{332288}9\definecolor{color2}{HTML}{FDB863}10\definecolor{color3}{HTML}{B2ABD2}11\definecolor{color4}{HTML}{5E3C99}12\begin{axis}[13legend pos=north west,14legend cell align={left},15axis x line=middle,16axis y line=middle,17x tick label style={/pgf/number format/fixed,18/pgf/number format/fixed zerofill,19/pgf/number format/precision=1},20y tick label style={/pgf/number format/fixed,21/pgf/number format/fixed zerofill,22/pgf/number format/precision=1},23grid = major,24width=16cm,25height=8cm,26grid style={dashed, gray!30},27xmin=-2, % start the diagram at this x-coordinate28xmax= 2, % end the diagram at this x-coordinate29ymin=-1, % start the diagram at this y-coordinate30ymax= 2, % end the diagram at this y-coordinate31%axis background/.style={fill=white},32xlabel=x,33ylabel=y,34tick align=outside,35enlargelimits=false]36% plot the stirling-formulae37\addplot[domain=-2:2, color1, ultra thick,samples=500] {1/(1+exp(-x))};38\addplot[domain=-2:2, color2, ultra thick,samples=500] {tanh(x)};39\addplot[domain=-2:2, color4, ultra thick,samples=500] {max(0, x)};40\addplot[domain=-2:2, color4, ultra thick,samples=500, dashed] {ln(exp(x) + 1)};41\addplot[domain=-2:2, color3, ultra thick,samples=500, dotted] {max(x, exp(x) - 1)};42\addlegendentry{$\varphi_1(x)=\frac{1}{1+e^{-x}}$}43\addlegendentry{$\varphi_2(x)=\tanh(x)$}44\addlegendentry{$\varphi_3(x)=\max(0, x)$}45\addlegendentry{$\varphi_4(x)=\log(e^x + 1)$}46\addlegendentry{$\varphi_5(x)=\max(x, e^x - 1)$}47\end{axis}48\end{tikzpicture}49\end{document}505152