Example #1
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()
Example #2
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()
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()
Example #6
0
#pgm.add_node(Node('Transmission',r"$\phi(\lambda)$", 7, 7))
#pgm.add_node(Node('Counts',r"$\overline{f}_i$", 8, 5,scale=1.2,fixed=True,offset=(15,0)))
#pgm.add_node(Node('Counts_g',r"$\overline{f}_{gi}$", 8, 4,scale=1.2,fixed=True,offset=(10,-25)))
#pgm.add_node(Node('Zeropoints',r"${Z}$", 9, 7, observed=True))
pgm.add_node(Node('^Counts',r"${f_i}$", 4, 2, observed=True))

pgm.add_node(Node('Spars',r"${T}_{Si}$, ${z}_{Si}$", 4,1, scale=1.4,aspect=1.2, observed=True))
#pgm.add_node(Node('^Host',r"${z}_{Hi},{\theta}_{Hi}$", 7, 2, scale=1.5,observed=True))

#pgm.add_node(Node('Detected',r"Detected$_i$", 8, 3, fixed=True,offset=(-10,-20)))
#pgm.add_node(Node('^Type',r"$\tau_i$", 9, 2, fixed=True,offset=(10,-10)))

pgm.add_node(Node('Gals',r"$\theta_{G1}$, $\theta_{G2}$", 1,1, scale=1.4, aspect=1.2, observed=True))


pgm.add_edge("G_i","Gals")

pgm.add_edge("rate","Type")


pgm.add_edge("mu","HD")
#pgm.add_edge("^Counts","^Type")
#pgm.add_edge("Spars","^Type")
#pgm.add_edge("Host","Luminosity")


pgm.add_edge("G_i","HD")


# pgm.add_edge("Coords","G_i")
#pgm.add_edge("G_i","Host")
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_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()
Example #9
0
def pgm():
    from daft import PGM, Node, Plate
    from matplotlib import rc
    rc("font", family="serif", size=8)
    rc("text", usetex=True)

    pgm = PGM([9.5, 8.5], origin=[0., 0.2], observed_style='inner')

    #pgm.add_node(Node('dispersion',r"\center{$\sigma_{Ia}$ \newline $\sigma_{!Ia}$}", 1,6,scale=1.2,aspect=1.8))
    pgm.add_node(Node('Rate_Ia', r"{SNIa Rate}", 1, 8, fixed=1))
    pgm.add_node(Node('Rate_II', r"{SNII Rate}", 2, 8, scale=1.6, aspect=1.2))
    pgm.add_node(Node('L_Ia', r"{SNIa L, $\sigma_L$}", 3, 8, scale=1.6, aspect=1.2))
    pgm.add_node(Node('L_II', r"{SNII L, $\sigma_L$}", 4, 8, scale=1.6, aspect=1.2))
    pgm.add_node(Node('Cosmology', r"Cosmology", 7, 8, scale=1.6, aspect=1.2))
    pgm.add_node(Node('Calibration', r"Calibration", 8, 8, scale=1.6, aspect=1.2))

 #   pgm.add_node(Node('Neighbors',r"\centering{Neighbor \newline Redshifts}", 5,7, scale=1.6,aspect=1.2))
    pgm.add_node(Node('Redshift', r"{Redshift}", 6, 7, scale=1.6, aspect=1.2))

    pgm.add_node(Node('Type_prob', r"Type prob", 1, 6, fixed=1, offset=(20, -10)))
    pgm.add_node(Node('Distance', r"$L_D$", 7, 6, fixed=1, offset=(10, 10)))

    pgm.add_node(Node('Type', r"Type", 1, 5, scale=1.6, aspect=1.2))

    pgm.add_node(Node('Luminosity', r"Luminosity", 4, 4, scale=1.6, aspect=1.2))
    pgm.add_node(Node('Flux', r"Flux", 7, 3, scale=1.2, fixed=True, offset=(-20, -20)))


    pgm.add_node(Node('Obs_Type', r"Obs type", 1, 1, scale=1.6, aspect=1.2, observed=1))
    pgm.add_node(Node('Obs_Redshift', r"Obs redshift", 6, 1, scale=1.6, aspect=1.2, observed=1))
    pgm.add_node(Node('Counts', r"Counts", 8, 1, scale=1.2, observed=1))


    pgm.add_edge("Rate_Ia","Type_prob")
    pgm.add_edge("Rate_II","Type_prob")

    pgm.add_edge("Cosmology","Distance")
    pgm.add_edge("Redshift","Distance")

    pgm.add_edge("Type_prob", "Type")

    pgm.add_edge("Type","Luminosity")
    pgm.add_edge("L_Ia", "Luminosity")
    pgm.add_edge("L_II", "Luminosity")

    pgm.add_edge("Luminosity","Flux")
    pgm.add_edge("Redshift","Flux")
    pgm.add_edge("Distance","Flux")

    pgm.add_edge("Type","Obs_Type")
