I have a neural network figure and I would like to learn how to add a bias node to this diagram at both hidden and output layer. Kindly guide me on this.

Cuurently, the figure looks like this enter image description here I would like to modify it as enter image description here

my present code is



    every neuron/.style={
        minimum size=1cm
    neuron missing/.style={
        draw=none, fill=none,%<-----------------new
        text height=0.333cm,
        execute at begin node=\color{black}$\vdots$

\begin{tikzpicture}[x=1.3cm, y=1.3cm, >=stealth]
    \foreach \m/\l [count=\y] in {1,2,3,missing,4}
    \node [fill=black!20, every neuron/.try, neuron \m/.try, ] (input-\m) at (0,2.5-\y) {};%<-----fill=
    \foreach \m [count=\y] in {1,missing,2}
    \node [every neuron/.try, neuron \m/.try ] (hidden-\m) at (2,2-\y*1.25) {};
    \foreach \m [count=\y] in {1,2,missing,3}
    \node [every neuron/.try, neuron \m/.try ] (output-\m) at (4,2.0-\y) {};
    \foreach \l [count=\i] in {1,2,3,j}
    \draw [<-] (input-\i) -- ++(-1,0)
    node [above, midway] {$I$};
    \foreach \l [count=\i] in {1,k}
    \node [above] at (hidden-\i.north) {$H$};
    \foreach \l [count=\i] in {1,2,l}
    \draw [->] (output-\i) -- ++(1,0)
    node [above, midway] {$O$};
    \foreach \i in {1,...,4}
    \foreach \j in {1,...,2}
    \draw [->] (input-\i) -- (hidden-\j);
    \foreach \i in {1,...,2}
    \foreach \j in {1,...,3}
    \draw [->] (hidden-\i) -- (output-\j);
    \foreach \l [count=\x from 0] in {Input, Hidden, Output}
    \node [align=center, above] at (\x*2,2) {\l \\ layer};
    \node (nx1) at (hidden-1) {$\mathbf{f_x}$};%<---------------new
    \node (nx2) at (hidden-2) {$\mathbf{f_x}$};%<---------------new
  • You should be more specific in terms of the output you want. Bias nodes can be described and positioned in numerous ways. Can you add an image that highlights exactly the location/position and content of the additions?
    – Werner
    Jul 12 at 16:56
  • @Werner Thank you for the input ! I apologise I should have thought of that while posting the first time. I have now edited my question. Kindly have a look
    – user157522
    Jul 12 at 17:13

There is nothing new to be done in your question. Adding extra nodes in exact the same way as you already do your other nodes:

Code fragment on purpose:

\node[circle, draw] (b1) at (1,2) {b};
\draw[->]  (b1) -- (hidden-1);
\draw[->]  (b1) -- (hidden-2);

\node[circle, draw] (b2) at (3,2) {b};
\draw[->]  (b2) -- (output-1);
\draw[->]  (b2) -- (output-2);
\draw[->]  (b2) -- (output-3);

Graph with two extra nodes

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.