瀏覽代碼

tikz: Add activation functions

Martin Thoma 8 年之前
父節點
當前提交
cb58e0a6b3

+ 33 - 0
tikz/activation-functions/Makefile

@@ -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 - 0
tikz/activation-functions/README.md

@@ -0,0 +1,3 @@
+Compiled example
+----------------
+![Example](activation-functions.png)

二進制
tikz/activation-functions/activation-functions.png


+ 50 - 0
tikz/activation-functions/activation-functions.tex

@@ -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}