使用 tikz 绘制填充的神经网络图

使用 tikz 绘制填充的神经网络图

我正在尝试使用 tikz 绘制神经网络图。
我想更改圆圈颜色。
例如,输入应填充绿色。
提前谢谢您。

\begin{tikzpicture}[x=1.5cm, y=1.5cm, >=latex]
\tikzset{%
 every neuron/.style={
    circle,
    draw,
    minimum size=1cm},
neuron missing/.style={
    draw=none, 
    scale=4,
    text height=0.333cm,
    execute at begin node=\color{black}$\vdots$},
}

\foreach \m/\l [count=\y] in {1,2,3,missing,4}
   \node [every neuron/.try, neuron \m/.try,green!50] (input-\m) at (0,2.5-\y) {};

 \foreach \m [count=\y] in {1,missing,2}
    \node [every neuron/.try, neuron \m/.try,red!50] (output-\m) at (4,1.5-\y) {};

\foreach \l [count=\i] in {1,2,3,n}
  \draw [<-] (input-\i) -- ++(-1,0)
   node [above, midway] {$x_\l$};

\foreach \l [count=\i] in {1,n}
  \draw [->] (output-\i) -- ++(1,0)
   node [above, midway] {$a_\l$};

\foreach \i in {1,...,4}
  \foreach \j in {1,...,2}
   \draw [->] (input-\i) -- (output-\j);

\foreach \l [count=\x from 0] in {Eingangs-, Ausgangs-}
  \node [align=center, above] at (\x*4,2) {\l \\ Neuronen};
\end{tikzpicture}

它产生了那个。 在此处输入图片描述

答案1

如果你能提供关联回到你问题中的代码来源。我在代码中标记了更改。

\documentclass[tikz,border=5pt]{standalone}
\begin{document}
\begin{tikzpicture}[x=1.5cm, y=1.5cm, >=latex]
\tikzset{%
 every neuron/.style={
    circle,
    draw,
    minimum size=1cm},
neuron missing/.style={
    draw=none, 
    fill=none, %<- added
    scale=4,
    text height=0.333cm,
    execute at begin node=\color{black}$\vdots$},
}

\foreach \m [count=\y] in {1,2,3,missing,4} %<- removed "/\l" here 
   \node [fill=green,every neuron/.try, neuron \m/.try,green!50] (input-\m) at (0,2.5-\y) {};
% added "fill=green" in the line above

 \foreach \m [count=\y] in {1,missing,2}
    \node [every neuron/.try, neuron \m/.try,red!50] (output-\m) at (4,1.5-\y) {};

\foreach \l [count=\i] in {1,2,3,n}
  \draw [<-] (input-\i) -- ++(-1,0)
   node [above, midway] {$x_\l$};

\foreach \l [count=\i] in {1,n}
  \draw [->] (output-\i) -- ++(1,0)
   node [above, midway] {$a_\l$};

\foreach \i in {1,...,4}
  \foreach \j in {1,...,2}
   \draw [->] (input-\i) -- (output-\j);

\foreach \l [count=\x from 0] in {Eingangs-, Ausgangs-}
  \node [align=center, above] at (\x*4,2) {\l \\ Neuronen};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容