Skip to content

Commit

Permalink
Added sections
Browse files Browse the repository at this point in the history
Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
  • Loading branch information
aryan26roy committed Jun 22, 2023
1 parent 18596ef commit 0f8d15b
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions examples/intro/inducing_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
from pywhy_graphs import PAG
from pywhy_graphs.viz import draw

# construct the causal graph from figure 2 of
# https://arxiv.org/pdf/1104.5617.pdf
# %%
# The Graph
# ----------------------------------------------
# To illustrate the workings of the inducing path algorithm, we will
# construct the causal graph from figure 2 of https://arxiv.org/pdf/1104.5617.pdf.


G = PAG()
G.add_edge("X4", "X1", G.directed_edge_name)
Expand All @@ -43,18 +47,27 @@
dot_graph = draw(G)
dot_graph.render(outfile="pag.png", view=True)

# All adjacent nodes have a trivial inducing path
# which is the edge between them

# %%
# Inducing Path Between Adjacent Nodes
# ----------------------------------------------
# By definition, all adjacent nodes have a trivial inducing path between them,
# that path only consists of one edge, which is the edge between those two nodes.

L = {}
S = {}

# All such tests will return True.
print(pywhy_graphs.inducing_path(G, "X1", "X4", L, S))
print(pywhy_graphs.inducing_path(G, "X3", "X2", L, S))

# %%
# Inducing Path Two Arbitrary Nodes
# ----------------------------------------------
# Given the definition of an inducing path, we need to satisfy all
# requirements for the function to return True. Adding the latent
# variables to L is not enough for the pair [X1,X5]

# Including all the 'L' nodes is not enough to
# open up an inducing path between X1 and X5
L = {"L1", "L2"}
S = {}

Expand All @@ -73,6 +86,14 @@
# now it returns True
print(pywhy_graphs.inducing_path(G, "X1", "X5", L, S))


# %%
# The Role of Colliders
# ----------------------------------------------
# Adding Colliders to the set S has a downstream effect.
# Since adding the collider opens up all the inducing paths containing
# the collider ancestors of that node.

# Even now, some inducing paths are not opened.
# For example, the path between X1 and X3 is not available

Expand All @@ -81,6 +102,7 @@

# We need to add X6, which will open up paths
# including all the collider ancestors of X6
# in this case that node is X2.

L = {"L1", "L2", "X3"}
S = {"X6"}
Expand Down

0 comments on commit 0f8d15b

Please sign in to comment.