I am trying to create an "unfolded" version of this diagram made with tikz:
This was made with the code:
\documentclass[a4paper, 11pt]{article}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{fit, arrows.meta}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage[]{algorithm2e}
\graphicspath{ {images/} }
\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$
},
}
\def\layersep{2.5cm}
\begin{document}
\begin{tikzpicture}[x=1.5cm, y=1.5cm, >=stealth]
\foreach \m/\l [count=\y] in {1,2,3,4}
\node [every neuron/.try, neuron \m/.try] (input-\m) at (0,2.5-\y) {};
\foreach \m [count=\y] in {1,2}
\node [every neuron/.try, neuron \m/.try ] (hidden-\m) at (2,2-\y*1.25) {};
\foreach \m [count=\y] in {1,2}
\node [every neuron/.try, neuron \m/.try ] (output-\m) at (4,2-\y*1.25) {};
\foreach \l [count=\i] in {1,2,3,n}
\draw [<-] (input-\i) -- ++(-1,0)
node [above, midway] {};
\foreach \l [count=\i] in {1,n}
\node [above] at (hidden-\i.north) {};
\foreach \l [count=\i] in {1,n}
\draw [->] (output-\i) -- ++(1,0)
node [above, midway] {};
\foreach \i in {1,...,4}
\foreach \j in {1,...,2}
\draw [->] (input-\i) -- (hidden-\j);
\foreach \i in {1,...,2}
\foreach \j in {1,...,2}
\draw [->] (hidden-\i) -- (output-\j);
\draw[->,shorten >=1pt] (hidden-1) to [out=90,in=180,loop,looseness=8.8] (hidden-1);
\draw[->,shorten >=1pt] (hidden-2) to [out=-90,in=180,loop,looseness=8.8] (hidden-2);
\draw[->,shorten >=1pt] (hidden-1) to [out=180,in=180,loop,looseness=2.8] (hidden-2);
\draw[->,shorten >=1pt] (hidden-2) to [out=180,in=180,loop,looseness=1.8] (hidden-1);
\foreach \l [count=\x from 0] in {Input, Hidden, Ouput}
\node [align=center, above] at (\x*2,2) {\l \\ layer};
\end{tikzpicture}
\end{document}
Now I am trying to do something like this but can't really figure out how to modify my code so that I will have Three networks next to each other:
I looked at the question in the following link, but it is not quite the same as what I am trying to do: How to Draw Recurrent Neural Network
So can my code be modified for me to do this? Do you Think it would be possible to rotate the networks -90 degrees so that they fit an A4 page better?
Best Answer
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.
Next to each other
This is still wider than the textblock though.