Tikz를 사용하여 Markov 체인을 그리는 방법에 대한 질문

Tikz를 사용하여 Markov 체인을 그리는 방법에 대한 질문

저는 Tikz 패키지에 익숙하지 않습니다. 다음 코드는 동료의 기존 코드에서 수정되었습니다. 이것은 마르코프 체인 플롯입니다. 최선을 다했지만 구부러진 화살표는 주의 중심에서 시작하므로 주의 가장자리에서 시작했으면 합니다. 다른 방법이 있나요? 당신의 도움을 주셔서 감사합니다!

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}

%circle
\draw [thick] (-3.5,-1.6) circle [radius=0.6];
\draw [thick] (-0.9,-1.6) circle [radius=0.6];
\draw [thick] (1.7,-1.6) circle [radius=0.6];
\draw [thick] (6.8,-1.6) circle [radius=0.6];
\draw [thick] (9.4,-1.6) circle [radius=0.6];

%label state
\node (A) at (-3.5,-1.6) {1};
\node (B) at (-0.9,-1.6) {2};
\node (C) at (1.7,-1.6) {3};
\node (D) at (6.8,-1.6) {$m$};
\node (E) at (9.4,-1.6) {$m+1$};

%horizontal arrow
\draw [->, thick] (-2.9,-1.6) --(-1.5,-1.6);
\draw [->, thick] (-0.3,-1.6) --(1.1,-1.6);
\draw [->, thick] (2.3,-1.6) --(3.7,-1.6);
\draw [->, thick] (4.8,-1.6) --(6.2,-1.6);
\draw [->, thick] (7.4,-1.6) --(8.8,-1.6);


%dots
\draw [thick, dotted] (3.7,-1.6) -- (4.8,-1.6);



%parameters - horizontal arrow
\node [above] at (-2.2,-1.6) {{\footnotesize $x^{(m)}$}};
\node [above] at (0.4,-1.6) {{\footnotesize $D^{(m)}$}};
\node [above] at (3,-1.6) {{\footnotesize $D^{(m-1)}$}};
\node [above] at (5.5,-1.6) {{\footnotesize $D^{(3)}$}};
\node [above] at (8.1,-1.6) {{\footnotesize $D^{(2)}$}};

%vertical arrow
\draw [->, thick] (-3.5,1) --(-3.5,-1);

%bending arrow
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(C);
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(D);
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(E);

\node [right] at (-3.5,0) {{\footnotesize $\displaystyle \pi_1$}};
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

답변1

노드가 아닌 원을 그렸기 때문입니다.케이Z는 국경에 화살표를 긋기 시작해야 한다는 사실을 모릅니다. 노드에 최소 크기와 모양(여기서는 원)을 지정하고 Ti에게 알려주는 것이 좋습니다.케이Z로 그려보세요.

마르코프 체인

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}[mystate/.style={draw,circle,minimum size=1.2cm}]

%circle
%\draw [thick] (-3.5,-1.6) circle [radius=0.6];
%\draw [thick] (-0.9,-1.6) circle [radius=0.6];
%\draw [thick] (1.7,-1.6) circle [radius=0.6];
%\draw [thick] (6.8,-1.6) circle [radius=0.6];
%\draw [thick] (9.4,-1.6) circle [radius=0.6];

%label state
\node[mystate] (A) at (-3.5,-1.6) {1};
\node[mystate] (B) at (-0.9,-1.6) {2};
\node[mystate] (C) at (1.7,-1.6) {3};
\node[minimum size=1.2cm] (C')at (4.25,-1.6){};
\node[mystate] (D) at (6.8,-1.6) {$m$};
\node[mystate] (E) at (9.4,-1.6) {$m+1$};

%horizontal arrow
\draw [->, thick] (A) -- (B) node[midway, above] {\footnotesize $x^{(m)}$};
\draw [->, thick] (B) -- (C) node[midway, above] {\footnotesize $D^{(m)}$};
\draw [->, thick] (C) -- (C') node[midway, above] {\footnotesize $D^{(m-1)}$};
\draw [->, thick] (C') -- (D) node[midway, above] {\footnotesize $D^{(3)}$};
\draw [->, thick] (D) -- (E) node[midway, above] {\footnotesize $D^{(2)}$};


%dots
\draw [thick, dotted] (3.7,-1.6) -- (4.8,-1.6);



%vertical arrow
\draw [->, thick] (-3.5,1) --(-3.5,-1);

%bending arrow
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(C);
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(D);
\draw[->, thick] (A)  to [out=60,in=120, looseness=1]
(E);

\node [right] at (-3.5,0) {{\footnotesize $\displaystyle \pi_1$}};
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

솔직히 말해서 이것은 이런 종류의 그래프를 그리는 가장 좋은 방법은 아닙니다. 라이브러리 를 사용하여 hox를 사용 chains하고 그리는 방법을 배워야 합니다 . Ti에 익숙하지 않기 때문에 코드를 너무 많이 수정하지 않았습니다.edgesquotes케이Z, 하지만 이 사이트에서는 Markov 체인의 훌륭한 예를 많이 찾을 수 있습니다.

답변2

여기 당신을 위한 제안이 있습니다.

여기에 이미지 설명을 입력하세요

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{center}
\begin{tikzpicture}
\def\a{2.5} 
\path[nodes={circle,draw,minimum size=12mm}]
   (0,0) node (1) {$1$}
++(\a,0) node (2) {$2$}
++(\a,0) node (3) {$3$}
;
\draw[<-] (1)--+(90:2) node[midway,right]{$\pi_1$};
\draw[->] (1)--(2) node[midway,above]{$x^{(m)}$}; 
\draw[->] (2)--(3) node[midway,above]{$D^{(m)}$};
\draw[->] (1) to[out=60,in=120] (3);
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}

관련 정보