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.12k stars 197 forks source link

[BUG] IAMB algorithm modifies input data #111

Open caph1993 opened 2 years ago

caph1993 commented 2 years ago

Describe the bug

The IAMB algorithm is modifying the input data when predict is called. It shouldn't.

I am running the following code in Python 3.8.10 with cdt 0.5.23, and 0 GPUs:

import networkx as nx
from cdt.causality.graph import IAMB
from cdt.data import load_dataset

data, graph = load_dataset("sachs")
print(data.columns)

for method in ['no-graph', 'digraph', 'undigraph']:
    print(f'Running {method}...')
    obj = IAMB()
    if method=='no-graph':
        output = obj.predict(data)
    elif method=='undigraph':
        output = obj.predict(data, nx.Graph(graph))
    elif method=='digraph':
        output = obj.predict(data, graph)
    else:
        raise Exception(method)
    print(data.columns)

The 'digraph' case modifies data.columns, and causes the subsequent case to raise an Exception. The code above prints:

No GPU automatically detected. Setting SETTINGS.GPU to 0, and SETTINGS.NJOBS to cpu_count.
Index(['praf', 'pmek', 'plcg', 'PIP2', 'PIP3', 'p44/42', 'pakts473', 'PKA',
       'PKC', 'P38', 'pjnk'],
      dtype='object')
Running no-graph...
Index(['praf', 'pmek', 'plcg', 'PIP2', 'PIP3', 'p44/42', 'pakts473', 'PKA',
       'PKC', 'P38', 'pjnk'],
      dtype='object')
Running digraph...
The algorithm is ran on the skeleton of the given graph.
Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], dtype='int64')
Running undigraph...

R Python Error Output 
-----------------------

[Errno 2] No such file or directory: '/tmp/cdt_bnlearn_e391065c-4c2e-4a03-bd58-28731f3aca79/result.csv'
... (long traceback) ...
diviyank commented 2 years ago

Hello ! Thanks for the feedback, I look into this !