# How do I make Bayesian networks?

I am trying to tek up a Bayesian network with nodes, edges, and truth tables next to each node like this:

What tools can I use to make something like that? Perhaps some package from the TikZ library?

Here's one possibility using TikZ; the tabular material was placed inside \nodes. The shapes library was used to have elliptical nodes.

The dcolumn package was used to get columns with alignment at the decimal separator; the booktabs package was used to build the tables (in particular, no vertical rules were drawn):

\documentclass{article}
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows}

\newcolumntype{M}[1]{D{.}{.}{1.#1}}

\begin{document}

\begin{tikzpicture}[
node distance=1cm and 0cm,
mynode/.style={draw,ellipse,text width=2cm,align=center}
]
\node[mynode] (sp) {Sprinkler};
\node[mynode,below right=of sp] (gw) {Grass wet};
\node[mynode,above right=of gw] (ra) {Rain};
\path (ra) edge[-latex] (sp)
(sp) edge[-latex] (gw)
(gw) edge[latex-] (ra);
\node[left=0.5cm of sp]
{
\begin{tabular}{cM{2}M{2}}
\toprule
& \multicolumn{2}{c}{Sprinkler} \\
Rain & \multicolumn{1}{c}{T} & \multicolumn{1}{c}{F} \\
\cmidrule(r){1-1}\cmidrule(l){2-3}
F & 0.4 & 0.6 \\
T & 0.01 & 0.99 \\
\bottomrule
\end{tabular}
};
\node[right=0.5cm of ra]
{
\begin{tabular}{M{1}M{1}}
\toprule
\multicolumn{2}{c}{Sprinkler} \\
\multicolumn{1}{c}{T} & \multicolumn{1}{c}{F} \\
\cmidrule{1-2}
0.2 & 0.8 \\
\bottomrule
\end{tabular}
};
\node[below=0.5cm of gw]
{
\begin{tabular}{ccM{2}M{2}}
\toprule
& & \multicolumn{2}{c}{Grass wet} \\
\multicolumn{2}{l}{Sprinkler rain} & \multicolumn{1}{c}{T} & \multicolumn{1}{c}{F} \\
\cmidrule(r){1-2}\cmidrule(l){3-4}
F & F & 0.4 & 0.6 \\
F & T & 0.01 & 0.99 \\
T & F & 0.01 & 0.99 \\
T & T & 0.01 & 0.99 \\
\bottomrule
\end{tabular}
};

\end{tikzpicture}

\end{document}


• Unfortunately, I am not able to comment Gonzalo Medinas answer, but please note that the arrow between "Grass wet" and "Rain" points into the wrong direction, which makes the network cyclic! Jun 16 '15 at 9:02
• @black.firefly the fix is simple: change (gw) edge[-latex] (ra) to (gw) edge[latex-] (ra). I edited the answer to incorporate the change. Thanks. Jun 16 '15 at 13:54