3

So I tried to follow the answer in https://stats.stackexchange.com/questions/16750/software-for-drawing-bayesian-networks-graphical-models with limited success.

My problem is

  1. How do I incorporate multiple variables without writing down all of them (eg. just say $\pi_1 - \pi_k$ or similar)
  2. How do I incorporate 'ghost nodes' as seen for the ones connecting to $\pi_3, \pi_k$.

enter image description here

2
  • Have a look at tikz matrix or foreach loops with positioning library. In very few lines the job can be done.
    – s__C
    Commented Jul 28, 2014 at 6:14
  • You may want to have a look to How to draw graphs in LaTeX? Commented Jul 28, 2014 at 6:18

1 Answer 1

5

Based on a search for matrix I came up with this: It's not the most beautiful solution, but is close to your pic.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, calc, positioning,matrix}
\tikzset{
data/.style={circle, draw, text centered, minimum height=3em ,minimum width = .5em, inner sep = 2pt},
empty/.style={circle, text centered, minimum height=3em ,minimum width = .5em, inner sep = 2pt},
}
\begin{document}
\begin{tikzpicture}[
align = flush center,
font = \small]
\matrix [
    matrix of nodes,
    column sep = 0.5em,
    row sep = 1.3em, 
    draw, dashed,
    nodes = {solid},
    ] (m)
{  
|[data]|$\pi_1$ &  |[data]|$\pi_2$ & |[data]|$\pi_3$ & |[empty]| & |[data]|$\pi_K$ \\
|[data]|$C_1$ &  |[data]|$C_2$ & |[data]|$C_3$ & |[empty]| & |[data]|$C_K$ \\
|[data]|$w_1$ &  |[data]|$w_2$ & |[data]|$w_3$ & |[empty]| & |[data]|$w_K$ \\
|[data]|$D_1$ &  |[data]|$D_2$ & |[empty]| & |[empty]| & |[data]|$D_N$ \\[.7em]
}; 
\draw[->](m-1-1) to (m-2-1);
\draw[->](m-2-1) to (m-3-1);
\draw[->](m-3-1) to (m-4-1);
\draw[->](m-3-1) to (m-1-2);
\draw[->](m-3-1.south) to (m-4-5);

\draw[->](m-1-2) to (m-2-2);
\draw[->](m-2-2) to (m-3-2);
\draw[->](m-3-2) to (m-1-1);
\draw[->](m-3-2) to (m-1-3);
\draw[->](m-3-2.south) to (m-4-1);
\draw[->](m-3-2.south) to (m-4-5);

\draw[->](m-1-3) to (m-2-3);
\draw[->](m-2-3) to (m-3-3);
\draw[->](m-3-3) to (m-1-2);

\draw[->](m-2-4) to (m-1-3);
\draw[->](m-3-4) to (m-1-5);

\draw[->](m-1-5) to (m-2-5);
\draw[->](m-2-5) to (m-3-5);
\draw[->](m-3-5) to (m-4-5);

\end{tikzpicture}
\end{document}

enter image description here

2
  • np, use CloudConvert to convert PDF to PNG
    – m0nhawk
    Commented Jul 28, 2014 at 8:49
  • @m0nhawk thanks again, i'll give it a try the next time :)
    – Dan H.
    Commented Jul 28, 2014 at 8:51

You must log in to answer this question.

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