lda-gauss-1.tex 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. \documentclass[varwidth=true, border=5pt]{article}
  2. \usepackage[active,tightpage]{preview}
  3. \usepackage[latin1]{inputenc}
  4. \usepackage{amsmath}
  5. \usepackage{pgfplots}
  6. \pgfplotsset{compat=1.10}
  7. \usepackage{tikz}
  8. \usetikzlibrary{arrows,positioning}
  9. \usepackage{helvet}
  10. \usepackage[eulergreek]{sansmath}
  11. \pgfmathdeclarefunction{gauss}{2}{%
  12. \pgfmathparse{1/(sqrt(2*pi*#2))*exp(-((x-#1)^2)/(2*#2))}%
  13. }
  14. % to be used: \gauss(mean)(variance)
  15. \pgfplotsset{
  16. tick label style = {font=\sansmath\sffamily},
  17. every axis label/.append style={font=\sffamily\footnotesize},
  18. }
  19. % Thanks to percusse for solving problems with the axis
  20. \newcommand{\meanI}{80}
  21. \newcommand{\meanII}{40}
  22. \newcommand{\varI}{100}
  23. \newcommand{\varII}{100}
  24. \newcommand{\labelheight}{0.03}
  25. \pgfmathsetmacro{\meanIheight}{1/(sqrt(2*pi*\varI))}%
  26. \pgfmathsetmacro{\meanIIheight}{1/(sqrt(2*pi*\varII))}%
  27. \pgfmathsetmacro{\plotheight}{max(\meanIheight, \meanIIheight, \labelheight+0.002)}%
  28. \begin{document}
  29. \begin{preview}
  30. \tikzstyle{plotA}=[ultra thick,red!90!black]
  31. \tikzstyle{plotB}=[ultra thick,cyan!50!black]
  32. \begin{tikzpicture}
  33. \begin{axis}[
  34. width=13.5cm,
  35. height=8.625cm,
  36. % Grid
  37. grid = major,
  38. % size
  39. xmin= 0, % start the diagram at this x-coordinate
  40. xmax= 125, % end the diagram at this x-coordinate
  41. ymin= 0, % start the diagram at this y-coordinate
  42. ymax= 0.045, % end the diagram at this y-coordinate
  43. % Legende
  44. legend style={
  45. font=\large\sansmath\sffamily,
  46. at={(0.5,-0.18)},
  47. anchor=north,
  48. legend cell align=left,
  49. legend columns=-1,
  50. column sep=0.5cm
  51. },
  52. % Ticks
  53. tick align=inside,
  54. minor tick style={thick},
  55. scaled y ticks = false,
  56. xtick={40,70,80},
  57. ytick=\empty,
  58. % Axis
  59. axis on top,
  60. axis line style = {very thick,shorten <=-0.5\pgflinewidth},
  61. axis lines = middle,
  62. axis line style = very thick,
  63. xlabel=$x$,
  64. x label style={at={(axis description cs:0.5,0)},
  65. anchor=north,
  66. font=\boldmath\Large},
  67. ylabel=$f(x)$,
  68. y label style={at={(axis description cs:0,0.5)},
  69. anchor=south,
  70. rotate=90,
  71. font=\boldmath\Large},
  72. ]
  73. \coordinate (plotAcoord) at (axis cs:70,0.024);
  74. \coordinate (plotAcoordY) at (axis cs:0,0.024);
  75. \draw[plotA,thick, dashed](plotAcoord -| plotAcoordY) -- (plotAcoord);
  76. \coordinate (plotBcoord) at (axis cs:70,0.0004);
  77. \coordinate (plotBcoordY) at (axis cs:0,0.0004);
  78. \draw[plotB,thick, dashed](plotBcoord -| plotBcoordY) -- (plotBcoord);
  79. \node[above right=0cm and 0cm of plotAcoordY,color=red!90!black] (f1y) {$f_{I}(70)$};
  80. \node[above right=0cm and 0cm of plotBcoordY,color=cyan!50!black] (f2y) {$f_{II}(70)$};
  81. % Plots of the distributions
  82. \addplot [domain=0:120,samples=200,plotA] {gauss(80,100)};
  83. \addplot [domain=0:120,samples=200,plotB] {gauss(40,100)};
  84. % Mark points
  85. \addplot+[plotA,
  86. samples at={70},
  87. mark=*,
  88. mark options={scale=1, fill=red!90!black}] {gauss(\meanI,\varI)};
  89. \addplot+[plotB,
  90. samples at={70},
  91. mark=*,
  92. mark options={scale=1, fill=cyan!50!black}] {gauss(\meanII,\varII)};
  93. \coordinate (a) at (axis cs:70,0.024);
  94. \draw[black,thick](a |- current plot begin) -- (a);
  95. % Add labels
  96. \node[plotA,above] at (axis cs:102,\labelheight){\Large $\mathcal{N}(\meanI,\varI)$};
  97. \node[plotB,above] at (axis cs:20,\labelheight){\Large $\mathcal{N}(\meanII,\varII)$};
  98. \end{axis}
  99. \end{tikzpicture}
  100. \end{preview}
  101. \end{document}