Ejemplo n.º 1
0
def coin_flip_pgm():
    G = PGM()
    G.add_node("alpha", content=r"$\alpha$", x=-1, y=1, scale=1.2, fixed=True)
    G.add_node("beta", content=r"$\beta$", x=1, y=1, scale=1.2, fixed=True)
    G.add_node("p", content="p", x=0, y=1, scale=1.2)
    G.add_node("result", content="result", x=0, y=0, scale=1.2, observed=True)
    G.add_edge("alpha", "p")
    G.add_edge("beta", "p")
    G.add_edge("p", "result")
    G.show()
def ice_cream_one_group_pgm():
    G = PGM()
    G.add_node("alpha", content=r"$\alpha$", x=-1, y=1, scale=1.2, fixed=True)
    G.add_node("beta", content=r"$\beta$", x=1, y=1, scale=1.2, fixed=True)

    G.add_node("p", content="p", x=0, y=1, scale=1.2)
    G.add_node("likes", content="l", x=0, y=0, scale=1.2, observed=True)
    G.add_edge("alpha", "p")
    G.add_edge("beta", "p")
    G.add_edge("p", "likes")
    G.show()
def ice_cream_n_group_pgm():
    G = PGM()
    G.add_node("alpha", content=r"$\alpha$", x=-1, y=1, scale=1.2, fixed=True)
    G.add_node("beta", content=r"$\beta$", x=1, y=1, scale=1.2, fixed=True)

    G.add_node("p", content=r"$p_{i}$", x=0, y=1, scale=1.2)
    G.add_node("likes", content=r"$l_{i}$", x=0, y=0, scale=1.2, observed=True)
    G.add_edge("alpha", "p")
    G.add_edge("beta", "p")
    G.add_edge("p", "likes")
    G.add_plate([-0.5, -0.8, 1, 2.3], label=r"shop $i$")
    G.show()
Ejemplo n.º 4
0
def korea_pgm():
    G = PGM()
    G.add_node("s_mean", r"$\mu_{s}$", x=0, y=1)
    G.add_node("s_scale", r"$\sigma_{s}$", x=1, y=1)
    G.add_node("s_height", r"$h_s$", x=0.5, y=0)
    G.add_edge("s_mean", "s_height")
    G.add_edge("s_scale", "s_height")

    G.add_node("n_mean", r"$\mu_{n}$", x=2, y=1)
    G.add_node("n_scale", r"$\sigma_{n}$", x=3, y=1)
    G.add_node("n_height", r"$h_n$", x=2.5, y=0)
    G.add_edge("n_mean", "n_height")
    G.add_edge("n_scale", "n_height")

    G.show()
def convoluted_hierarchical_p():
    G = PGM()
    G.add_node("likes",
               content="$l_{j, i}$",
               x=1,
               y=1,
               scale=1.2,
               observed=True)
    G.add_node("p_shop", content="$p_{j, i}$", x=1, y=2, scale=1.2)
    G.add_node("alpha_owner", content=r"$\alpha_{j}$", x=0, y=3, scale=1.2)
    G.add_node("beta_owner", content=r"$\beta_{j}$", x=2, y=3, scale=1.2)
    G.add_node("lambda_a_pop",
               content=r"$\lambda_{\alpha}$",
               x=0,
               y=4,
               scale=1.2)
    G.add_node("lambda_b_pop",
               content=r"$\lambda_{\beta}$",
               x=2,
               y=4,
               scale=1.2)
    G.add_node(
        "tau_lambda_a",
        content=r"$\tau_{\lambda_{\alpha}}$",
        x=0,
        y=5,
        fixed=True,
    )
    G.add_node(
        "tau_lambda_b",
        content=r"$\tau_{\lambda_{\beta}}$",
        x=2,
        y=5,
        fixed=True,
    )

    G.add_edge("alpha_owner", "p_shop")
    G.add_edge("beta_owner", "p_shop")
    G.add_edge("p_shop", "likes")
    G.add_edge("lambda_a_pop", "alpha_owner")
    G.add_edge("lambda_b_pop", "beta_owner")
    G.add_edge("tau_lambda_a", "lambda_a_pop")
    G.add_edge("tau_lambda_b", "lambda_b_pop")

    G.add_plate(plate=[0.5, 0.2, 1, 2.3], label=r"shop $i$")
    G.add_plate(plate=[-0.5, 0, 3, 3.5], label=r"owner $j$")
    G.render()
def hierarchical_p():
    """A naive representation of the hierarchical p that we desire."""
    G = PGM()
    G.add_node("p_shop", content=r"$p_{j, i}$", x=1, y=2, scale=1.2)
    G.add_node("likes",
               content="$l_{j, i}$",
               x=1,
               y=1,
               scale=1.2,
               observed=True)
    G.add_node("p_owner", content=r"$p_{j}$", x=1, y=3, scale=1.2)
    G.add_node("p_pop", content=r"$p$", x=1, y=4, scale=1.2)

    G.add_edge("p_pop", "p_owner")
    G.add_edge("p_owner", "p_shop")
    G.add_edge("p_shop", "likes")

    G.add_plate(plate=[0.3, 0.3, 1.5, 2.2], label=r"shop $i$")
    G.add_plate(plate=[0, -0.1, 2.1, 3.6], label=r"owner $j$")

    G.render()
