1

I'm following the tutorial found here to create a drawing of a neural network in Latex. The network I would like to depict has 19 input nodes and 25 nodes in the hidden layer. I would like to draw the first few input nodes, an ellipsis, then the 19th input node, then do something similar for the hidden layer. I've been trying to make this work, but haven't had much success. Here is what I have now (from the tutorial):

\def\layersep{2.5cm}

\begin{tikzpicture}[shorten >=1pt,->,draw=black!50, node distance=\layersep]
    \tikzstyle{every pin edge}=[<-,shorten <=1pt]
    \tikzstyle{neuron}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
    \tikzstyle{input neuron}=[neuron, fill=green!50];
    \tikzstyle{output neuron}=[neuron, fill=red!50];
    \tikzstyle{hidden neuron}=[neuron, fill=blue!50];
    \tikzstyle{annot} = [text width=4em, text centered]

    % Draw the input layer nodes
    \foreach \name / \y in {1,...,4}
    % This is the same as writing \foreach \name / \y in {1/1,2/2,3/3,4/4}
        \node[input neuron, pin=left:Input \#\y] (I-\name) at (0,-\y) {};

    % Draw the hidden layer nodes
    \foreach \name / \y in {1,...,5}
        \path[yshift=0.5cm]
            node[hidden neuron] (H-\name) at (\layersep,-\y cm) {};

    % Draw the output layer node
    \node[output neuron,pin={[pin edge={->}]right:Output}, right of=H-3] (O) {};

    % Connect every node in the input layer with every node in the
    % hidden layer.
    \foreach \source in {1,...,4}
        \foreach \dest in {1,...,5}
            \path (I-\source) edge (H-\dest);

    % Connect every node in the hidden layer with the output layer
    \foreach \source in {1,...,5}
        \path (H-\source) edge (O);

    % Annotate the layers
    \node[annot,above of=H-1, node distance=1cm] (hl) {Hidden layer};
    \node[annot,left of=hl] {Input layer};
    \node[annot,right of=hl] {Output layer};
\end{tikzpicture}
1
  • Welcome to TeX.SE! Something like in this answer?
    – user121799
    Apr 5, 2018 at 18:12

1 Answer 1

1

like this?

enter image description here

based on my answer on this question:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{calc, chains, positioning}

\begin{document}
\def\layersep{2.5cm}
    \begin{tikzpicture}[shorten >=1pt,->, draw=black!50,
        node distance = 6mm and 18mm,
          start chain = going below,
every pin edge/.style = {<-,shorten <=1pt},
        neuron/.style = {circle, fill=#1,
                         minimum size=17pt, inner sep=0pt},
        annot/.style = {text width=4em, align=center}
                        ]
% Draw the input and hyden layer nodes
\foreach \y [count=\i] in {1,2,3,19}
{
\ifnum\i=3
    \node[neuron=none, on chain]     (I-\i)  {$\vdots$};
    \node[neuron=none, right=of I-3] (H-\i)  {$\vdots$};
\else
    \node[neuron=green!50, on chain,
          pin=180:Input \#\y
          ]                 (I-\i)  {$x_{\y}$};
    \node[neuron=blue!50,
          right=of I-\i]        (H-\i)  {};
\fi
}
\foreach \y [count=\i] in {1,2,3,25}
{
\ifnum\i=3
\else
    \node[neuron=blue!50,
          right=of I-\i]        (H-\i)  {$h_{\y}$};
\fi
}
% Draw the output layer node
    \node[neuron=red!50,
          right=of $(H-2)!0.5!(H-3)$]  (O-1)   {};
% Connect input nodes with hidden nodes and
%  hidden nodes with output nodes with the output layer
    \foreach \i in {1,2,4}
        \foreach \j in {1,2,4}
{
    \draw (I-\i) edge (H-\j)
          (H-\j) edge (O-1);
}
    \draw (O-1) -- node[below] {$h_{w,b}(x)$} + (2,0);
% Annotate layers
\node[annot,below=of I-4.center]        {Layer 1};
\node[annot,below=of H-4.center]        {Layer 2};
\node[annot,below=of O-1 |- H-4.center] {Layer 3};
    \end{tikzpicture}
\end{document}
1
  • @StephaniePavlick, if you like the answer and if you do not (in short) get a better answer, than you can accept it by clicking on check mark at the top left side of answer :-)
    – Zarko
    Apr 5, 2018 at 19:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .