7

I'm trying to annotate an diagram of a neural network with an equation that describes the activity of each node. I can't get the equation to the upper right, where I want it to be. I've tried using the scope environment in TikZ, \vspace and \hspace outside of tikz and even multicols.

I feel there likely is an easier or more elegant way of doing this. To make it easier to find, the equation I want to put in the upper right is, in this example, immediately after the tikzpicture environment ends. Here's my MWE:

 \documentclass[tikz]{standalone}
 \usepackage{tikz}
 \usetikzlibrary{arrows}
 \definecolor{burntorange}{RGB}{204,85,0}

 \begin{document}
 \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
   thick,main node/.style={circle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]

  \node[main node, scale=1.4] (interest) {$\vec{v}_i$};
  \node[main node, fill=blue!10] (j) [below left of=interest] {$\vec{v}_j$};
  \node[main node, fill=blue!10] (k) [below right of=j] {$\vec{v}_k$};
  \node[main node, fill=burntorange, below right of=interest, distance = 5cm ]  (input) [below right of=interest] {input $u$};

 \begin{scope}[every node/.style={font=\sffamily\small}]
  \path
(interest)
            edge [bend right] node[left] {$\mathbf{M}_{ji}$} (j) 
        edge [loop above] node[above] {$\mathbf{M}_{ii}$}  (interest)
        edge [bend left] node {$\mathbf{M}_{ki}$} (k);
\path[every edge/.style={gray,draw=gray}]
(j)     edge node [right] {$\mathbf{M}_{ij}$} (interest)
        edge [loop left] node {$\mathbf{M}_{jj}$} (j)
        edge [bend right] node[left] {$\mathbf{M}_{jk}$} (k)
(k)     edge node [right] {$\mathbf{M}_{kj}$} (j)
        edge node [bend right] {$\mathbf{M}_{ik}$} (interest)
        edge [loop below] node {$\mathbf{M}_{kk}$} (k)
(input) edge [bend right] node {$\mathbf{W}_i$} (interest)
        edge [bend left] node {$\mathbf{W}_k$} (k);
 \end{scope}
 \end{tikzpicture}
 {$\tau_{i}\frac{d\vec{v_{i}}}{dt}=-\vec{v}_{i}+\mathbf{M}_{ii}\vec{v}_{i}+
  \sum_{j\neq i}\mathbf{M}_{ij}\vec{v}_{j}+\mathbf{W}_{i}\vec{u}$}
 \end{document}
7

I hope I understand your question corrcectly. You can put the equation in a node and position that node. Positioning can be in various ways left of v_i, above input u etc. Here is another alternative:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\definecolor{burntorange}{RGB}{204,85,0}
\begin{document}

 \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
   thick,main node/.style={circle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]

  \node[main node, scale=1.4] (interest) {$\vec{v}_i$};
  \node[main node, fill=blue!10] (j) [below left of=interest] {$\vec{v}_j$};
  \node[main node, fill=blue!10] (k) [below right of=j] {$\vec{v}_k$};
  \node[main node, fill=burntorange, below right of=interest, distance = 5cm ]  (input) [below right of=interest] {input $u$};

 \begin{scope}[every node/.style={font=\sffamily\small}]
  \path
(interest)
            edge [bend right] node[left] {$\mathbf{M}_{ji}$} (j) 
        edge [loop above] node[above] {$\mathbf{M}_{ii}$}  (interest)
        edge [bend left] node {$\mathbf{M}_{ki}$} (k);
\path[every edge/.style={gray,draw=gray}]
(j)     edge node [right] {$\mathbf{M}_{ij}$} (interest)
        edge [loop left] node {$\mathbf{M}_{jj}$} (j)
        edge [bend right] node[left] {$\mathbf{M}_{jk}$} (k)
(k)     edge node [right] {$\mathbf{M}_{kj}$} (j)
        edge node [bend right] {$\mathbf{M}_{ik}$} (interest)
        edge [loop below] node {$\mathbf{M}_{kk}$} (k)
(input) edge [bend right] node {$\mathbf{W}_i$} (interest)
        edge [bend left] node {$\mathbf{W}_k$} (k);
 \end{scope}
\node at ([shift={(-1cm,-1cm)}]current bounding box.north east) {$\tau_{i}\frac{d\vec{v_{i}}}{dt}=-\vec{v}_{i}+\mathbf{M}_{ii}\vec{v}_{i}+
  \sum_{j\neq i}\mathbf{M}_{ij}\vec{v}_{j}+\mathbf{W}_{i}\vec{u}$};

 \end{tikzpicture}
\end{document}

enter image description here

  • That's exactly what I wanted. I tried annotating edges, but it never occurred to me to use a node like that. Thank you for teaching me something about TikZ. – mac389 Sep 30 '12 at 14:45
  • 1
    @mac389 My pleasure. If the math needs to be regular, you can add \displaystyle just after the first $ sign which would show it as if it was enclosed by \[...\] – percusse Sep 30 '12 at 14:47

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.