#    pgm.add_edge("Neighbors","Obs_Redshift")
    pgm.add_edge("Redshift","Obs_Redshift")

    pgm.add_edge("Flux","Counts")
    pgm.add_edge("Calibration","Counts")

    # Big Plate: Galaxy
    pgm.add_plate(Plate([0.4, 0.5, 8.2, 7.],
                        label=r"SNe $i = 1, \cdots, N_{SN}$",
                        shift=-0.2,label_offset=[20,2]))

    pgm.add_plate(Plate([0.5, 3.5, 4., 2.],
                        label=r"Type $\in \{Ia, II\}$",
                        shift=-0.2,label_offset=[20,2]))
    # Render and save.

    pgm.render()

    # pgm.figure.text(0.01,0.9,r'\underline{UNIVERSAL}',size='large')
    # pgm.figure.text(0.01,0.55,r'{\centering \underline{INDIVIDUAL} \newline \underline{SN}}',size='large')
    # pgm.figure.text(0.01,0.2,r'\underline{OBSERVATORY}',size='large')
    # pgm.figure.text(0.01,0.1,r'\underline{DATA}',size='large')


    pgm.figure.savefig("../results/nodes_pgm.pdf")
Example #10
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()
Example #11
0
#pgm.add_node(Node('z',r"$z_i$", 3, 3, fixed=True,offset=(-10,-5)))


pgm.add_node(Node('Flux',r"$f_i(t,\lambda)$", 6, 2, scale=1.2,fixed=True,offset=(20,5)))
#pgm.add_node(Node('Counts',r"$\overline{n}_i$", 7, 2,scale=1.2,fixed=True,offset=(-15,0)))
#pgm.add_node(Node('Counts_g',r"$\overline{\mathit{ADU}}_{gi}$", 8, 2,scale=1.2,fixed=True,offset=(20,0)))
#pgm.add_node(Node("Summary",r"$S({\mathit{ADU}_i})$", 9, 1, fixed=True, offset=(0,-25)))

pgm.add_node(Node('Stheta',r"${\theta}_{Si}$", 1, 1,  observed=True))
pgm.add_node(Node('ST',r"${T}_{Si}$", 2, 1, observed=True))
pgm.add_node(Node('Sz',r"${z}_{Si}$", 3, 1, observed=True))
pgm.add_node(Node('^Counts',r"${n_i}$", 7, 1, observed=True))


#pgm.add_edge("^Counts","Summary")
pgm.add_edge("G_i","Gals")
#pgm.add_edge("G_Ni","Gals")
pgm.add_edge("rate","Type")
#pgm.add_edge("Type", "theta_Ti")
pgm.add_edge("mu","HD")
pgm.add_edge("theta_T", "theta_Ti")
pgm.add_edge("G_i","HD")
pgm.add_edge("G_i","Sz")
pgm.add_edge("G_i","Luminosity")
pgm.add_edge("HD","Flux")
#pgm.add_edge("z","Flux")
#pgm.add_edge("G_Ni","Flux_g")
#pgm.add_edge("HD","Flux_g")
#pgm.add_edge("z","Flux_g")
pgm.add_edge("G_i","Type")
pgm.add_edge("G_i","theta_Ti")
Example #12
0
 def fully_connect(self, graph: PGM, layer1: List[Node],
                   layer2: List[Node]):
     for l1_node in layer1:
         for l2_node in layer2:
             graph.add_edge(l1_node.name, l2_node.name)
