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}
TeXnician
  • 33,589
Alsace
  • 61
  • 4
    What have you tried so far? TikZ? Pstricks? Metapost? Please help us help you by providing a minimal compilable example (MWE). – TeXnician Sep 24 '18 at 08: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 Sep 25 '18 at 06:01

1 Answers1

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

Zarko
  • 296,517
  • 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 Sep 25 '18 at 09: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 Sep 25 '18 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 Sep 25 '18 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 Sep 25 '18 at 10:56
  • The arrows library is now official depreciated. One should use arrows.meta. – James Sep 17 '21 at 19:41
  • 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 Sep 17 '21 at 21:30