11

I'm trying to create a neural network illustration using the neuralnetwork package. I want to label my bias-neurons separately.

Right now I have the code:

\documentclass[fleqn,11pt,a4paper,final]{article} 
\usepackage{neuralnetwork}
\begin{document}

\begin{figure}[h!]
\begin{neuralnetwork}[height=1.5 ,maintitleheight=1cm,layertitleheight=3cm]
  \newcommand{\nodetextx}[2]{$x_{#2}$}
  \newcommand{\nodetextz}[2]{$y$}
  \newcommand{\nodetexth}[2]{$h_{#2,1}$}
  \newcommand{\nodetexthto}[2]{$h_{#2,2}$}
  \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{figure}
\end{document}

Which gives me the following illustration: enter image description here

I want the x_0-neuron to be labelled \textbf{c_1}, the h_{0,1}-neuron to be labelled \textbf{c_2} and finally the h_{0,2}-neuron to be labelled b. How do I do this?

Help is appreciated. Thanks

0
10

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}
0
-1

to resolve

enter image description here

I want to contribute to my solution. Get resolved by putting the bias = false tag. I do not know what bias is for anymore I found it on another blog and it worked.

\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
     $i_{#2}$
  \fi
}

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

\newcommand{\nodetexth}[2]{
  \ifnum \nn@nodeindex=0
    $\mathbf{c_2}$
  \else
    $h_{1, #2}$
  \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=5cm]
  \inputlayer[count=5, bias=false, title={Input}, text=\nodetextx]

  \hiddenlayer[count=10, bias=false, title={Oc1}, text=\nodetexth]
  \linklayers
  \hiddenlayer[count=10, bias=false, title={Oc2}, text=\nodetexthto]
  \linklayers

  \outputlayer[count=1, title={Output}, text=\nodetextz] 
  \linklayers
\end{neuralnetwork}
\end{document}
1
  • 4
    I guess your point is that you've eliminated the bias nodes. But, since labelling those is the point of the question, eliminating them is hardly an answer to it. Am I missing something? You seem to be answering some other question and your answer may be a good answer to that question, but it doesn't seem to be any answer at all to this question.
    – cfr
    Jun 27 '18 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.