0

From an answer to my previous question, I have this:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{positioning}
\begin{document}
\pagestyle{empty}

\def\layersep{2.5cm}

\begin{tikzpicture}[
      shorten >=1pt,->,draw=black!50, node distance=\layersep,
      every pin edge/.style={<-,shorten <=1pt},
      neuron/.style={circle split,fill=black!25,minimum size=17pt,inner sep=0pt},
      input neuron/.style={neuron, fill=green!50},
      output neuron/.style={neuron, fill=red!50},
      compute neuron/.style={neuron, fill=blue!50},
      annot/.style={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 position=-90, rotate=90] (I-\name) at (0,-\y) {};

    \node[left=1pt of I-1]{$h_0$};
    % Draw the compute layer nodes
    \foreach \name / \y in {1,...,5}
        \path[yshift=0.5cm]
            node[compute neuron,rotate=90] (C-\name) at (\layersep,-\y cm) {};

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

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

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

    % Annotate the layers
    \node[annot,above of=C-1, node distance=1cm] (hl) {compute layer};
    \node[annot,left of=hl] {Input layer};
    \node[annot,right of=hl] {Compute layer};
\end{tikzpicture}
% End of code
\end{document}

Notice the problem with the $h_0$ label. I want that label to be to the left of the node. I want other labels to be above nodes. How can I achieve this? The rotation of the node to accommodate the vertical line seems to affect the label, but I need both.

  • Why don't you use a label? – cfr Jun 01 '17 at 04:01
  • Hi @cfr, thanks for the reply. How can I do that? Can you illustrate? – StatsSorceress Jun 01 '17 at 04:09
  • see edit of my answer to your linked question ... there I assume, that label only one (so, it is written as node) and above (where don't overwrite existing drawings. but, as I see, you not very interested for my answer :) – Zarko Jun 01 '17 at 04:37

1 Answers1

1

Like this?

enter image description here

Still partially based on guessing but anyway. MWE, which generate above image is based on my answer here:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand\ppbb{path picture bounding box}

\begin{document}
\pagestyle{empty}

\def\layersep{2.5cm}

\begin{tikzpicture}[shorten >=1pt, ->, draw=black!50, 
        node distance = \layersep,
every pin edge/.style = {<-, shorten <=1pt},
   every label/.style = {label distance=0pt, inner sep=1pt,font=\small},
        neuron/.style = {circle, minimum size=17pt, inner sep=0pt,  
                         path picture={%
                         \path[draw=black!75,semithick,-]   (\ppbb.north)  -- (\ppbb.south);},
                         },
  input neuron/.style = {neuron, fill=green!50},
 output neuron/.style = {neuron, fill=red!50},
compute neuron/.style = {neuron, fill=blue!50},
         annot/.style = {text width=4em, text centered},
                    ]
% Draw the input layer nodes
\foreach \y [count=\yi from 0] in {1,...,4}
{\ifnum\y=1
    \node[input neuron, label=left:$h_\yi$] (I-\y) at (0,-\y)  {};
 \else  
    \node[input neuron, label=$h_\yi$] (I-\y) at (0,-\y) {};
 \fi
}
% Draw the compute layer nodes
\foreach \y [count=\yi from 0] in {1,...,5}
    \node[yshift=0.5cm,compute neuron,label=$C_\yi$] (C-\y) at (\layersep,-\y cm) {};
% Draw the output layer node
\node[output neuron,pin={[pin edge={->}]right:Output}, right=of C-3.west] (O) {};
% Connect every node in the input layer with every node in the
% compute layer.
\foreach \source in {1,...,4}
    \foreach \dest in {1,...,5}
        \path (I-\source) edge (C-\dest);
% Connect every node in the compute layer with the output layer
\foreach \source in {1,...,5}
    \path (C-\source) edge (O);
% Annotate the layers
    \begin{scope}[node distance=0pt]
\node[annot,above=4mm of C-1] (hl)      {Compute layer};
\node[annot,above=of hl.south -| I-1]   {Input layer};
\node[annot,above=of hl.south -| O]     {Output layer};

    \end{scope}
\end{tikzpicture}
% End of code
\end{document}
Zarko
  • 296,517
  • Basically yes, I want h_0 on the left hand side (all Input # stuff removed), and the other labels are correctly placed. – StatsSorceress Jun 01 '17 at 05:33
  • please see changed image in "answer". do you like to have labels above other neurons too (I_0,...., I_4)? – Zarko Jun 01 '17 at 06:15