0

I'm trying to draw a neural network diagram with tikz.
I want to change the circle color.
e.g. Inputs should be green filled.
I thank you in advance.

\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}

It produces that. enter image description here

esref
  • 45
  • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. It is much easier to help you if we can start with some compilable code that illustrates your problem. –  Mar 28 '18 at 23:31
  • Try \node [every neuron/.try,fill=green, neuron \m/.try,green!50] in the first \foreach loop. But what are you doing here with every and /.try? –  Mar 28 '18 at 23:31
  • It doesn't work. Here is minimal example. It can maybe help you. https://tex.stackexchange.com/questions/153957/drawing-neural-network-with-tikz – esref Mar 29 '18 at 00:42

1 Answers1

0

It would have been nice if you would have provided the link to the origin of your code in your question. I marked the changes in the code.

\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}

enter image description here