如何在隐马尔可夫模型的节点中包含多行文本/数学?

如何在隐马尔可夫模型的节点中包含多行文本/数学?

我想知道是否有可能在 latex 中复制下图中的 HMM。如果可以,应该对下面的代码进行哪些修改?任何帮助都将不胜感激。

HMM_论文

请注意以下代码

\begin{tikzpicture}[
shorten >=1pt,
node distance=2cm,
auto,
state/.style={rectangle, draw=black!60, very thick, minimum size=5mm
},
]
\node[state] (l_1) {$\ell_1$};
\node[state] (l_2) [right of=l_1] {$\ell_2$};
\node[state] (l_3) [right of=l_2] {$\ell_3$};
\node[state] (l_i) [above of=l_3] {$\ell_i$};
\node[state] (l_4) [right of=l_3] {$\ell_4$};
\node[state] (l_5) [right of=l_4] {$\ell_5$};
\node[state] (l_6) [right of=l_5] {$\ell_6$};
\node[state] (end) [right of=l_6] {$\ell_e$};
\path[->] (l_1) edge node [swap] {1} (l_2)
(l_2) edge node [swap] {1} (l_3)
(l_3) edge node {3/5} (l_i)
edge node [swap] {2/5} (l_4)
(l_i) edge node {3/5} (l_4)
edge [loop above] node {2/5} ()
(l_4) edge node [swap] {1} (l_5)
(l_5) edge node [swap] {1} (l_6)
(l_6) edge node [swap] {1} (end)
(end) edge [loop right] node {1} ();
\end{tikzpicture}

输出图形(这里的转移概率是第一个图形中概率的指数) 输出图

那么,我应该如何最好地在节点内包含多行乳胶?

答案1

align=center或添加align=left到节点的选项中,例如单独显示,或通过样式显示多个。用于\\换行。

例子

\documentclass[10pt, border=20pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
shorten >=1pt,
node distance=2cm,
auto,
state/.style={rectangle, draw=black!60, very thick, minimum size=5mm
},
]
\node[state, align=left] (l_1) {$\ell_1$\\A: $+1.16$\\T: $-0.22$};
\node[state] (l_2) [right of=l_1] {$\ell_2$};
\node[state] (l_3) [right of=l_2] {$\ell_3$};
\node[state] (l_i) [above of=l_3] {$\ell_i$};
\node[state] (l_4) [right of=l_3] {$\ell_4$};
\node[state] (l_5) [right of=l_4] {$\ell_5$};
\node[state] (l_6) [right of=l_5] {$\ell_6$};
\node[state] (end) [right of=l_6] {$\ell_e$};
\path[->] (l_1) edge node [swap] {1} (l_2)
(l_2) edge node [swap] {1} (l_3)
(l_3) edge node {3/5} (l_i)
edge node [swap] {2/5} (l_4)
(l_i) edge node {3/5} (l_4)
edge [loop above] node {2/5} ()
(l_4) edge node [swap] {1} (l_5)
(l_5) edge node [swap] {1} (l_6)
(l_6) edge node [swap] {1} (end)
(end) edge [loop right] node {1} ();
\end{tikzpicture}
\end{document}

答案2

结果

\documentclass{article}

    \usepackage{tikz}
    \usepackage{amsmath}
    \usetikzlibrary{matrix}

    \usepackage{tikz-cd}
    \usetikzlibrary{arrows.meta, 
            shapes.geometric}
    \usepackage{amsmath}

\begin{document}

\begin{tikzpicture}[
shorten >=1pt,
node distance=3cm,
auto,
state/.style={rectangle, draw=black!60, very thick, minimum size=5mm
},
]
\node[state] (l_1) {
    \begin{tabular}{c} \( A:1.16 \) \\ \( T:-0.22 \) \end{tabular}
};
\node[state] (l_2) [right of=l_1] {
    \begin{tabular}{c} \( C:1.16 \) \\ \( G:-0.22 \) \end{tabular}
};
\node[state] (l_3) [right of=l_2]  {
    \begin{tabular}{c} \( A:1.16 \) \\ \( C:-0.22 \) \end{tabular}
};
\node[state] (l_i) [above of=l_3] {
    \begin{tabular}{c} \( A:-0.22 \) \\ \( C:0.47 \) \\ \(G:-0.22\) \\    \(T:-0.22\) \end{tabular}
};
\node[state] (l_4) [right of=l_3]  {
    \begin{tabular}{c} \( A:1.39 \) \end{tabular}
};
\node[state] (l_5) [right of=l_4]  {
    \begin{tabular}{c} \( G:-0.22 \) \\ \( T:1.16 \) \end{tabular}
};
\node[state] (l_6) [right of=l_5]  {
    \begin{tabular}{c} \( C:1.16 \) \\ \( G:-0.22 \) \end{tabular}
};
\path[->] (l_1) edge node [swap] {1} (l_2)
(l_2) edge node [swap] {0} (l_3)
(l_3) edge node {-0.51} (l_i)
edge node [swap] {-0.92} (l_4)
(l_i) edge node {-0.51} 
(l_4) edge [loop above] node {-0.92} ()
(l_4) edge node [swap] {0} (l_5)
(l_5) edge node [swap] {0} (l_6);
\end{tikzpicture}

\end{document}

相关内容