dfm/daft — pull request #56 by justinkamerman (2013-03-08 21:11:49+00:00)
Title: Added edge annotations

I know it's not strictly speaking part of the PGM notation but I added edge notations so I could use Daft for some other stuff too. Text offset is hard coded so might not resize well. It was a bit beyond my Matplotlib skills to figure this out....

from matplotlib import rc
rc("font", family="serif", size=20)
rc("text", usetex=True)

import daft

pgm = daft.PGM([6.0, 5.0], grid_unit=4, node_unit=2, line_width=1.5, origin=[0.5, 0])

# Nodes
pgm.add_node(daft.Node("i", r"$i$", 1.0, 3))

pgm.add_node(daft.Node("i2", r"$i$", 3, 4))
pgm.add_node(daft.Node("j", r"$j$", 3, 3))
pgm.add_node(daft.Node("k", r"$k$", 3, 2))

pgm.add_node(daft.Node("j2", r"$j$", 5, 3))

# Edges
pgm.add_edge("i", "i2", label=r"$p_{ii}^{(t)}$")
pgm.add_edge("i", "j", label=r"$p_{ij}^{(t)}$")
pgm.add_edge("i", "k", label=r"$p_{ik}^{(t)}$")
pgm.add_edge("i2", "j2", label=r"$p_{ij}^{(t+1)}$")
pgm.add_edge("j", "j2", label=r"$p_{jj}^{(t+1)}$")
pgm.add_edge("k", "j2", label=r"$p_{kj}^{(t+1)}$")

# Plates
pgm.add_plate(daft.Plate([0.5, 1.5, 1, 3], label=r"$t$", label_offset=[0.5, 0.5], shift=-0.1))
pgm.add_plate(daft.Plate([2.5, 1.5, 1, 3], label=r"$t+1$", label_offset=[0.5, 0.5], shift=-0.1))
pgm.add_plate(daft.Plate([4.5, 1.5, 1, 3], label=r"$t+2$", label_offset=[0.5, 0.5], shift=-0.1))

# Render
pgm.render()

![daft_edges](https://f.cloud.github.com/assets/771107/238366/aa1aaeaa-8834-11e2-86c1-9fbe1d09a117.png)