py-why / py-why/causal-learn

Wrong v-structure orientations with background knowledge

Open
#224 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
274
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal example through the pc entry point and inspect how BackgroundKnowledge is applied during orientation. Compare the graph outputs with and without the forbidden X–Z edges, then trace the orientation steps that produce the v-structure. Done means the forbidden-edge knowledge does not create an orientation absent from the expected DAG/CPDAG, with a regression test covering the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.