如何在贝叶斯网络中向节点添加自循环?

如何在贝叶斯网络中向节点添加自循环?

已经有很多问题询问如何在有限状态机类图中添加循环,但我找不到关于的具体答案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}

在此处输入图片描述

相关内容