FenTechSolutions / CausalDiscoveryToolbox

Package for causal inference in graphs and in the pairwise settings. Tools for graph structure recovery and dependencies are included.
https://fentechsolutions.github.io/CausalDiscoveryToolbox/html/index.html
MIT License
1.08k stars 198 forks source link

[BUG] orient_graph removes some of the edges #146

Open chhajer-rajul opened 1 year ago

chhajer-rajul commented 1 year ago

Describe the bug While applying Orient graph to orient a CPDAG, the procedure removes some of the edges present in the graph. I specifically used ANM object to call this procedure.

def orient_graph(self, df_data, graph, printout=None, **kwargs):

        if isinstance(graph, nx.DiGraph):
            edges = [a for a in list(graph.edges()) if (a[1], a[0]) in list(graph.edges())]
            oriented_edges = [a for a in list(graph.edges()) if (a[1], a[0]) not in list(graph.edges())]
       Output of edges variable: 

[('V2', 'V7'), ('V3', 'V7'), ('V7', 'V2'), ('V7', 'V3'), ('V7', 'V8'), ('V8', 'V7'), ('V8', 'V9'), ('V9', 'V8')]

// below code deletes the edges from the edge list which later would be used for orientation


            for a in edges:
                if (a[1], a[0]) in list(graph.edges()):
                    edges.remove(a)
            output = nx.DiGraph()
            for i in oriented_edges:
                output.add_edge(*i)
       Output of edges variable: 

[('V7', 'V3'), ('V9', 'V8')]

Not Sure why the algorithm deleting some of the un-oriented edges