Background knowledge not working
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 274
- PR merge metrics
- No merged PRs in 30d
Description
Hi! I have come across an issue where even when I forbid certain nodes when using PC, they still appear in my causal graph result:
from causallearn.utils.PCUtils.BackgroundKnowledge import BackgroundKnowledge
from causallearn.search.ConstraintBased.PC import pc
cg_without_background_knowledge = pc(X) # Run PC and obtain the estimated graph (CausalGraph object)
nodes = cg_without_background_knowledge.G.get_nodes()
bk = BackgroundKnowledge() \
.add_forbidden_by_node(nodes[0], nodes[1]) \
.add_forbidden_by_node(nodes[1], nodes[2]) \
.add_forbidden_by_node(nodes[0], nodes[2]) \
.add_forbidden_by_node(nodes[0], nodes[3]) \
.add_forbidden_by_node(nodes[1], nodes[3]) \
.add_forbidden_by_node(nodes[2], nodes[3])
cg_with_background_knowledge = pc(X, background_knowledge=bk)
assert cg_with_background_knowledge.G.get_edge(nodes[2], nodes[3]) is None
assert cg_with_background_knowledge.G.get_edge(nodes[0], nodes[1]) is None
I get this error, as well as an error for some other node combinations in my background knowledge:
AssertionError Traceback (most recent call last)
Cell In[9], line 18
15 cg_with_background_knowledge = pc(X, background_knowledge=bk)
17 assert cg_with_background_knowledge.G.get_edge(nodes[2], nodes[3]) is None
---> 18 assert cg_with_background_knowledge.G.get_edge(nodes[0], nodes[1]) is None
20 g, edges = fci(X, background_knowledge=bk)
22 sns.heatmap(g.graph, cmap='coolwarm', annot=True, xticklabels=node_names, yticklabels=node_names)AssertionError:
It seems like if the background knowledge is being used, it's being overriden somewhere. Please help! This also happens with FCI. I looked at the code and I can't figure out why this could be happening.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the assertions with the BackgroundKnowledge example, then trace how background_knowledge is passed through causallearn/search/ConstraintBased/PC.py and the FCI entry point. Check where forbidden node pairs are applied during graph construction and orienting; done means the reported forbidden edges are absent for both PC and FCI, with regression coverage for 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