figure-four-layers-of-neural-network.tex 3.15 KB
Newer Older
孟霞 committed
1 2 3 4
%%%------------------------------------------------------------------------------------------------------------
\begin{tikzpicture}
\begin{scope}[]

孟霞 committed
5
\def\neuronsep{1.5}
孟霞 committed
6

孟霞 committed
7
\tikzstyle{neuronnode} = [minimum size=2em,circle,draw,ublue,very thick,inner sep=1pt, fill=white,align=center,drop shadow={shadow xshift=0.1em,shadow yshift=-0.1em}]
孟霞 committed
8 9 10 11 12 13 14 15 16 17 18

%%% layer 1
\foreach \n in {1,...,5}{
    \node [neuronnode] (neuron0\n) at (\n * \neuronsep,0) {\tiny{$f_1$}\\[-1ex] \tiny{$\sum$}};
    \draw [-,ublue] (neuron0\n.east) -- (neuron0\n.west);
}

\foreach \n in {1,...,5}{
    \foreach \m in {1,...,5}{
        \draw [<-] ([yshift=-0.1em]neuron0\m.south) -- ([yshift=-1.8em]neuron0\n.south);
    }
孟霞 committed
19
    \node [anchor=north] (x\n) at ([yshift=-2em]neuron0\n.south) {$x_\n$};
孟霞 committed
20 21
}

孟霞 committed
22
\node [anchor=west] (w1label) at ([xshift=-0.5em,yshift=0.8em]x5.north east) {${\mathbi{W}}^{[1]}$};
孟霞 committed
23 24 25 26 27

\begin{pgfonlayer}{background}
\node [rectangle,inner sep=0.2em,fill=red!20] [fit = (neuron01) (neuron05)] (layer01) {};
\end{pgfonlayer}

孟霞 committed
28
\node [anchor=west] (layer00label) at ([xshift=1.4em]x5.east) {\footnotesize{第0层}};
孟霞 committed
29
\node [anchor=west] (layer00label2) at (layer00label.east) {\footnotesize{(输入层)}};
孟霞 committed
30 31 32 33
{
\node [anchor=west] (layer01label) at ([xshift=1em]layer01.east) {\footnotesize{第1层}};
}
{
孟霞 committed
34
\node [anchor=west] (layer01label2) at (layer01label.east) {\footnotesize{{隐层}}};
孟霞 committed
35 36 37 38 39
}

%%% layer 2
{
\foreach \n in {2,...,4}{
孟霞 committed
40
    \node [neuronnode] (neuron1\n) at (\n * \neuronsep,4.5em) {\tiny{$f_2$}\\[-1ex] \tiny{$\sum$}};
孟霞 committed
41 42 43 44 45 46 47 48 49
    \draw [-,ublue] (neuron1\n.east) -- (neuron1\n.west);
}

\foreach \n in {2,...,4}{
    \foreach \m in {1,...,5}{
        \draw [<-] ([yshift=-0.1em]neuron1\n.south) -- (neuron0\m.north);
    }
}

孟霞 committed
50
\node [anchor=west] (w2label) at ([xshift=-2.5em,yshift=5.4em]x5.north east) {${\mathbi{W}}^{[2]}$};
孟霞 committed
51 52 53 54 55 56 57

\begin{pgfonlayer}{background}
{
\node [rectangle,inner sep=0.2em,fill=ugreen!20] [fit = (neuron12) (neuron14)] (layer02) {};
}
\end{pgfonlayer}

孟霞 committed
58
\node [anchor=west] (layer02label) at ([xshift=5em]layer02.east) {\footnotesize{第2层}};
孟霞 committed
59
{
孟霞 committed
60
\node [anchor=west] (layer02label2) at (layer02label.east) {\footnotesize{{隐层}}};
孟霞 committed
61 62 63 64 65 66
}
}

%%% layer 3
{
\foreach \n in {1,...,5}{
孟霞 committed
67
    \node [neuronnode] (neuron2\n) at (\n * \neuronsep,9em) {\tiny{$f_3$}\\[-1ex] \tiny{$\sum$}};
孟霞 committed
68 69 70 71 72 73 74 75 76 77 78 79
    \draw [-,ublue] (neuron2\n.east) -- (neuron2\n.west);
}

\foreach \n in {1,...,5}{
    \foreach \m in {2,...,4}{
        \draw [<-] ([yshift=-0.1em]neuron2\n.south) -- (neuron1\m.north);
    }

    \node [anchor=south] (y\n) at ([yshift=1.2em]neuron2\n.north) {$y_\n$};
    \draw [<-,thick] ([yshift=1.1em]neuron2\n.north) -- (neuron2\n.north);
}

孟霞 committed
80
\node [anchor=west] (w3label) at ([xshift=-2.5em,yshift=9.5em]x5.north east) {${\mathbi{W}}^{[3]}$};
孟霞 committed
81 82 83 84 85 86 87 88 89

\begin{pgfonlayer}{background}
{
\node [rectangle,inner sep=0.2em,fill=blue!20] [fit = (neuron21) (neuron25)] (layer03) {};
}
\end{pgfonlayer}

\node [anchor=west] (layer03label) at ([xshift=1em]layer03.east) {\footnotesize{第3层}};
{
孟霞 committed
90
\node [anchor=west] (layer03label2) at (layer03label.east) {\footnotesize{{输出层}}};
孟霞 committed
91 92 93 94 95
}
}

\end{scope}
\end{tikzpicture}
孟霞 committed
96
%%%------------------------------------------------------------------------------------------------------------