2

enter image description here

I want to have those remarks inside the rectangular box. Thank you so much. So far I made this, but I don't know how to type more words inside the boxes. And how can I make those "Input" cloud and "Output" cloud at the position that I want?

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

% Define block styles
\tikzstyle{block} = [rectangle, draw,  
    text width=15em, text centered, rounded corners, minimum height=16em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse, node distance=6cm,
    minimum height=8em]

\begin{document}

\begin{tikzpicture}[node distance = 10cm, auto]
    % Place nodes
    \node [block] (init) {\underline{Machine}};
    \node [cloud, left of=init] (data) {\underline{Training data set}};
    \node [cloud, above right of=init] (input) {\underline{Input}};
    \node [cloud, below right of=init] (output) {\underline{Output}};
    % Draw edges
    \path [line] (data) -- (init);
    \path [line] (input) -- (init);
    \path [line] (init) -- (output);
\end{tikzpicture}


\end{document}
2
  • 4
    What have you tried so far? TikZ? Pstricks? Metapost? Please help us help you by providing a minimal compilable example (MWE).
    – TeXnician
    Commented Sep 24, 2018 at 8:57
  • So far I made this, but I don't know how to type more words inside the boxes. And how can I make those "Input" cloud and "Output" cloud at the position that I want?
    – Alsace
    Commented Sep 25, 2018 at 6:01

1 Answer 1

5

As a starting point:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows,
                positioning,    % <--- added
                shapes}
