I'm trying to recreate this image of a MADE net in TikZ.
Here's what I have so far.
Any advice on how to draw the mask matrices and perhaps how to incorporate the numbers inside the neurons of the MADE net into the drawLayers macro would be much appreciated. (Those numbers indicate the maximum number of input units that affect the neuron in question.)
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\newcommand\drawLayers[2]{
% #1 (str): namespace
% #2 (list[int]): number of nodes in each layer
\foreach \neurons [count=\lyrIdx] in #2
\foreach \n in {1,...,\neurons}
\node[neuron] (#1-\lyrIdx-\n) at (1.5*\lyrIdx, \neurons/2-\n) {};
}
\newcommand\denselyConnectNodes[2]{
% #1 (str): namespace
% #2 (list[int]): number of nodes in each layer
\foreach \n [count=\lyrIdx, remember=\lyrIdx as \previdx, remember=\n as \prevn] in #2 {
\foreach \y in {1,...,\n} {
\ifnum \lyrIdx > 1
\foreach \x in {1,...,\prevn}
\draw (#1-\previdx-\x) -- (#1-\lyrIdx-\y);
\fi
}
}
}
\newcommand\connectSomeNodes[2]{
% #1 (str): namespace
% #2 (list[list[list[int]]]): for each node in each layer, list all connected nodes in the next layer
\foreach \layer [count=\lyrIdx, evaluate=\lyrIdx as \nextLyr using int(\lyrIdx+1)] in #2
\foreach \neuron [count=\nIdx] in \layer
\foreach \edge in \neuron
\draw (#1-\lyrIdx-\nIdx) -- (#1-\nextLyr-\edge);
}
\begin{document}
\begin{tikzpicture}[
shorten >=1pt, shorten <=1pt, ->,
neuron/.style={circle, draw, minimum size=4ex, thick},
legend/.style={font=\large\bfseries},
]
% Fully-connected neural net
\drawLayers{fcnn}{{3, 4, 4, 3}}
\denselyConnectNodes{fcnn}{{3, 4, 4, 3}}
\path (fcnn-1-1) -- (fcnn-2-1) node[midway, above=1ex] {$W_1$};
\path (fcnn-2-1) -- (fcnn-3-1) node[midway, above=1ex] {$W_2$};
\path (fcnn-3-1) -- (fcnn-4-1) node[midway, above=1ex] {$V$};
% MADE net
\begin{scope}[xshift=10cm]
\drawLayers{made}{{3, 4, 4, 3}}
\connectSomeNodes{made}{{
{{}, {1,2,3,4}, {1,3,4}},
{{2,3}, {1,2,3,4}, {2,3}, {2,3}},
{{1,3}, {1}, {1}, {1,3}},
}}
\end{scope}
% Input + output labels
\foreach \label [count=\c] in {{$p(x_1|x_2,x_3)$}, $p(x_2)$, $p(x_3|x_2)$} {
\node[left=0 of fcnn-1-\c] {$x_\c$};
\node[right=0 of fcnn-4-\c] {$\hat x_\c$};
\node[left=0 of made-1-\c] {$x_\c$};
\node[right=0 of made-4-\c] {\label};
}
\node[legend, below=0.5 of fcnn-3-4] {autoencoder};
\node[legend, below=0.5 of made-2-4] {MADE};
\end{tikzpicture}
\end{document}



