![我如何绘制隐马尔可夫模型的图表?](https://linux22.com/image/398376/%E6%88%91%E5%A6%82%E4%BD%95%E7%BB%98%E5%88%B6%E9%9A%90%E9%A9%AC%E5%B0%94%E5%8F%AF%E5%A4%AB%E6%A8%A1%E5%9E%8B%E7%9A%84%E5%9B%BE%E8%A1%A8%EF%BC%9F.png)
答案1
练习(如何绘制虚线和使用空单元格):
\documentclass[margin=3mm]{standalone}
\usepackage{tikz-cd}
\usepackage{amsmath}
\begin{document}
\begin{tikzcd}[nodes in empty cells]
X_1 \ar[r, "A"] \ar[dd, "B"']
& X_2 \ar[r, "A"] \ar[dd, "B"']
& X_3 \ar[r, "A"] \ar[dd, "B"']
& \dots \ar[r, "A"]
& X_{T-1} \ar[dd, "B"'] \\
\arrow[rrrr, dashed, -,
start anchor={[shift={(-3ex,2ex)}]north west},
end anchor ={[shift={( 3ex,2ex)}]north east}]
& & & & \\
& & & \dotsm &
\end{tikzcd}
\end{document}
完整再现所呈现的图像:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz-cd}
\usepackage{amsmath}
\begin{document}
\begin{tikzcd}[nodes in empty cells]
\text{Markov process:}
& X_0 \ar[r, "A"] \ar[dd, "B"']
& X_1 \ar[r, "A"] \ar[dd, "B"']
& X_2 \ar[r, "A"] \ar[dd, "B"']
& \dots \ar[r, "A"]
& X_{T-1} \ar[dd, "B"'] \\
& \arrow[rrrr, dashed, -,
start anchor={[shift={(-3ex,2ex)}]north west},
end anchor ={[shift={( 3ex,2ex)}]north east}]
& & & & & \\
\text{Observations:}
& \mathcal{O}_0
& \mathcal{O}_1
& \mathcal{O}_2
& \dotsm
& \mathcal{O}_{T-1} \\
\end{tikzcd}
\end{document}
答案2
使用正常的matrix of math nodes
。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of math nodes,column sep=2em,row sep=4em] (m) {
\text{Markov process}: &
X_0 & X_1 & X_2 & \cdots & X_{T-1}\\
\text{Observations}: &
\mathcal{O}_0 & \mathcal{O}_1 & \mathcal{O}_2 & \cdots & \mathcal{O}_{T-1}\\
};
\foreach \X in {2,3,4,5}
{\draw[-latex] (m-1-\X) -- (m-1-\the\numexpr\X+1) node[midway,above]{$A$};
\ifnum\X=5
\draw[-latex] (m-1-6) -- (m-2-6) node[pos=0.6,left]{$B$};
\else
\draw[-latex] (m-1-\X) -- (m-2-\X) node[pos=0.6,left]{$B$};
\fi}
\draw[dashed] ([yshift=1ex]m.east) -- ([yshift=1ex]m.east-|m-1-1.east);
\end{tikzpicture}
\end{document}