我想在下图中添加一条将 beta 链接到 beta 的边:
使用DAFT生成以下代码:
from matplotlib import rc
rc("font", family="serif", size=12)
rc("text", usetex=True)
import daft
pgm = daft.PGM([2.3, 3.05], origin=[0.3, 0.3], observed_style="inner")
# Hierarchical parameters.
pgm.add_node(daft.Node("beta", r"$\beta$", 1.5, 2))
# Latent variable.
pgm.add_node(daft.Node("w", r"$w_n$", 1, 1))
# Data.
pgm.add_node(daft.Node("x", r"$x_n$", 2, 1, observed=True))
# Add in the edges.
pgm.add_edge("beta", "beta") # Attempting to create a self-edge, but no effect!
pgm.add_edge("w", "x")
pgm.add_edge("w", "w")
pgm.add_edge("w", "beta")
pgm.add_edge("beta", "x")
# Render and save.
pgm.render()
pgm.figure.savefig("nogray.pdf")
但为什么它不起作用?尤其是这条线pgm.add_edge("beta", "beta")
。我欢迎 Daft 以外的其他建议,只要它在 Python 下。