I need exactly this diagram drawn in LaTeX but frankly, I have absolutely no idea how to do it. I would greatly appreciate if anyone can draw it out in latex for me or could point me to a tool where I can draw it out graphically and the LaTeX is generated. Thank you so much!
[Tex/LaTex] How to a draw branch of a backpropagation neural network
tikz-arrowstikz-graphdrawingtikz-pgf
Related Solutions
One possible method is to add another \foreach
loop, that repeats everything you have done three times. Note that the nodes are positioned at e.g. (0+\X,2.5-\y)
, where \X
is the loop variable for the new, outer loop. There are some adjustments to node names, to accommodate three instances of the same.
Some adjustments of the newly added arrows (final \foreach
loop) might be in order.
To rotate it you could just swap x and y coordinates everywhere. Below, I instead swapped the unit vectors.
I commented out some unused, and invisible, nodes.
\documentclass[a4paper,11pt]{article}
\usepackage{tikz}
\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$
},
}
\begin{document}
\begin{center}
\begin{tikzpicture}[
% swap the unit vectors
x={(0,-1cm)},
y={(1.5cm,0)},
>=stealth,
]
\foreach [count=\xx] \X in {0,6.5,13}{
\foreach \m/\l [count=\y] in {1,2,3,4}
\node [every neuron/.try, neuron \m/.try] (input-\m-\xx) at (0+\X,2.5-\y) {};
\foreach \m [count=\y] in {1,2}
\node [every neuron/.try, neuron \m/.try ] (hidden-\m-\xx) at (2+\X,2-\y*1.25) {};
\foreach \m [count=\y] in {1,2}
\node [every neuron/.try, neuron \m/.try ] (output-\m-\xx) at (4+\X,2-\y*1.25) {};
\foreach \l [count=\i] in {1,2,3,n}
\draw [<-] (input-\i-\xx) -- ++(-1,0);
% node [above, midway] {};
%\foreach \l [count=\i] in {1,n}
% \node [above] at (hidden-\i-\xx.north) {};
\foreach \l [count=\i] in {1,n}
\draw [->] (output-\i-\xx) -- ++(1,0);
% node [above, midway] {};
\foreach \i in {1,...,4}
\foreach \j in {1,...,2}
\draw [->] (input-\i-\xx) -- (hidden-\j-\xx);
\foreach \i in {1,...,2}
\foreach \j in {1,...,2}
\draw [->] (hidden-\i-\xx) -- (output-\j-\xx);
\draw[->,shorten >=1pt] (hidden-1-\xx) to [out=0,in=90,loop,looseness=8.8] (hidden-1-\xx);
\draw[->,shorten >=1pt] (hidden-2-\xx) to [out=180,in=90,loop,looseness=8.8] (hidden-2-\xx);
\draw[->,shorten >=1pt] (hidden-1-\xx) to [out=90,in=90,loop,looseness=1.7] (hidden-2-\xx);
\draw[->,shorten >=1pt] (hidden-2-\xx) to [out=90,in=90,loop,looseness=1] (hidden-1-\xx);
\foreach \l/\txt [count=\x from 0] in {Input/input, Hidden/hidden, Output/output}
\node [align=center] at (\txt-1-\xx-|+0,3) {\l \\ layer};
}% end of outer foreach
\foreach [evaluate=\i as \j using int(\i+1)] \i in {1,2}
{
\draw [red] (hidden-1-\i) to[bend left] (hidden-1-\j);
\draw [red] (hidden-1-\i) to[bend left] (hidden-2-\j);
\draw [red] (hidden-2-\i) to[bend right] (hidden-1-\j);
\draw [red] (hidden-2-\i) to[bend right] (hidden-2-\j);
}
\end{tikzpicture}
\end{center}
\end{document}
Next to each other
This is still wider than the textblock though.
\documentclass[a4paper,11pt]{article}
\usepackage{tikz}
\tikzset{%
every neuron/.style={
circle,
draw,
minimum size=7mm
},
neuron missing/.style={
draw=none,
scale=4,
text height=0.333cm,
execute at begin node=\color{black}$\vdots$
},
}
\begin{document}
\begin{center}
\begin{tikzpicture}[
% swap the unit vectors
x={(0,-1cm)},
y={(1.1cm,0)},
>=stealth,
]
\foreach [count=\xx] \X in {0,4,8}{
\foreach \m/\l [count=\y] in {1,2,3,4}
\node [every neuron/.try, neuron \m/.try] (input-\m-\xx) at (0,2.5-\y+\X) {};
\foreach \m [count=\y] in {1,2}
\node [every neuron/.try, neuron \m/.try ] (hidden-\m-\xx) at (2,2-\y*1.25+\X) {};
\foreach \m [count=\y] in {1,2}
\node [every neuron/.try, neuron \m/.try ] (output-\m-\xx) at (4,2-\y*1.25+\X) {};
\foreach \l [count=\i] in {1,2,3,n}
\draw [<-] (input-\i-\xx) -- ++(-1,0);
% node [above, midway] {};
%\foreach \l [count=\i] in {1,n}
% \node [above] at (hidden-\i-\xx.north) {};
\foreach \l [count=\i] in {1,n}
\draw [->] (output-\i-\xx) -- ++(1,0);
% node [above, midway] {};
\foreach \i in {1,...,4}
\foreach \j in {1,...,2}
\draw [->] (input-\i-\xx) -- (hidden-\j-\xx);
\foreach \i in {1,...,2}
\foreach \j in {1,...,2}
\draw [->] (hidden-\i-\xx) -- (output-\j-\xx);
\draw[->,shorten >=1pt] (hidden-1-\xx) to [out=0,in=90,loop,looseness=8.8] (hidden-1-\xx);
\draw[->,shorten >=1pt] (hidden-2-\xx) to [out=180,in=90,loop,looseness=8.8] (hidden-2-\xx);
\draw[->,shorten >=1pt] (hidden-1-\xx) to [out=90,in=90,loop,looseness=1.7] (hidden-2-\xx);
\draw[->,shorten >=1pt] (hidden-2-\xx) to [out=90,in=90,loop,looseness=1] (hidden-1-\xx);
}% end of outer foreach
\foreach \l/\txt [count=\x from 0] in {Input/input, Hidden/hidden, Output/output}
\node [align=center] at (\txt-1-\xx-|0,-2.5) {\l \\ layer};
\foreach [evaluate=\i as \j using int(\i+1)] \i in {1,2}
{
\draw [red,->] (hidden-1-\i) to[bend left] (hidden-1-\j);
\draw [red,->] (hidden-1-\i) to[bend left] (hidden-2-\j);
\draw [red,->] (hidden-2-\i) to[bend right] (hidden-1-\j);
\draw [red,->] (hidden-2-\i) to[bend right] (hidden-2-\j);
}
\end{tikzpicture}
\end{center}
\end{document}
Compile with LuaLaTeX
\documentclass[tikz, border=1cm]{standalone}
\pagecolor{black}
\usetikzlibrary{calc}
\usepackage[]{tikz-feynman}
\begin{document}
\begin{tikzpicture}[rotate=45, white]
\begin{feynman}
\vertex (a);
\vertex (b);
\vertex (c);
\vertex (d);
\vertex (e);
\diagram[thick, horizontal= a to e]{
a -- [fermion]b[dot],
c--[anti fermion]b,
d--[anti fermion]b,
e--[fermion]b,
};
\vertex[below=1em of a]{$a$};
\vertex[below=1em of b]{$b$};
\vertex[below=1em of c]{$c$};
\vertex[below=1em of d]{$d$};
\vertex[below=1em of e]{$e$};
\draw[->, thick, red, shorten <=0.4 cm, shorten >=0.4 cm] ($ (a)!0.1!(c) $) to[out=0, in=270] ($ (a)!0.9!(c) $) ;
\draw[->, thick, red, shorten <=0.4 cm, shorten >=0.4 cm] ($ (d)!0.1!(e) $) to[out=90, in=180] ($ (d)!0.9!(e) $) ;
\end{feynman}
\end{tikzpicture}
\end{document}
Best Answer
From this question indexed letters inside circles there is a possibility also with
tikz-cd
.