如何在 Latex 中绘制循环马尔可夫链 n 个状态图?

如何在 Latex 中绘制循环马尔可夫链 n 个状态图?

在此处输入图片描述

生命周期分为 n 个阶段,从卵到成虫。个体只有达到成虫阶段才能进行生产。p11、p22... 是生存概率,p12、p23... 过渡概率 R 是状态 n 到 1 的生产率。

答案1

此示例可用于进一步调整图形以满足您的需求。我之前没有更改过最终节点成人n-1n

给出马尔可夫链的九个步骤的示例代码:

\documentclass[11pt]{article}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,automata,decorations.markings,decorations.pathreplacing,decorations.text,backgrounds,shapes.geometric}

\begin{document}
    
    
    \begin{tikzpicture}
        [trans/.style={to path={ .. controls +(60:1.5) and +(120:1.5) .. (\tikztotarget) \tikztonodes}},radius=2cm]
        
            \path (4,0) -- +(180:2cm) node(p0) {0} arc [start angle=-180, delta angle=-40] node(p1) {1};
            \draw[-{Stealth},shorten <=8pt, font=\footnotesize] (p0)  arc [start angle=-180, delta angle=-32]  (p1);
            \draw[fill=blue!30, opacity=0.2] (p0) circle[radius=3mm] (p1) circle[radius=3mm];
            \path[->] (p0) edge [trans,red,rotate=90] (p0); 
            \path[->] (p1) edge [trans,above,red,rotate=50] (p1); 
            \path (4,0) --+(160:1.6cm) node {$p_{01}$};
            \path (4,0) --+(180:3.3cm) node[red,rotate=90] {$p_{00}$};
            \path (4,0) --+(140:3.3cm) node[red,rotate=50] {$p_{01}$};
            
            \foreach [count=\i, evaluate=\px as \hk using 140+\px*40,   % calculate next arc angle
                                evaluate=\hk as \hkp using \hk+20,      % calculate halfway angle to place nodes on arc
                                evaluate=\px as \lpr using 90-\px*40,   % calculate edge to place loop
                                evaluate=\px as \lpa using \hk+40]      % calculate angle to place nodes on loop
                    \px in {2,3,...,8}{
                \path[font=\small] (p\i) arc [start angle=-\hk, delta angle=-40] node(p\px) {\px};
                \draw[fill=blue!30, opacity=0.2] (p\px) circle[radius=3mm];
                \draw[-{Stealth},shorten <=8pt, font=\footnotesize] (p\i)  arc [start angle=-\hk, delta angle=-32]  (p\px);
                \path (4,0) -- +(-\hkp:1.6cm) node {$p_{\i\px}$};
                \path[->] (p\px) edge [trans,red,rotate=\lpr] (p\px);
                \path (4,0) --+(-\lpa:3.3cm) node[red,rotate=\lpr] {$p_{\px\px}$};
            }
        
        \draw[-{Stealth},shorten <=8pt, font=\footnotesize] (p8)  arc [start angle=-140, delta angle=-32]  (p0);
        \path[font=\bfseries\small] (4,0) --+(-160:1.6cm) node {R};
        \node[left of= p8, font=\bfseries\small] {adult};
        \node[right of= p0, font=\bfseries\small] {egg};
        
    \end{tikzpicture}
    
\end{document}

马尔可夫链

添加

