Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong v-structure orientations with background knowledge #224

Open
Matyasch opened this issue Mar 3, 2025 · 0 comments
Open

Wrong v-structure orientations with background knowledge #224

Matyasch opened this issue Mar 3, 2025 · 0 comments

Comments

@Matyasch
Copy link

Matyasch commented Mar 3, 2025

Hi! I would like to add background knowledge to the pc algorithm using the BackgroundKnowledge class. However, I noticed that some v-structures are orientated wrongly when using it. I provide a minimal example below, where background knowledge about a forbidden edge makes pc orient a v-structure that does not exist in the true DAG/CPDAG:

from causallearn.search.ConstraintBased.PC import pc
from causallearn.utils.PCUtils.BackgroundKnowledge import BackgroundKnowledge
import networkx as nx
import numpy as np

# True DAG is X -> Y -> Z, true CPDAG is X - Y - Z
dag = nx.DiGraph()
dag.add_edge(0, 1)
dag.add_edge(1, 2)

# Run PC without background knowledge
cg_without_background_knowledge = pc(np.zeros((1,3)), 0.05, "d_separation", true_dag=dag)

nodes = cg_without_background_knowledge.G.get_nodes()
# Passes because output is X - Y - Z
assert cg_without_background_knowledge.G.is_undirected_from_to(nodes[0], nodes[1])
# Passes because output is X - Y - Z
assert cg_without_background_knowledge.G.is_undirected_from_to(nodes[1], nodes[2])

# Run PC with background knowledge of forbidden edge between X and Z
bk = BackgroundKnowledge().add_forbidden_by_node(nodes[0], nodes[2]).add_forbidden_by_node(nodes[2], nodes[0])
cg_with_background_knowledge = pc(np.zeros((1,3)), 0.05, "d_separation", true_dag=dag, background_knowledge=bk)

nodes = cg_with_background_knowledge.G.get_nodes()
# Fails because output is X -> Y <- Z
assert cg_with_background_knowledge.G.is_undirected_from_to(nodes[0], nodes[1])
# Fails because output is X -> Y <- Z
assert cg_with_background_knowledge.G.is_undirected_from_to(nodes[1], nodes[2])

I would be very happy to hear some inputs from you on how to use BackgroundKnowledge in pc while ensuring that such erroneous orientations do not arise. Note, that my question is different from #171 and #219, as my issue is about orientations rather than the skeleton search. Thank you for your effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant