Skip to content

Commit

Permalink
feat(graph.py): function only_directed_edge_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
this-is-sofia committed Oct 15, 2023
1 parent 2f3e158 commit 1fc72a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
5 changes: 5 additions & 0 deletions causy/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ def directed_edge_exists(self, u: Node, v: Node):
return False
return True

def only_directed_edge_exists(self, u: Node, v: Node):
if self.directed_edge_exists(u, v) and not self.directed_edge_exists(v, u):
return True
return False

def edge_value(self, u: Node, v: Node):
return self.edges[u][v]

Expand Down
28 changes: 14 additions & 14 deletions causy/orientation_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test(
# It cannot be a collider because we have already oriented all unshielded triples that contain colliders.
results = []
for z in potential_zs:
if graph.directed_edge_exists(x, z):
if graph.only_directed_edge_exists(x, z):
results.append(
TestResult(
x=y,
Expand All @@ -114,7 +114,7 @@ def test(
data={},
)
)
if graph.directed_edge_exists(y, z):
if graph.only_directed_edge_exists(y, z):
results.append(
TestResult(
x=x,
Expand Down Expand Up @@ -151,8 +151,8 @@ def test(
for z in potential_zs:
if (
graph.edge_exists(x, y)
and graph.directed_edge_exists(x, z)
and graph.directed_edge_exists(z, y)
and graph.only_directed_edge_exists(x, z)
and graph.only_directed_edge_exists(z, y)
):
results.append(
TestResult(
Expand All @@ -164,8 +164,8 @@ def test(
)
if (
graph.edge_exists(x, y)
and graph.directed_edge_exists(y, z)
and graph.directed_edge_exists(z, x)
and graph.only_directed_edge_exists(y, z)
and graph.only_directed_edge_exists(z, x)
):
results.append(
TestResult(
Expand Down Expand Up @@ -206,8 +206,8 @@ def test(
w = zs[1]
if (
not graph.edge_exists(x, y)
and graph.directed_edge_exists(x, z)
and graph.directed_edge_exists(y, z)
and graph.only_directed_edge_exists(x, z)
and graph.only_directed_edge_exists(y, z)
and graph.edge_exists(x, w)
and graph.edge_exists(y, w)
and graph.edge_exists(z, w)
Expand All @@ -222,8 +222,8 @@ def test(
)
if (
not graph.edge_exists(x, y)
and graph.directed_edge_exists(x, w)
and graph.directed_edge_exists(y, w)
and graph.only_directed_edge_exists(x, w)
and graph.only_directed_edge_exists(y, w)
and graph.edge_exists(x, z)
and graph.edge_exists(y, z)
and graph.edge_exists(z, w)
Expand Down Expand Up @@ -267,8 +267,8 @@ def test(
w = zs[1]
if (
not graph.edge_exists(x, y)
and graph.directed_edge_exists(x, z)
and graph.directed_edge_exists(z, y)
and graph.only_directed_edge_exists(x, z)
and graph.only_directed_edge_exists(z, y)
and graph.edge_exists(z, w)
and graph.edge_exists(x, z)
and graph.edge_exists(y, z)
Expand All @@ -283,8 +283,8 @@ def test(
)
if (
not graph.edge_exists(y, x)
and graph.directed_edge_exists(y, z)
and graph.directed_edge_exists(z, x)
and graph.only_directed_edge_exists(y, z)
and graph.only_directed_edge_exists(z, x)
and graph.edge_exists(z, w)
and graph.edge_exists(x, z)
and graph.edge_exists(y, z)
Expand Down

0 comments on commit 1fc72a7

Please sign in to comment.