causal-learn
causal-learn copied to clipboard
How to efficiently assign forbidden edges by nodes?
I currently use the following code to add forbidden edges, but it's taking so long when the adjacency matrix (in the example below named partial_order
) is large for adding background knowledge, is there any way to make this more efficient in the causal-learn
package?
import numpy as np
nodenames = final_df.columns
bk= BackgroundKnowledge()
position_matrix = np.argwhere(partial_order == 1)
for coordinate in position_matrix:
x, y = coordinate
node1 = nodenames[x]
node2 = nodenames[y]
bk.add_forbidden_by_node(GraphNode(node2), GraphNode(node1))
Hi, this improved version of BackGroundKnowledge might be helpful, which is proposed and implemented by @verae98. Also a related issue: #90
Not sure if the solution is 100% free of issues, but that could be great to try. Let me know if you have any better ideas, or would like to contribute perhaps by incorporating that solution :)