def hierarchical_pgm():
    G = PGM()

    tfm_plot_params = {"ec": "red"}

    G.add_node("likes",
               content=r"$l_{j,i}$",
               x=0,
               y=0,
               scale=1.2,
               observed=True)
    G.add_node(
        "p_shop",
        content=r"$p_{j,i}$",
        x=0,
        y=1,
        scale=1.2,
        plot_params=tfm_plot_params,
    )
    G.add_node("mu_shop", content=r"$\mu_{j,i}$", x=1, y=1, scale=1.2)
    G.add_node("mu_owner", content=r"$\mu_{j}$", x=1, y=2, scale=1.2)
    G.add_node("sigma_owner", content=r"$\sigma_{j}$", x=2, y=2, scale=1.2)
    G.add_node(
        "p_owner",
        content=r"$p_{j}$",
        x=0,
        y=2,
        scale=1.2,
        plot_params=tfm_plot_params,
    )
    G.add_node("mu_population", content=r"$\mu$", x=1, y=3, scale=1.2)
    G.add_node(
        "sigma_population",
        content=r"$\sigma$",
        x=2,
        y=3,
        scale=1.2,
        fixed=True,
    )
    G.add_node(
        "p_population",
        content="p",
        x=0,
        y=3,
        scale=1.2,
        plot_params=tfm_plot_params,
    )
    G.add_node("lambda", content=r"$\lambda$", x=3, y=2, scale=1.2, fixed=True)
    G.add_node("mean_population",
               content="mean",
               x=1,
               y=4,
               scale=1.2,
               fixed=True)
    G.add_node(
        "variance_population",
        content="variance",
        x=2,
        y=4,
        scale=1.2,
        fixed=True,
    )

    G.add_edge("mu_shop", "p_shop")
    G.add_edge("p_shop", "likes")
    G.add_edge("mu_owner", "mu_shop")
    G.add_edge("sigma_owner", "mu_shop")
    G.add_edge("mu_owner", "p_owner")
    G.add_edge("mu_population", "mu_owner")
    G.add_edge("sigma_population", "mu_owner")
    G.add_edge("mu_population", "p_population")
    G.add_edge("lambda", "sigma_owner")
    G.add_edge("mean_population", "mu_population")
    G.add_edge("variance_population", "mu_population")

    G.add_plate([-0.5, -0.5, 2, 2], label="shop $i$", position="bottom right")
    G.add_plate([-0.7, -0.7, 3.2, 3.2],
                label="owner $j$",
                position="bottom right")

    G.render()
Ejemplo n.º 8
0
def car_crash_pgm():
    G = PGM()
    G.add_node("crashes", content="crashes", x=0, y=0, scale=1.5)
    G.add_node("rate", content="rate", x=0, y=1, scale=1.5)
    G.add_edge("rate", "crashes")
    G.show()
Ejemplo n.º 9
0
#!/usr/bin/env python

from matplotlib import rc
from daft import PGM, Node, Plate

rc("font", family="serif", size=12)
rc("text", usetex=True)

pgm = PGM([6, 4.2], origin=[0., 0.2], observed_style='inner')

# x_1 and c distributions on top line
pgm.add_node(Node("sigdist", r"$\sigma_{\mathrm{int}}^{\mathrm{dist}}$", 3, 4))
pgm.add_node(Node("x1dist", r"$x_1^{\mathrm{dist}}$", 4, 4))
pgm.add_node(Node("cdist", r"$c^{\mathrm{dist}}$", 5, 4))

# Per-SN parameters:  top line in the plate
pgm.add_node(Node("x1itrue", r"$x_{1,i}^\mathrm{true}$", 4, 3))
pgm.add_node(Node("citrue", r"$c_i^\mathrm{true}$", 5, 3))

# Per-SN parameters: second line in the plate
pgm.add_node(Node("x0itrue", r"$x_{0,i}^\mathrm{true}$", 3, 2))
#pgm.add_node(Node("mui", r"$\mu_i$", 2, 2))

# Per-SN parameters: third line in the plate
pgm.add_node(Node("zi", r"$z_i$", 2, 1, observed=True))

# Observed photometry
pgm.add_node(Node("fij", r"$f_{i,j}$", 4, 1, observed=True))

pgm.add_node(Node("t0true", r"$t_0^{\mathrm{true}}$", 5, 1))
Ejemplo n.º 10
0
from daft import PGM

pgm = PGM(directed=True)

pgm.add_node('G', content='G', observed=False, x=0, y=0)
pgm.add_node('rho', content='rho', observed=False, x=1, y=0, alternate=True)
pgm.add_node('R', content='R', observed=True, x=.25 + .75 / 2, y=1.2)
pgm.add_node('tau', content='tau', observed=True, x=1.5, y=.8)
pgm.add_node('f', content='f', observed=False, x=1.75, y=2, shape='rectangle')
pgm.add_node('beta',
             content='beta',
             observed=False,
             x=1.75,
             y=3,
             alternate=True)
pgm.add_node('ITI', content='ITI', observed=True, x=2.5, y=2)
pgm.add_node('k', content='k', observed=False, x=1, y=2, alternate=True)
pgm.add_node('B', content='B', observed=False, x=-0.5, y=2)
pgm.add_node('p_omega',
             content='Pom',
             observed=False,
             x=.25,
             y=3,
             alternate=True)
pgm.add_node('omega',
             content='om',
             observed=False,
             x=.25,
             y=2.25,
             shape='rectangle')
pgm.add_node('a', content='a', observed=False, x=-1.25, y=2.5)