TikZ-PGF – TikZ: Diagram of a Perceptron

diagramstikz-pgf

I'm trying to create a TikZ based version of the following diagram (taken from here), but I don't know how to approach it.

It doesn't need to look exactly like the original, but the basic idea should be preserved. It would especially be great if the paths from X_n to the sum function were straight lines without a "bend" like in the original. That makes a matrix layout difficult to use.

The definition of the output function can be left away.

Could someone point me to an approach that will work in this case, or even create a tikz texample?

Perceptron


Update: I ended up combining the approaches by @m0nhawk and @Toscho and came up with this:

Perceptron in TikZ

Sourcecode is here: https://github.com/dbrgn/blog/blob/master/content/images/2013/3/26/perceptron.tex

Best Answer

Here is the simple reconstruction. Issues:

  • Left of equations, can easily be added with node.
  • Make inputs and weights with \foreach.
  • Increase the Activation function to be more like the original one.
  • Improve TikZ styles.

Code:

\documentclass[tikz]{standalone}
\usepackage{tikz}
    \usetikzlibrary{positioning}

\tikzset{basic/.style={draw,fill=blue!20,text width=1em,text badly centered}}
\tikzset{input/.style={basic,circle}}
\tikzset{weights/.style={basic,rectangle}}
\tikzset{functions/.style={basic,circle,fill=blue!10}}

\begin{document}
    \begin{tikzpicture}
        \node[functions] (center) {};
        \node[below of=center,font=\scriptsize,text width=4em] {Activation function};
        \draw[thick] (0.5em,0.5em) -- (0,0.5em) -- (0,-0.5em) -- (-0.5em,-0.5em);
        \draw (0em,0.75em) -- (0em,-0.75em);
        \draw (0.75em,0em) -- (-0.75em,0em);
        \node[right of=center] (right) {};
            \path[draw,->] (center) -- (right);
        \node[functions,left=3em of center] (left) {$\sum$};
            \path[draw,->] (left) -- (center);
        \node[weights,left=3em of left] (2) {$w_2$} -- (2) node[input,left of=2] (l2) {$x_2$};
            \path[draw,->] (l2) -- (2);
            \path[draw,->] (2) -- (left);
        \node[below of=2] (dots) {$\vdots$} -- (dots) node[left of=dots] (ldots) {$\vdots$};
        \node[weights,below of=dots] (n) {$w_n$} -- (n) node[input,left of=n] (ln) {$x_n$};
            \path[draw,->] (ln) -- (n);
            \path[draw,->] (n) -- (left);
        \node[weights,above of=2] (1) {$w_1$} -- (1) node[input,left of=1] (l1) {$x_1$};
            \path[draw,->] (l1) -- (1);
            \path[draw,->] (1) -- (left);
        \node[weights,above of=1] (0) {$w_0$} -- (0) node[input,left of=0] (l0) {$1$};
            \path[draw,->] (l0) -- (0);
            \path[draw,->] (0) -- (left);
        \node[below of=ln,font=\scriptsize] {inputs};
        \node[below of=n,font=\scriptsize] {weights};
    \end{tikzpicture}
\end{document}

Picture:

result