浏览代码

Add learning curve example

Martin Thoma 8 年之前
父节点
当前提交
5ddf82b0a9
共有 4 个文件被更改,包括 80 次插入0 次删除
  1. 33 0
      tikz/learn-curve-ml/Makefile
  2. 3 0
      tikz/learn-curve-ml/README.md
  3. 二进制
      tikz/learn-curve-ml/learn-curve-ml.png
  4. 44 0
      tikz/learn-curve-ml/learn-curve-ml.tex

+ 33 - 0
tikz/learn-curve-ml/Makefile

@@ -0,0 +1,33 @@
+SOURCE = learn-curve-ml
+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/learn-curve-ml/README.md

@@ -0,0 +1,3 @@
+Compiled example
+----------------
+![Example](learn-curve-ml.png)

二进制
tikz/learn-curve-ml/learn-curve-ml.png


+ 44 - 0
tikz/learn-curve-ml/learn-curve-ml.tex

@@ -0,0 +1,44 @@
+\documentclass{standalone}
+
+\usepackage{pgfplots}
+\usepackage{tikz}
+\usetikzlibrary{positioning}
+\usetikzlibrary{decorations.text}
+\usetikzlibrary{decorations.pathmorphing}
+
+\begin{document}
+\begin{tikzpicture}
+    \begin{axis}[
+        legend pos=north east,
+        axis x line=middle,
+        axis y line=middle,
+        grid = major,
+        width=14cm,
+        height=8cm,
+        grid style={dashed, white}, % gray!30
+        xmin=0,       % start the diagram at this x-coordinate
+        xmax= 104,    % end   the diagram at this x-coordinate
+        ymin= 0,      % start the diagram at this y-coordinate
+        ymax= 0.79,   % end   the diagram at this y-coordinate
+        axis background/.style={fill=white},
+        xlabel=Training samples,
+        ylabel=Error,
+        tick align=outside,
+        minor tick num=-3,
+        tension=0.08]
+      \addplot[domain=1:100, red, thick,samples=200,dashed] {1/(x+2)+0.4};
+      \addplot[domain=1:100, green, thick,samples=200] {0.4-(1/(x+2))};
+
+      % \draw[dashed,thick] (axis cs:0,0.4) -- (axis cs:110,0.4);
+      \draw[dashed,thick] (axis cs:0,0.2) -- (axis cs:110,0.2);
+      \draw[thick,<->] (axis cs:80,0.2) -- (axis cs:80,0.3878);
+      \draw[thick,<->] (axis cs:20,0.3545) -- (axis cs:20,0.4454);
+      \draw[decoration={text along path, text={desired}, text align={center}}, decorate] (axis cs:20,0.21) -- (axis cs:50,0.21);
+      \draw[decoration={text along path, text={bias}, text align={center}}, decorate] (axis cs:80,0.28) -- (axis cs:90,0.28);
+      \draw[decoration={text along path, text={variance}, text align={center}}, decorate] (axis cs:0,0.39) -- (axis cs:20,0.39);
+
+      \addlegendentry{Validation}
+      \addlegendentry{Training}
+    \end{axis}
+\end{tikzpicture}
+\end{document}