lda-gauss-variance-small.tex 3.6 KB

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