查看上面的代码,节点和n-1/n节点没有被放置在图中。节点中的下标看起来根本不像下标。tikz图片下面的代码解决/补充了所有问题:

    \begin{tikzpicture}
        [trans/.style={to path={ .. controls +(60:1.5) and +(120:1.5) .. (\tikztotarget) \tikztonodes}},radius=2cm]
    
        \path (4,0) -- +(180:2cm) node(p0) {0} arc [start angle=-180, delta angle=-40] node(p1) {1};
        \draw[-{Stealth},shorten <=8pt, font=\footnotesize] (p0)  arc [start angle=-180, delta angle=-32]  (p1);
        \draw[fill=blue!30, opacity=0.2] (p0) circle[radius=3mm] (p1) circle[radius=3mm];
        \path[-{Stealth}, shorten >=2pt] (p0) edge [trans,red,rotate=90] (p0); 
        \path[-{Stealth}, shorten >=2pt] (p1) edge [trans,above,red,rotate=50] (p1); 
        \path (4,0) --+(160:1.6cm) node {$p_{{\textstyle\mathstrut}01}$};
        \path (4,0) --+(180:3.3cm) node[red,rotate=90] {$p_{{\textstyle\mathstrut}00}$};
        \path (4,0) --+(140:3.3cm) node[red,rotate=50] {$p_{{\textstyle\mathstrut}11}$};
    
        \foreach [count=\i, evaluate=\px as \hk using 140+\px*40,   % calculate next arc angle
                evaluate=\hk as \hkp using \hk+20,      % calculate halfway angle to place nodes on arc
                evaluate=\px as \lpr using 90-\px*40,   % calculate edge to place loop
                evaluate=\px as \lpa using \hk+40]      % calculate angle to place nodes on loop
                \px in {2,3,...,5}{
            \path[font=\small] (p\i) arc [start angle=-\hk, delta angle=-40] node(p\px) {\px};
            \draw[fill=blue!30, opacity=0.2] (p\px) circle[radius=3mm];
            \draw[-{Stealth},shorten <=8pt, font=\footnotesize] (p\i)  arc [start angle=-\hk, delta angle=-32]  (p\px);
            \path (4,0) -- +(-\hkp:1.6cm) node {$p_{{\textstyle\mathstrut}\i\px}$};
            \path[-{Stealth}, shorten >=2pt] (p\px) edge [trans,red,rotate=\lpr] (p\px);
            \path (4,0) --+(-\lpa:3.3cm) node[red,rotate=\lpr] {$p_{{\textstyle\mathstrut}\px\px}$};
            }


        \path (4,0) -- +(260:2cm) node(p7) [font=\footnotesize] {$n\!\shortminus\!1$};
        \path (4,0) -- +(220:2cm) node(p8) {$n$};
        \draw[fill=blue!30, opacity=0.2] (p7) circle[radius=3mm] (p8) circle[radius=3mm];
        \draw[-{Stealth},shorten <=8pt, font=\footnotesize] (p7)  arc [start angle=-100, delta angle=-32]  (p8);
        \path[-{Stealth}, shorten >=2pt] (p7) edge [trans,red,rotate=170] (p7); 
        \path[-{Stealth}, shorten >=2pt] (p8) edge [trans,above,red,rotate=130] (p8); 
        \path (4,0) --+(260:1.6cm) node {$p_{{\textstyle\mathstrut}n(n\!\shortminus\!1)}$};
        \path (4,0) --+(220:3.3cm) node[red,rotate=130] {$p_{{\textstyle\mathstrut}nn}$};
        \path (4,0) --+(260:3.3cm) node[red,rotate=170] {$p_{{\textstyle\mathstrut}(n\!\shortminus\!1)(n\!\shortminus\!1)}$};
        
        \draw[-{Stealth},shorten <=8pt, font=\footnotesize] (p8)  arc [start angle=-140, delta angle=-32]  (p0);
        \path[font=\bfseries\small] (4,0) --+(-160:1.6cm) node {R};
        \node[left of= p8, font=\bfseries\small] {adult};
        \node[right of= p0, font=\bfseries\small, xshift=-2mm] {egg};

        \draw[-{Stealth},shorten <=8pt, font=\footnotesize,dashed] (p5)  arc [start angle=-20, delta angle=-70]  (p7); % decorate,decoration={shape=circle, shape size=2mm, shape sep={5mm, between centers}}, doesn't work unfortunately
        
\end{tikzpicture}

现在的结果看起来几乎和提供的照片一样:

markov_chain_n_nodes

由于正常数学模式使用相当大的minus符号,因此我使用了答案短减号在节点中。要使用此答案,请将以下几行添加到序言中:

\usepackage{amssymb}  % provided it isn't loaded by another package
\DeclareMathSymbol{\shortminus}{\mathbin}{AMSa}{"39}

可以找到降低下标的选项这里

相关内容