mlp-multilayer-perceptron.tex 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage{amsmath}
  5. \usepackage{tikz}
  6. \usetikzlibrary{shapes, calc, shapes, arrows, snakes}
  7. \newcommand{\width}{0.2}
  8. \begin{document}
  9. \begin{preview}
  10. \tikzset{sigmoid/.style={path picture= {
  11. \begin{scope}[x=1pt,y=10pt]
  12. \draw plot[domain=-7:7] (\x,{1/(1 + exp(-\x))-0.5});
  13. \end{scope}
  14. }
  15. }
  16. }
  17. \tikzset{relu/.style={path picture= {
  18. \begin{scope}[x=7pt,y=6pt]
  19. \draw plot[domain=-1:0] (\x,0);
  20. \draw plot[domain=0:1] (\x,\x);
  21. \end{scope}
  22. }
  23. }
  24. }
  25. \tikzstyle{input}=[draw,fill=red!50,circle,minimum size=20pt,inner sep=0pt]
  26. \tikzstyle{hidden}=[draw,fill=green!50,circle,minimum size=20pt,inner sep=0pt]
  27. \tikzstyle{output}=[draw,fill=white,circle,minimum size=20pt,inner sep=0pt]
  28. \tikzstyle{bias}=[draw,dashed,fill=gray!50,circle,minimum size=20pt,inner sep=0pt]
  29. \tikzstyle{layer}=[fill=gray!70]
  30. \tikzstyle{stateTransition}=[->, thick]
  31. \begin{tikzpicture}[scale=2]
  32. \fill[layer] (-\width,-1.7) rectangle (\width,1.7);
  33. \fill[layer] (1+-\width,-1.7) rectangle (1+\width,1.7);
  34. \fill[layer] (2+-\width,-1.7) rectangle (2+\width,1.7);
  35. \fill[layer] (3+-\width,-1.7) rectangle (3+\width,1.7);
  36. \node (l1label) at (0, -1.9) {3};
  37. \node (l2label) at (1, -1.9) {64};
  38. \node (l3label) at (2, -1.9) {64};
  39. \node (l4label) at (3, -1.9) {1};
  40. \node (r)[input,fill=red] at (0, 1) {R};
  41. \node (g)[input,fill=green] at (0, 0) {G};
  42. \node (b)[input,fill=blue] at (0,-1) {B};
  43. \node (h11)[hidden, sigmoid] at (1, 1.5) {};
  44. \node (h12)[hidden, sigmoid] at (1, 0.5) {};
  45. \node[circle, inner sep=0] (h13) at (1,-0.5) {\vdots};
  46. \node (h14)[hidden, sigmoid] at (1,-1.5) {};
  47. \node (h21)[hidden, relu] at (2, 1.5) {};
  48. \node (h22)[hidden, relu] at (2, 0.5) {};
  49. \node[circle, inner sep=0] (h23) at (2,-0.5) {\vdots};
  50. \node (h24)[hidden, relu] at (2,-1.5) {};
  51. \node (o1)[output, sigmoid] at (3,0) {};
  52. \draw[stateTransition] (r) -- (h11) node [midway,above=-0.06cm] {};
  53. \draw[stateTransition] (r) -- (h12) node [midway,above=-0.06cm] {};
  54. \draw[stateTransition] (r) -- (h13) node [midway,above=-0.06cm] {};
  55. \draw[stateTransition] (r) -- (h14) node [midway,above=-0.06cm] {};
  56. \draw[stateTransition] (g) -- (h11) node [midway,above=-0.06cm] {};
  57. \draw[stateTransition] (g) -- (h12) node [midway,above=-0.06cm] {};
  58. \draw[stateTransition] (g) -- (h13) node [midway,above=-0.06cm] {};
  59. \draw[stateTransition] (g) -- (h14) node [midway,above=-0.06cm] {};
  60. \draw[stateTransition] (b) -- (h11) node [midway,above=-0.06cm] {};
  61. \draw[stateTransition] (b) -- (h12) node [midway,above=-0.06cm] {};
  62. \draw[stateTransition] (b) -- (h13) node [midway,above=-0.06cm] {};
  63. \draw[stateTransition] (b) -- (h11) node [midway,above=-0.06cm] {};
  64. \draw[stateTransition] (h11) -- (h21) node [midway,above=-0.06cm] {};
  65. \draw[stateTransition] (h11) -- (h22) node [midway,above=-0.06cm] {};
  66. \draw[stateTransition] (h11) -- (h23) node [midway,above=-0.06cm] {};
  67. \draw[stateTransition] (h11) -- (h24) node [midway,above=-0.06cm] {};
  68. \draw[stateTransition] (h12) -- (h21) node [midway,above=-0.06cm] {};
  69. \draw[stateTransition] (h12) -- (h22) node [midway,above=-0.06cm] {};
  70. \draw[stateTransition] (h12) -- (h23) node [midway,above=-0.06cm] {};
  71. \draw[stateTransition] (h12) -- (h24) node [midway,above=-0.06cm] {};
  72. \draw[stateTransition] (h13) -- (h21) node [midway,above=-0.06cm] {};
  73. \draw[stateTransition] (h13) -- (h22) node [midway,above=-0.06cm] {};
  74. \draw[stateTransition] (h13) -- (h23) node [midway,above=-0.06cm] {};
  75. \draw[stateTransition] (h13) -- (h24) node [midway,above=-0.06cm] {};
  76. \draw[stateTransition] (h14) -- (h21) node [midway,above=-0.06cm] {};
  77. \draw[stateTransition] (h14) -- (h22) node [midway,above=-0.06cm] {};
  78. \draw[stateTransition] (h14) -- (h23) node [midway,above=-0.06cm] {};
  79. \draw[stateTransition] (h14) -- (h21) node [midway,above=-0.06cm] {};
  80. \draw[stateTransition] (h21) -- (o1) node [midway,above=-0.06cm] {};
  81. \draw[stateTransition] (h22) -- (o1) node [midway,above=-0.10cm] {};
  82. \draw[stateTransition] (h23) -- (o1) node [midway,above=-0.06cm] {};
  83. \draw[stateTransition] (h24) -- (o1) node [midway,above=-0.06cm] {};
  84. \draw [
  85. thick,
  86. decoration={
  87. brace,
  88. mirror,
  89. raise=0.5cm
  90. },
  91. decorate
  92. ] (1+-\width, -1.8) -- (2+\width, -1.8)
  93. node [pos=0.5,anchor=north,yshift=-0.55cm] {50\% dropout};
  94. \end{tikzpicture}
  95. \end{preview}
  96. \end{document}