Last active
April 3, 2021 03:59
-
-
Save junipertcy/b4cde5d9d6db4c7aa5a84ab3eec4a89d to your computer and use it in GitHub Desktop.
Figure 3.15 from Barber using daft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://docs.daft-pgm.org/en/latest/ | |
# pip install daft | |
# Figure 3.15: Belief network structure for the Chest Clinic example. | |
import daft | |
from matplotlib import rc | |
rc("font", family="serif", size=12) | |
rc("text", usetex=True) | |
pgm = daft.PGM() | |
pgm.add_node("a", r"$a$", 1, 5, aspect=1) | |
pgm.add_node("t", r"$t$", 1, 3, aspect=1) | |
pgm.add_edge("a", "t") | |
pgm.add_node("s", r"$s$", 4, 4, aspect=1) | |
pgm.add_node("l", r"$l$", 3, 3, aspect=1) | |
pgm.add_node("b", r"$b$", 5, 3, aspect=1) | |
pgm.add_edge("s", "l") | |
pgm.add_edge("s", "b") | |
pgm.add_node("e", r"$e$", 2, 2, aspect=1) | |
pgm.add_node("x", r"$x$", 1, 1, aspect=1) | |
pgm.add_node("d", r"$d$", 4, 1, aspect=1) | |
pgm.add_edge("t", "e") | |
pgm.add_edge("l", "e") | |
pgm.add_edge("b", "d") | |
pgm.add_edge("e", "x") | |
pgm.add_edge("e", "d") | |
# Render and save. | |
pgm.render(dpi=100) | |
pgm.savefig("chest_clinic.png", dpi=100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment