Skip to content

Wrong v-structure orientations with background knowledge #224

@Matyasch

Description

@Matyasch

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions