1

How can I draw the following which depicts certain vector and matrix operations.

Vector Mixture vs Tensor Based

Update: I modified @rpapa 's solution a bit and to get the following.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fit,backgrounds}
\usepackage{float}
\usepackage{caption}

\begin{document}

\tikzstyle{background}=[rectangle, fill=green!85, inner sep=0.1cm, rounded corners=2.5mm, line width=0.3mm]

\newcommand{\Vcol}[2]{
  \foreach \nn in {1,2,...,5}{
    \node[circle,draw,fill=#2, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
  }
  \begin{pgfonlayer}{background}
    \node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
  \end{pgfonlayer}
}

\newcommand{\VcolS}[3]{
  \foreach \nn in {1,2,...,5}{
    \node[circle,draw, shade, left color=#2, right color=#3, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
  }
  \begin{pgfonlayer}{background}
    \node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
  \end{pgfonlayer}
}

\newcommand{\VcolD}[3]{
  \node[circle,draw,fill=#2, line width=0.25mm] (#1-1) at (0,{-1.5*1 em}) {};
  \foreach \nn in {2,...,5}{
    \node[circle,draw,fill=#3, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
  }
  \begin{pgfonlayer}{background}
    \node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
  \end{pgfonlayer}
}


\newcommand{\Mat}[2]{
  \foreach \nr in {1,2,...,5}{
    \foreach \nc in {1,2,...,5}{
      \node[circle,draw,fill=#2, line width=0.25mm] (#1-\nr-\nc) at ({1.5*\nr em},{-1.5*\nc em}) {};
    }
  }
  \begin{pgfonlayer}{background}
    \node [background, fit=(#1-1-1) (#1-5-5), draw] (col-#1) {};
  \end{pgfonlayer}
}


\begin{tikzpicture}

\begin{scope}[xshift=0]
  \Vcol{a}{yellow!85}
\end{scope}

\begin{scope}[xshift=3em]
  \Vcol{b}{red!85}
\end{scope}

\begin{scope}[xshift=6em]
  \VcolS{c}{yellow}{red}
\end{scope}

\begin{scope}[xshift=9em]
  \Mat{e}{yellow!85}
\end{scope}

\begin{scope}[xshift=19.5em]
  \Vcol{b}{red!85}
\end{scope}

\begin{scope}[xshift=22.5em]
  \VcolD{b}{brown!85}{red!45}
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

  • 1
    You're asking an awful lot, have you tried anything? Yes, you could draw this with something like TikZ, course you could. But I'm not really sure that would be the best use of your time, this is something better drawn in image creation software - is there any reason why you can't just include this image? TikZ is really meant, I think, for technical drawings, or really really simple stuff. This doesn't even have any text, so it's not really clear to me why it couldn't be included as is. In any case, TikZ is a massive learning curve, and I wouldn't start by trying to draw this – Au101 Jan 13 '16 at 4:58
  • You may start with the Tikz/PGF package for drawing diagrams. sourceforge.net/projects/pgf and ctan.org/pkg/pgf. Some examples texample.net/tikz/examples/all. You are more likely to get help if you add a minimum working example. – AJN Jan 13 '16 at 5:01
  • See if this example is is useful as a strting point. texample.net/tikz/examples/matrix-multiplication. It shows how to make matrices, put circles around elements, and draw arrows. – AJN Jan 13 '16 at 5:11
  • @Au101 I agree that this is not meant to be drawn in TeX but in an image creation software. I posted the question to check if there are any 'magical' packages (that I do not know of) which make drawing this easy. I would need this to show various deep learning architectures (some examples: RNN Encoder-Decoder, MV RNN ) for my project and thesis. I tried to modify rpapa's answer as updated in the post. I think, using Inkscape is the best thing for me. – Chetan Naik Jan 13 '16 at 11:08
1

Here are a beginning with tikz

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,fit}
\usepackage{caption}

\begin{document}

\newcommand{\Vcol}[2]{
\foreach \nn in {1,2,...,5}{
\node[circle,draw, fill=#2](#1-\nn) at (0,{-1.5*\nn em}){};
}
\node[fit=(#1-1) (#1-5), draw](col-#1){};
}

\begin{tikzpicture}

\begin{scope}[xshift=0]
\Vcol{a}{red}
\end{scope}

\begin{scope}[xshift=3em]
\Vcol{b}{green}
\end{scope}


\begin{scope}[xshift=6em]
\Vcol{b}{green!50!red}
\end{scope}



\end{tikzpicture}

\end{document}

enter image description here

1

Here a supplement to your code to draw arrows

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fit,backgrounds}
\usepackage{float}
\usepackage{caption}

\begin{document}

\tikzstyle{background}=[rectangle, fill=green!85, inner sep=0.1cm, rounded corners=2.5mm, line width=0.3mm]

\newcommand{\Vcol}[2]{
  \foreach \nn in {1,2,...,5}{
    \node[circle,draw,fill=#2, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
  }
  \begin{pgfonlayer}{background}
    \node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
  \end{pgfonlayer}
}

\newcommand{\VcolS}[3]{
  \foreach \nn in {1,2,...,5}{
    \node[circle,draw, shade, left color=#2, right color=#3, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
  }
  \begin{pgfonlayer}{background}
    \node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
  \end{pgfonlayer}
}

\newcommand{\VcolD}[3]{
  \node[circle,draw,fill=#2, line width=0.25mm] (#1-1) at (0,{-1.5*1 em}) {};
  \foreach \nn in {2,...,5}{
    \node[circle,draw,fill=#3, line width=0.25mm] (#1-\nn) at (0,{-1.5*\nn em}) {};
  }
  \begin{pgfonlayer}{background}
    \node [background, fit=(#1-1) (#1-5), draw] (col-#1) {};
  \end{pgfonlayer}
}


\newcommand{\Mat}[2]{
  \foreach \nr in {1,2,...,5}{
    \foreach \nc in {1,2,...,5}{
      \node[circle,draw,fill=#2, line width=0.25mm] (#1-\nr-\nc) at ({1.5*\nr em},{-1.5*\nc em}) {};
    }
  }
  \begin{pgfonlayer}{background}
    \node [background, fit=(#1-1-1) (#1-5-5), draw] (col-#1) {};
  \end{pgfonlayer}
}


\begin{tikzpicture}

\begin{scope}[xshift=0]
  \Vcol{a}{yellow!85}
\end{scope}

\begin{scope}[xshift=3em]
  \Vcol{b}{red!85}
\end{scope}


\begin{scope}[xshift=6em]
  \VcolS{c}{yellow}{red}
\end{scope}

\begin{scope}[xshift=9em]
  \Mat{e}{yellow!85}
\end{scope}

\begin{scope}[xshift=19.5em]
  \Vcol{f}{red!85}
\end{scope}


\begin{scope}[xshift=22.5em]
  \VcolD{g}{brown!85}{red!45}
\end{scope}

\foreach \i in{1,2,...,5}{
\draw[<->,blue,thick](a-\i)--(b-\i);}

\node [font=\large\bfseries] at ($(b-3)!0.5!(c-3)$){=};
\node [font=\large\bfseries] at ($(f-3)!0.5!(g-3)$){=};

\draw[->,blue,thick](e-5-1.center)--(e-5-5.center)--(f-5);
\draw[->,blue,thick](e-4-1.center)--(e-4-4.center)--($(e-5-4.center)+(-0.05,0)$)arc(180:00:0.05)--(f-4);
\draw[->,blue,thick](e-3-1.center)--(e-3-3.center)--($(e-4-3.center)+(-0.05,0)$)arc(180:00:0.05)--($(e-5-3.center)+(-0.05,0)$)arc(180:00:0.05)--(f-3);
\draw[->,blue,thick](e-2-1.center)--(e-2-2.center)--($(e-3-2.center)+(-0.05,0)$)arc(180:00:0.05)--($(e-4-2.center)+(-0.05,0)$)arc(180:00:0.05)--($(e-5-2.center)+(-0.05,0)$)arc(180:00:0.05)--(f-2);
\draw[->,blue,thick](e-1-1.center)--+(0,0.5)-|(f-1.center);
\end{tikzpicture}
\end{document}

enter image description here

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.