\documentclass{article}

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

%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\begin{document}
\pagestyle{empty}

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=6cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=12em, text centered, rounded corners, minimum height=4em]
\tikzstyle{block2} = [rectangle, draw, 
    text width=12em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=6cm,
    minimum height=2em]
    
\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [block2] (input) {\textbf{Input data:} $D = (D_L, D_U)$};
    \node [block, below of=input, node distance=3cm] (gmm) {\textbf{Phenotype modeling}: Select $D_L^i$ and model $F = D_L^i \cup D_U$ using a GMM (cluster number estimate using BIC).};
    \node [block, right of=gmm, node distance=6cm] (candidates) {\textbf{Get candidates}: Members of $D_U$ clustered with $D_L^i$ are considered candidats of class $i$.};
    \node [block, below of=candidates, node distance=3cm] (outlier) {Each candidate is tested against an \textbf{outlier detection} algorithm.};
    \node [block, left of=outlier, node distance=6cm] (decision) {Candidates classified as members of $i$ are merged with $D_L^i$. Those which are rejected are returned to $D_U$};
    \node [block, below of=decision, node distance=6cm] (new) {\textbf{Update classes:} examples in $D_U$ that are consistently accepted into a single class $i$ are labelled as members of $D_L^i$. \\ \bigskip \textbf{New phenotype:} Any example of $D_U$ not merged with any $D_L^i$ and which are consistenlty clustered together throughout the $N$ iterations are considered members of a \textit{new phenotype}. };
    \node [block2, right of=new, node distance=6cm] (output) {\textbf{Output:} Return unassigned examples, new $D_L^i$ members and new phenotypes. };

    \path [line] (input) -- (gmm);
    \path [line] (gmm) -- (candidates);
    \path [line] (candidates) -- (outlier);
    \path [line] (outlier) -- (decision);
    \path [line] (decision) -- node {next class $i$} (gmm);
    \path [line] (decision) -- node {all classes considered} (new);
    \path [line] (new) -- (output);

    % Background
    \begin{pgfonlayer}{background}
      \node [fill=yellow!20,rounded corners, draw=black!50, dashed, fit=(gmm) (outlier) (candidates) (decision)] {};
    \end{pgfonlayer}

    \node at (3,-1.5) {Repeat $N$ times};



    %% \node [cloud, right of=init] (system) {system};
    %% \node [block, below of=init] (identify) {identify candidate models};
    %% \node [block, below of=identify] (evaluate) {evaluate candidate models};
    %% \node [block, left of=evaluate, node distance=3cm] (update) {update model};
    %% \node [decision, below of=evaluate] (decide) {is best candidate better?};
    %% \node [block, below of=decide, node distance=3cm] (stop) {stop};
    %% % Draw edges
    %% \path [line] (init) -- (identify);
    %% \path [line] (identify) -- (evaluate);
    %% \path [line] (evaluate) -- (decide);
    %% \path [line] (decide) -| node [near start] {yes} (update);
    %% \path [line] (update) |- (identify);
    %% \path [line] (decide) -- node {no}(stop);

    %% \path [line,dashed] (system) -- (init);
    %% \path [line,dashed] (system) |- (evaluate);
\end{tikzpicture}


\end{document}
