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 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()
Ejemplo n.º 4
0

#pgm.add_edge("Transmission","Counts")
#pgm.add_edge("Transmission","Counts_g")
#pgm.add_edge("Transmission","Zeropoints")

pgm.add_edge("Type","Spars")
pgm.add_edge("G_i","Spars")

#pgm.add_edge("Counts_g","^Counts")


#pgm.add_edge("Detected","^Counts")




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


# Render and save.
pgm.render()
# pgm.figure.text(0.2,0.98,r'\underline{UNIVERSE}',size='large')
# pgm.figure.text(0.45,0.98,r'\underline{OBSERVATORY}',size='large')
# pgm.figure.text(0.72,0.98,r'\underline{DATA}',size='large')

pgm.figure.savefig("../results/toy_pgm.pdf")
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.º 6
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")
Ejemplo n.º 7
0
pgm.add_edge("G_i","Type")
pgm.add_edge("G_i","theta_Ti")
pgm.add_edge("Type","Luminosity")
pgm.add_edge("Luminosity","Flux")
pgm.add_edge("Type","Stheta")
pgm.add_edge("theta_T","Luminosity")
pgm.add_edge("theta_Ti","Luminosity")
pgm.add_edge("Flux","^Counts")
#pgm.add_edge("Flux_g","Counts_g")
#pgm.add_edge("Counts","^Counts")
#pgm.add_edge("Counts_g","^Counts")
pgm.add_edge("Transmission","^Counts")
#pgm.add_edge("Transmission","Counts_g")
pgm.add_edge("Type","ST")
pgm.add_edge("theta_Ti","Stheta")
#pgm.add_edge("Counts_g","^Counts")

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


# Render and save.
pgm.render()
# pgm.figure.text(0.2,0.98,r'\underline{UNIVERSE}',size='large')
# pgm.figure.text(0.45,0.98,r'\underline{OBSERVATORY}',size='large')
# pgm.figure.text(0.72,0.98,r'\underline{DATA}',size='large')

pgm.figure.savefig("../results/hdpgm.pdf")
Ejemplo n.º 8
0
Archivo: pgm.py Proyecto: Samreay/abc
# pgm.add_edge("Type","Stheta")
pgm.add_edge("theta_T", "Luminosity")
# pgm.add_edge("theta_Ti","Luminosity")
pgm.add_edge("Flux", "^Counts")
# pgm.add_edge("Flux_g","Counts_g")
# pgm.add_edge("Counts","^Counts")
# pgm.add_edge("Counts_g","^Counts")
pgm.add_edge("Global Transmission", "Transmission")
pgm.add_edge("Transmission", "^Counts")
# pgm.add_edge("Transmission","Counts_g")
pgm.add_edge("Type", "ST")
# pgm.add_edge("theta_Ti","Stheta")
# pgm.add_edge("Counts_g","^Counts")

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


pgm.add_plate(
    Plate(
        [4.5, 0.6, 4, 4.0],
        label=r"{\centering LC Point $j = 1, \cdots, N_{band}$, $k = 1, \cdots, N_{date}$}",
        shift=-0.2,
        label_offset=[2, 2],
    )
)


# Render and save.
pgm.render()
pgm.figure.text(0.01, 0.9, r"\underline{UNIVERSAL}", size="large")
Ejemplo n.º 9
0
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))

# 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")