Neural Network illustration

This might be more complicated than it needs be, but it does seem to work.

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{xpatch}
\usepackage{neuralnetwork}
% this is the command that prints the first node in a layer
%    \node[bias neuron] (L\nn@layerindex-0) at (\nn@node@xb, \nn@node@y) {\nn@nodecaption{\nn@layerindex}{0}};
% we want to modify the last bit to use the loop macro \nn@nodeindex instead of 0
\makeatletter
\xpatchcmd{\layer}{\nn@nodecaption{\nn@layerindex}{0}}{\nn@nodecaption{\nn@layerindex}{\nn@nodeindex}}{}{}

% define the nodeindex to be zero initially
\newcommand\nn@nodeindex{0}

\newcommand{\nodetextx}[2]{
  \ifnum \nn@nodeindex=0
     $\mathbf{c_1}$
  \else
     $x_{#2}$
  \fi
}

\newcommand{\nodetextz}[2]{$y$}

\newcommand{\nodetexth}[2]{
  \ifnum \nn@nodeindex=0
    $\mathbf{c_2}$
  \else
    $h_{#2,1}$
  \fi
}

\newcommand{\nodetexthto}[2]{
  \ifnum \nn@nodeindex=0
    $b$
  \else
    $h_{#2,2}$
  \fi
}
\makeatother

\begin{document}
\begin{neuralnetwork}[height=1.5 ,maintitleheight=1cm,layertitleheight=3cm]
  \inputlayer[count=3, title={Input-lag}, text=\nodetextx]
  \hiddenlayer[count=5, title={Skjult lag}, text=\nodetexth]
  \linklayers
  \hiddenlayer[count=4, title={Skjult lag}, text=\nodetexthto]
  \linklayers
  \outputlayer[count=1, title={Output-lag}, text=\nodetextz] 
  \linklayers
\end{neuralnetwork}
\end{document}

Tags:

Graphs