说明马尔可夫链中状态之间的转换

说明马尔可夫链中状态之间的转换

我怎样才能制作这样的图表来说明状态转换概率?

在此处输入图片描述

答案1

这可以使用TikZ有很多不同的方法。下面是一个使用链的示例:

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains}

\begin{document}

\begin{tikzpicture}[
mynode/.style={
  draw,
  minimum size=1em
  },
every loop/.append style={-latex},  
start chain=going right  
]
\foreach \Value in {1,...,5}
  \node[mynode,on chain] (s\Value) {$S_{\Value}$};
\path[-latex]
  (s2) edge[bend right] node[auto,swap,font=\small] {$0.7$} (s1)
  (s2) edge[bend right] node[auto,swap,font=\small] {$0.3$} (s3)
  (s3) edge[bend right] node[auto,swap,font=\small] {$0.5$} (s2)
  (s3) edge[bend right] node[auto,swap,font=\small] {$0.5$} (s4)
  (s4) edge[bend right] node[auto,swap,font=\small] {$0.65$} (s3)
  (s4) edge[bend right] node[auto,swap,font=\small] {$0.35$} (s5)
  (s1) edge[loop left] node[left,font=\small] {$1$} (s1)
  (s5) edge[loop right] node[right,font=\small] {$1$} (s5);
\end{tikzpicture}

\end{document}

答案2

这是一个pstricks解决方案:

 \documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}%
\usepackage{fourier}

\usepackage{pst-node}
\usepackage{auto-pst-pdf}

\pagestyle{empty}

\begin{document}

\psset{arrows=<-, arrowinset=0.15, shortput=nab, labelsep=2pt}
\[ \begin{psmatrix}[ colsep = 1.2]
    \psframebox{\pnode(0,3pt){S1}S_1} & \psframebox{S_2} & \psframebox{S_3} & \psframebox{S_4} & \psframebox{S_5\pnode(0,3pt){S5}}
    \psset{offset=-1.5pt, nodesep =-1pt, arcangleA=30,arcangleB=30}
    \nccircle[angleA=90, nodesep=8pt]{S1}{0.4}\nbput{\scriptstyle1}
    \ncarc[nodesep = -1pt]{1,1}{1,2}^{\scriptstyle0.7}\ncarc{1,2}{1,3}^{\scriptstyle0.5} \ncarc{1,3}{1,4}^{\scriptstyle0.65}
    \psset{offset=-0.5pt, nodesep=-0.5pt}
    \ncarc{1,3}{1,2}_{\scriptstyle0.3}\ncarc{1,4}{1,3}_{\scriptstyle0.5} \ncarc{1,5}{1,4}_{\scriptstyle0.35}
    \nccircle[angleA=-90, nodesep=8pt]{S5}{0.4}\nbput{\scriptstyle1}
    \end{psmatrix} \]

\end{document} 

在此处输入图片描述

答案3

另一个可能的解决方案

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}


\begin{document}
\begin{tikzpicture}
    [%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        node distance =.8cm,
        place/.style={rectangle,draw=blue!50,fill=blue!20,thick,
                      inner sep=0pt,minimum size=6mm}
    ]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \node[place] (1) {$s_{1}$};
    \node[place] (2) [right=of 1] {$s_{2}$};
    \node[place] (3) [right=of 2] {$s_{3}$};
    \node[place] (4) [right=of 3] {$s_{4}$};
    \node[place] (5) [right=of 4] {$s_{5}$};

    \draw [->,thick] (1.south west) to [bend left=55]  node[left]  {1}    (1.north west);
    \draw [<-,thick] (1.north east) to [bend left=15]  node[above] {0.7}  (2.north west);
    \draw [->,thick] (2.north east) to [bend left=15]  node[above] {0.3}  (3.north west);
    \draw [->,thick] (3.north east) to [bend left=15]  node[above] {0.5}  (4.north west);
    \draw [->,thick] (4.north east) to [bend left=15]  node[above] {0.35} (5.north west);
    \draw [<-,thick] (3.south east) to [bend right=15] node[below] {0.65} (4.south west);
    \draw [<-,thick] (2.south east) to [bend right=15] node[below] {0.5}  (3.south west);
    \draw [->,thick] (5.north east) to [bend left=55]  node[right] {1}    (5.south east);

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容