所以我试着按照https://stats.stackexchange.com/questions/16750/software-for-drawing-bayesian-networks-graphical-models但收效甚微。
我的问题是
- 如何在不写下所有变量的情况下合并多个变量(例如只说 $\pi_1 - \pi_k$ 或类似的)
- 我如何合并连接到 $\pi_3, \pi_k$ 的“幽灵节点”。
答案1
基于搜索矩阵我想到了这个:这不是最漂亮的解决方案,但与你的图片很接近。
\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}