PC learns different graphs dependent on the ordering
@chenweiDelight is already working on this.
Since Oct 24, 2022.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 274
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
Thank you for your great work on this package!
I am testing the behaviour of the PC algorithm on simple simulated data. I found that the number of directed edges detected differs based on the ordering of the variables given to the algorithm.
I am running the following code:
import numpy as np
import matplotlib.pyplot as plt
from causallearn.search.ConstraintBased.PC import pc
def simulate_data(n_obs):
'''
Simulate data from the following graph
A B
\ /
v v
C
/ \
v v
D E
'''
A = np.random.normal(size = n_obs)
B = np.random.normal(size = n_obs)
C = A + B + np.random.normal(size = n_obs)*0.25
D = C + np.random.normal(size = n_obs)*0.25
E = C + np.random.normal(size = n_obs)*0.25
return np.stack((A,B,C,D,E), axis =1)
# generate data
n = 10000
data = simulate_data(n)
# test different permutations
permutations = [[0,1,2,3,4], [0,1,3,2,4]]
for permutation in permutations:
graph = pc(data[:,permutation], 0.05, 'fisherz', node_names = np.array(["A","B", "C", "D", "E"])[permutation], verbose = False)
graph.draw_pydot_graph(labels=np.array(["A","B", "C", "D", "E"])[permutation])
plt.show()
When the ordering of variables C and D is permuted, the PC algorithm returns the Graph with an undirected edge from C to D. However, when the ordering is unpermuted, the PC algorithm correctly directs the edge from C to D. This happens, even though the p-values in the CI tests are unchanged for the two permutations.
Is this expected behaviour or can you help me fix this?
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.
Assessment
This issue has not been assessed yet.