\usepackage{xparse}% So that we can have two optional parameters
\NewDocumentCommand\DownArrow{O{2.0ex} O{black}}%
{%
\mathrel{\tikz[baseline] \draw [<-, line width=0.5pt, #2] (0,0) -- ++(0,#1);}
}

\begin{document}
    \begin{tikzpicture}[
node distance = 3mm and 9mm,
 block/.style = {rectangle, draw, rounded corners,
                 text width =15em, align=center},
 cloud/.style = {draw, ellipse, aspect=1.2, align=center}
                    ]
% Place nodes
\node [block] (init) {\underline{Machine}\\
                      $f(\vec{x}) = \theta_0 + \theta_1x_1 + \dotsm + \theta_n x_n$\\[1ex]
                      $\DownArrow[30pt]$\\[1ex]
                      $y=\phi\bigl(f(\vec{x})\bigr)$
                      };
\node [cloud, left=of init] (data)
                    {\underline{Training data set}\\
                     dog, cat, pig, etc};
\node [cloud, above right=of init.east] (input)
                    {\underline{Input}\\
                     features data $\vec{x}$};
\node [cloud, below right=of init.east] (output)
                    {\underline{Output}\\
                     class: $y$};
% Draw edges
\draw[-latex']  (data) -- (init);
\draw[-latex']  (input) -- (init.east |- input);
\draw[-latex']  (init.east |- output) -- (output);
    \end{tikzpicture}
\end{document}

You were on the right track :). To your code I made the following changes:

  • Correct the input encoding (it should be only one, recent article for default use utf8).
  • For positioning, use the library positioning and its syntax (note above right=of ... instead your above of = ...).
  • The use of \tikzstyle is not recomended. Instead of it, use \tikzset or define styles as options to tikzpicture (as I do in the above MWE).
  • After defining align=center, you can write multi line (centered) text in the nodes

enter image description here

edit: next iteration (should be closer to your sketch):

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows,
                positioning,    % <--- added
                shapes}
\usepackage{xparse}% So that we can have two optional parameters
\NewDocumentCommand\DownArrow{O{2.0ex} O{black}}%
{%
\mathrel{\tikz[baseline] \draw [<-, line width=0.5pt, #2] (0,0) -- ++(0,#1);}
}

\begin{document}
    \begin{tikzpicture}[
node distance = 3mm and 9mm,
 block/.style = {rectangle, draw, rounded corners,
                 text width =15em, align=center},
 cloud/.style = {draw, ellipse, aspect=1.2, align=center},
                    ]
% Place nodes
\node [block, label={[anchor=east, align=center, xshift=-1em,
                      font=\small\linespread{0.8}\selectfont, 
                      text=purple]right:
                $x_1,\dotsc,x_n$:\\
                 features\\ 
                 variables} 
       ] (init) {\underline{Machine}\\
                 $f(\vec{x}) = \theta_0 + \theta_1 x_1 + \dotsm + \theta_n x_n$\\[1ex]
                 $\DownArrow[30pt]$\\[1ex]
                 $y=\phi\bigl(f(\vec{x})\bigr)$
                 };
\node [cloud, left=of init] (data)
                 {\underline{Training data set}\\
                  dog, cat, pig, etc};
\node [cloud, above right=of init.east] (input)
                 {\underline{Input}\\
                  features data $\vec{x}$};
\node [cloud, below right=of init.east] (output)
                  {\underline{Output}\\
                   class: $y$};
% Draw edges
\draw[-latex']  (data) -- (init);
\draw[red,-latex']  (input) -- (init.east |- input);
\draw[red,-latex']  (init.east |- output) -- (output);
    \end{tikzpicture}
\end{document}

enter image description here

Addendum: In the last three years, packages tikz and document class article have undergone several additions, with which the above solution proposal can/had to be now written as follows:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,    % changed
                positioning,    % <--- added
                shapes}
\NewDocumentCommand\DownArrow{O{2.0ex} O{black}}%
{%
\mathrel{\tikz[baseline] \draw [Straight Barb-, semithick, #2] (0,0) -- ++(0,#1);}
}

\begin{document}
    \begin{tikzpicture}[
node distance = 3mm and 9mm,
 block/.style = {rectangle, draw, rounded corners,
                 text width =15em, align=center},
 cloud/.style = {draw, ellipse, aspect=1.2, align=center},
                    ]
% Place nodes
\node [block, label={[anchor=east, align=center, xshift=-1em,
                      font=\small\linespread{0.8}\selectfont,
                      text=purple]right:
                $x_1,\dotsc,x_n$:\\
                 features\\
                 variables}
       ] (init) {\underline{Machine}\\
                 $f(\vec{x}) = \theta_0 + \theta_1 x_1 + \dotsm + \theta_n x_n$\\[1ex]
                 $\DownArrow[30pt]$\\[1ex]
                 $y=\phi\bigl(f(\vec{x})\bigr)$
                 };
\node [cloud, left=of init] (data)
                 {\underline{Training data set}\\
                  dog, cat, pig, etc};
\node [cloud, above right=of init.east] (input)
                 {\underline{Input}\\
                  features data $\vec{x}$};
\node [cloud, below right=of init.east] (output)
                  {\underline{Output}\\
                   class: $y$};
% Draw edges
\draw[-Latex]  (data) -- (init);
\draw[red,-Latex]  (input) -- (init.east |- input);
\draw[red,-Latex]  (init.east |- output) -- (output);
    \end{tikzpicture}
\end{document}

Result is almost the same as befone:

enter image description here

6
  • Thank you for your great help. I have two more questions: 1. How to rescale the whole chart? 2. How to change the color of the arrow? Thank you so much.
    – Alsace
    Commented Sep 25, 2018 at 9:13
  • @Alsacelei, (i) rescaling image is possible, but it is not good idea. is image to small or to big? (ii) color of arrows you can change on the way as is done in the second example: \draw[red,-latex'] ... where instead red color you use color which you like.
    – Zarko
    Commented Sep 25, 2018 at 10:43
  • Thanks. It is too big. Because I am going to put it into the presentation slide, so I want to rescale the whole chart.
    – Alsace
    Commented Sep 25, 2018 at 10:50
  • the best is ask new question that other people can see your problem . since my answer provide images as you ask in question, it will be nice from you that you accept it.
    – Zarko
    Commented Sep 25, 2018 at 10:56
  • 1
    @James, thank you very much for the info. I added new version for possible solution, which consider your information and advances of article document class.
    – Zarko
    Commented Sep 17, 2021 at 21:30

You must log in to answer this question.

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