activation-functions.tex 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. \documentclass[varwidth=false, border=2pt]{standalone}
  2. \usepackage{pgfplots}
  3. \usepackage{tikz}
  4. \usepackage{xcolor}
  5. \begin{document}
  6. \begin{tikzpicture}
  7. \definecolor{color1}{HTML}{332288}
  8. \definecolor{color2}{HTML}{FDB863}
  9. \definecolor{color3}{HTML}{B2ABD2}
  10. \definecolor{color4}{HTML}{5E3C99}
  11. \begin{axis}[
  12. legend pos=north west,
  13. legend cell align={left},
  14. axis x line=middle,
  15. axis y line=middle,
  16. x tick label style={/pgf/number format/fixed,
  17. /pgf/number format/fixed zerofill,
  18. /pgf/number format/precision=1},
  19. y tick label style={/pgf/number format/fixed,
  20. /pgf/number format/fixed zerofill,
  21. /pgf/number format/precision=1},
  22. grid = major,
  23. width=16cm,
  24. height=8cm,
  25. grid style={dashed, gray!30},
  26. xmin=-2, % start the diagram at this x-coordinate
  27. xmax= 2, % end the diagram at this x-coordinate
  28. ymin=-1, % start the diagram at this y-coordinate
  29. ymax= 2, % end the diagram at this y-coordinate
  30. %axis background/.style={fill=white},
  31. xlabel=x,
  32. ylabel=y,
  33. tick align=outside,
  34. enlargelimits=false]
  35. % plot the stirling-formulae
  36. \addplot[domain=-2:2, color1, ultra thick,samples=500] {1/(1+exp(-x))};
  37. \addplot[domain=-2:2, color2, ultra thick,samples=500] {tanh(x)};
  38. \addplot[domain=-2:2, color4, ultra thick,samples=500] {max(0, x)};
  39. \addplot[domain=-2:2, color4, ultra thick,samples=500, dashed] {ln(exp(x) + 1)};
  40. \addplot[domain=-2:2, color3, ultra thick,samples=500, dotted] {max(x, exp(x) - 1)};
  41. \addlegendentry{$\varphi_1(x)=\frac{1}{1+e^{-x}}$}
  42. \addlegendentry{$\varphi_2(x)=\tanh(x)$}
  43. \addlegendentry{$\varphi_3(x)=\max(0, x)$}
  44. \addlegendentry{$\varphi_4(x)=\log(e^x + 1)$}
  45. \addlegendentry{$\varphi_5(x)=\max(x, e^x - 1)$}
  46. \end{axis}
  47. \end{tikzpicture}
  48. \end{document}