Example #13
0
pgm.add_node(Node('^Counts',r"$\hat{f_i}$", 2, 2, observed=True))
pgm.add_node(Node('^Host',r"$\hat{z_{Hi}},\hat{\theta}_{Hi}$", 3, 3, observed=True,scale=1.5))

pgm.add_node(Node('^mu',r"$\hat{\mu_i}$", 2, 1))

pgm.add_node(Node('SNpars_i',r"$\theta^{true}_i$", 2, 3))




pgm.add_node(Node('^Type',r"$\hat{T_i}$", 2, 4))




pgm.add_edge("^Type","SNpars_i")


pgm.add_edge("SNpars","SNpars_i")

pgm.add_edge("SNpars_i","^Counts")
pgm.add_edge("SNpars_i","Spars")
pgm.add_edge("SNpars_i","^Host")
pgm.add_edge("Pars","^Counts")
pgm.add_edge("^mu","^Counts")

pgm.add_edge("mu","^mu")
pgm.add_edge("^z","Spars")

#pgm.add_node(Node("t0true", r"$t_0^{\mathrm{true}}$", 7, 1))
Example #14
0
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))

# Big Plate: SNe
pgm.add_plate(
    Plate([1.5, 0.5, 4, 3.], label=r"SNe $i = 1, \cdots, N_{SN}$", shift=-0.1))

# Cosmological parameters
pgm.add_node(Node("cosmology", r"$\Omega$", 1, 2))

# nuisance parameters
pgm.add_node(Node("nuisance", r"$\alpha, \beta, x_{00}$", 0.7, 3, aspect=2.0))

# Add in the edges.
pgm.add_edge("x1dist", "x1itrue")
pgm.add_edge("cdist", "citrue")
pgm.add_edge("sigdist", "x0itrue")

pgm.add_edge("x1itrue", "x0itrue")
pgm.add_edge("citrue", "x0itrue")

pgm.add_edge("cosmology", "x0itrue")
pgm.add_edge("nuisance", "x0itrue")

pgm.add_edge("zi", "x0itrue")

pgm.add_edge("x0itrue", "fij")
pgm.add_edge("x1itrue", "fij")
pgm.add_edge("citrue", "fij")
pgm.add_edge("zi", "fij")
Example #15
0
pgm.add_node('bHat',
             content='b\'',
             observed=False,
             x=-2,
             y=3.2,
             alternate=True)
pgm.add_node('m', content='m', observed=False, x=-1.25, y=3.2, alternate=True)
pgm.add_node('xHat',
             content='x\'',
             observed=False,
             x=-.5,
             y=3.2,
             shape='rectangle')
pgm.add_node('x', content='x', observed=False, x=0, y=3.75)
pgm.add_node('sigma', content='sig_x', observed=False, x=-.9, y=3.95)
pgm.add_edge('sigma', 'xHat')
pgm.add_edge('a', 'B')
pgm.add_edge('x', 'B')
#TODO: add real boundary b
pgm.add_edge('bHat', 'a')
pgm.add_edge('m', 'a')
pgm.add_edge('xHat', 'a')
pgm.add_edge('x', 'xHat')
pgm.add_edge('p_omega', 'omega')
pgm.add_edge('omega', 'R')
pgm.add_edge('B', 'R')
pgm.add_edge('beta', 'f')
pgm.add_edge('f', 'R')
pgm.add_edge('f', 'tau')
pgm.add_edge('k', 'R')
pgm.add_edge('k', 'tau')