7

The arrows from Training Examples and Hypothesis Set are crossing eachother. Is there a way to avoid this, i.e. that they change the "dock" position on Learning Algorithm?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    [myBox/.style={rectangle,
                   draw,
                   align=center,
                   inner sep=2.5mm}]

    \node[myBox] (unknownTargetFunction) at (-4, 4) {\textsc{Unknown Target Function}\\$f: \mathcal{X} \rightarrow \mathcal{Y}$};
    \node[myBox] (trainingExamples) at (-4, 2) {\textsc{Training Examples}\\$\mathcal{D} = (x_1,y_1),...,(x_n,y_n)$};
    \node[myBox] (learningAlgorithm) at ( 0, 0) {\textsc{Learning Algorithm}\\$\mathcal{A}$};
    \node[myBox] (finalHypothesis) at ( 5, 0) {\textsc{Final Hypothesis}\\$g \approx f$};
    \node[myBox] (hypothesisSet) at (-4,-2) {\textsc{Hypothesis Set}\\$\mathcal{H}$};

    \draw [->] (unknownTargetFunction) to (trainingExamples);
    \draw [->] (trainingExamples) to [bend right] (learningAlgorithm);
    \draw [->] (hypothesisSet) to [bend left] (learningAlgorithm);
    \draw [->] (learningAlgorithm) to (finalHypothesis);
\end{tikzpicture}
\end{document}

The code produces: LaTeX code output

Information: The idea behind the picture originate from the book "Learning From Data" by Y. S. Abu-Mostafa et.al.

  • 3
    \draw [->] (trainingExamples) to [bend right] (learningAlgorithm.170); \draw [->] (hypothesisSet) to [bend left] (learningAlgorithm.190); – Gonzalo Medina Jan 23 '15 at 20:35
  • 1
    Somewhat urelated: ... should be \dots and the colon in the map should be \colon instead of :. – Svend Tveskæg Jan 25 '15 at 10:59
5

You have, at least, three options:

  • You can use the "angle" anchors for a ņode:

    \draw [->] (trainingExamples) to [bend right] (learningAlgorithm.170);
    \draw [->] (hypothesisSet) to [bend left] (learningAlgorithm.190);
    
  • You can use the calc library and a partway modifier to avoid manual calculations:

    \draw [->] (trainingExamples) to [bend right]  
      ( $ (learningAlgorithm.west)!0.5!(learningAlgorithm.north west) $ );
    \draw [->] (hypothesisSet) to [bend left] 
      ( $ (learningAlgorithm.west)!0.5!(learningAlgorithm.south west) $ );
    
  • You can use the west anchor and a manual shift in the y direction:

    \draw [->] (trainingExamples) to [bend right]  
      ([yshift=10pt]learningAlgorithm.west);
    \draw [->] (hypothesisSet) to [bend left] 
      ([yshift=-10pt]learningAlgorithm.west);
    

The code, showing the first two options:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
    [myBox/.style={rectangle,
                   draw,
                   align=center,
                   inner sep=2.5mm}]

    \node[myBox] (unknownTargetFunction) at (-4, 4) {\textsc{Unknown Target Function}\\$f: \mathcal{X} \rightarrow \mathcal{Y}$};
    \node[myBox] (trainingExamples) at (-4, 2) {\textsc{Training Examples}\\$\mathcal{D} = (x_1,y_1),...,(x_n,y_n)$};
    \node[myBox] (learningAlgorithm) at ( 0, 0) {\textsc{Learning Algorithm}\\$\mathcal{A}$};
    \node[myBox] (finalHypothesis) at ( 5, 0) {\textsc{Final Hypothesis}\\$g \approx f$};
    \node[myBox] (hypothesisSet) at (-4,-2) {\textsc{Hypothesis Set}\\$\mathcal{H}$};

    \draw [->] (unknownTargetFunction) to (trainingExamples);
    \draw [->] (trainingExamples) to [bend right] (learningAlgorithm.170);
    \draw [->] (hypothesisSet) to [bend left] (learningAlgorithm.190);
    \draw [->] (learningAlgorithm) to (finalHypothesis);
\end{tikzpicture}

\begin{tikzpicture}
    [myBox/.style={rectangle,
                   draw,
                   align=center,
                   inner sep=2.5mm}]

    \node[myBox] (unknownTargetFunction) at (-4, 4) {\textsc{Unknown Target Function}\\$f: \mathcal{X} \rightarrow \mathcal{Y}$};
    \node[myBox] (trainingExamples) at (-4, 2) {\textsc{Training Examples}\\$\mathcal{D} = (x_1,y_1),...,(x_n,y_n)$};
    \node[myBox] (learningAlgorithm) at ( 0, 0) {\textsc{Learning Algorithm}\\$\mathcal{A}$};
    \node[myBox] (finalHypothesis) at ( 5, 0) {\textsc{Final Hypothesis}\\$g \approx f$};
    \node[myBox] (hypothesisSet) at (-4,-2) {\textsc{Hypothesis Set}\\$\mathcal{H}$};

    \draw [->] (unknownTargetFunction) to (trainingExamples);
    \draw [->] (trainingExamples) to [bend right]  
    ( $ (learningAlgorithm.west)!0.5!(learningAlgorithm.north west) $ );
    \draw [->] (hypothesisSet) to [bend left] 
        ( $ (learningAlgorithm.west)!0.5!(learningAlgorithm.south west) $ );
    \draw [->] (learningAlgorithm) to (finalHypothesis);
\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.