
유한 상태 기계와 같은 플롯에 루프를 추가하는 방법에 대해 이미 많은 질문이 있었지만 bayesnet
. 누군가가 의 노드에 자체 루프를 추가하는 방법을 말해 줄 수 있습니까 bayesnet
?
이 같은: Tikz에서 자체 루프를 그리고 그래프 가장자리에 레이블을 지정하려면 어떻게 해야 하나요?
편집: 샘플 코드를 추가했습니다. 한 가지 문제는 루프와 플레이트의 하단 텍스트가 모두 플레이트에 맞지 않는다는 것입니다.
\begin{figure}
\centering
\tikz{
\node[latent] (b_t) {$b_t$} ;
\node[latent, right=of b_t] (t_t)
{$t_t$} ;
\node[obs, right=of t_t] (o_t) {$o_t$} ;
% \edge {b_t} {b_t} ;
\edge {b_t} {t_t} ;
\edge {t_t} {o_t} ;
\path (b_t) edge [loop above] (b_t);
\plate[inner sep=0.225cm, yshift=.25cm] {plate1} {(b_t) (t_t) (o_t) (b_t')} {T}; %
}
\end{figure}
답변1
루프는 평소대로 작동합니다. 방금 복사했어요무작위 예루프를 추가했습니다.
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,bending}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{tikzpicture}[>={Stealth[bend]}]
% nodes
\node[obs] (x) {$x$};%
\node[latent,above=of x,xshift=-1cm,path picture={\fill[gray!25] (path picture bounding box.south) rectangle (path picture bounding box.north west);}]
(y) {$y$}; %
\node[latent,above=of x,xshift=1cm] (z) {$z$}; %
\path (z) edge [loop above] node (z') {$Z$} (z);
% plate
\plate[inner sep=.25cm,yshift=.2cm,transform shape=false]{plate1}{(x)(y)(z)(z')}{$N$}; %
% edges
\edge {y,z} {x}
\end{tikzpicture}
\end{document}
부록: 업데이트의 코드는 맞춤에 대한 보조 좌표를 추가하세요.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\node[latent] (b_t) {$b_t$} ;
\node[latent, right=of b_t] (t_t)
{$t_t$} ;
\node[obs, right=of t_t] (o_t) {$o_t$} ;
% \edge {b_t} {b_t} ;
\edge {b_t} {t_t} ;
\edge {t_t} {o_t} ;
\path (b_t) edge [loop above] coordinate[midway](aux) (b_t);
\plate[inner sep=0.225cm] {plate1}
{(b_t) (t_t) (o_t) (aux)} {T}; %
\end{tikzpicture}
\caption{Adding an auxiliary coordinate.}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{scope}[local bounding box=pft]
\node[latent] (b_t) {$b_t$} ;
\node[latent, right=of b_t] (t_t)
{$t_t$} ;
\node[obs, right=of t_t] (o_t) {$o_t$} ;
% \edge {b_t} {b_t} ;
\edge {b_t} {t_t} ;
\edge {t_t} {o_t} ;
\path (b_t) edge [loop above] (b_t);
\end{scope}
\plate[inner sep=0.225cm] {plate1} {(pft)} {T}; %
\end{tikzpicture}
\caption{Using a \texttt{local bounding box} node. (Note that this will probably improve
at a given point when the \texttt{bbox} library gets improved. Currently
development is frozen.)}
\end{figure}
\end{document}