Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typos import DAG_GNN, missing packages and ‘pcalg' problem #333

Open
Mathugo opened this issue Sep 19, 2024 · 0 comments
Open

Typos import DAG_GNN, missing packages and ‘pcalg' problem #333

Mathugo opened this issue Sep 19, 2024 · 0 comments

Comments

@Mathugo
Copy link

Mathugo commented Sep 19, 2024

Hi Thibault, I noticed while I was trying to run your code: train_eval.ipynb that:

  • from DCGL.model import DAG_GNN in train_eval.ipynb should be instead from DCGL.model import DAG_GCN, which causes an Import failure

Moreoever,
While executing the code for the Event Sequence and their associated model, in particular lines:

columns, event_table, ground_trues = DataLoader(name= "Microwave24V").data()
if data != "Wireless":
    new_event_table = event_table.loc[:, ["event_type", "time_stamp"]]
else:
    new_event_table = event_table
device = torch.device("cuda:0")

model = ADM4(device, len(columns), graph_threshold=0.05, max_iter=5, em_max_iter=5, rho=0.2, decay=1)
model = model.to(device)
model.fit(new_event_table, columns)
_SHD = model._eval(ground_trues, metric="SHD-C")
_SED = model._eval(ground_trues, metric="CSD")
_SID = model._eval(ground_trues, metric="SID")
_CED = model._eval(ground_trues, metric="CED")
print(f"ADM4, SHD:{_SHD}, SED:{_SED}, SID:{_SID}, CED:{_CED}")
    
model = RPPN(device, len(columns), init_scale=2, embedding_dim=64, hidden_size=64, graph_threshold=0.01, batch_size=64)
model = model.to(device)
model.fit(new_event_table, columns, epochs=20, num_workers=0, save_path="./", split_ratio=0.4   )
_SHD = model._eval(ground_trues, metric="SHD-C")
_SED = model._eval(ground_trues, metric="CSD")
_SID = model._eval(ground_trues, metric="SID")
_CED = model._eval(ground_trues, metric="CED")
print(f"RPPN, SHD:{_SHD}, SED:{_SED}, SID:{_SID}, CED:{_CED}")
    
model = SHP(device, len(columns), decay=3, time_interval=5, seed=42, reg=3, penalty="BIC")
model.fit(new_event_table, columns, threshold=0.9)
_SHD = model._eval(ground_trues, metric="SHD-C")
_SED = model._eval(ground_trues, metric="CSD")
_SID = model._eval(ground_trues, metric="SID")
_CED = model._eval(ground_trues, metric="CED")
print(f"SHP, SHD:{_SHD}, SED:{_SED}, SID:{_SID}, CED:{_CED}")

if data == "Wireless":
    node = [columns.index(event) for event in event_table["event_type"]]
    event = list(event_table["event_type"])
    timestamp = list(event_table["time_stamp"])
    event_dict = {"event": event,
                  "timestamp": timestamp,
                  "node": node}
    topology_matrix = np.mat(np.eye(len(node), dtype=int))
    max_hop = 0
else:
    node = list(event_table["node"])
    event = list(event_table["event_type"])
    timestamp = list(event_table["time_stamp"])
    event_dict = {"event": event,
                  "timestamp": timestamp,
                  "node": node}
    topology_matrix = np.load(f"./DCGL/data/dataset/{data}/Topology.npy")
    max_hop = 2
new_event_table = pd.DataFrame(event_dict)
model = TTPM(topology_matrix=topology_matrix, max_hop=max_hop)
model.learn(new_event_table)
causal_matrix = model.causal_matrix
_SHD = SHD_CPDAG(ground_trues, causal_matrix)
_SED = CSD(ground_trues, causal_matrix)
_SID = SID(ground_trues, causal_matrix)
_CED = CED(ground_trues, causal_matrix, ground_trues.shape[0])
print(f"THP, SHD:{_SHD}, SED:{_SED}, SID:{_SID}, CED:{_CED}")

of train_eval.ipynb, I'm stumbling upon an R package error:

 model._eval(ground_trues, metric="SHD-C")
     17 _SED = model._eval(ground_trues, metric="CSD")
     18 _SID = model._eval(ground_trues, metric="SID")

File ~/SageMaker/DOSEC/notebooks/research_pretraining/OCDB/model/BaseModel.py:33, in BaseModel._eval(self, ground_trues, metric)
     31     return SID(ground_trues, self.DAG)
     32 elif metric == "SHD-C":
---> 33     return SHD_CPDAG(ground_trues, self.DAG)
     34 elif metric == "CED":
     35     return CED(ground_trues, self.DAG, k=ground_trues.shape[0])

File ~/SageMaker/DOSEC/notebooks/research_pretraining/OCDB/metrics/Metrics.py:116, in SHD_CPDAG(G_true, G_pred)
    115 def SHD_CPDAG(G_true, G_pred):
--> 116     return cm.SHD_CPDAG(G_true, G_pred)

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/cdt/metrics.py:185, in SHD_CPDAG(target, pred)
    181 true_labels = retrieve_adjacency_matrix(target)
    182 predictions = retrieve_adjacency_matrix(pred, target.nodes()
    183                                         if isinstance(target, nx.DiGraph) else None)
--> 185 true_labels = get_CPDAG(true_labels)
    186 predictions = get_CPDAG(predictions)
    188 return SHD(true_labels, predictions, False)

File ~/anaconda3/envs/python3/lib/python3.10/site-packages/cdt/metrics.py:131, in get_CPDAG(dag)
    116 R"""Compute the completed partially directed acyclic graph (CPDAG) of
    117 a given DAG
    118 
   (...)
    128 
    129 """
    130 if not RPackages.pcalg:
--> 131     raise ImportError("pcalg R package is not available. Please check your installation.")
    133 dag = retrieve_adjacency_matrix(dag)
    135 base_dir = Path('{0!s}/cdt_CPDAG_{1!s}'.format(gettempdir(), uuid.uuid4()))

ImportError: pcalg R package is not available. Please check your installation.

Which triggered a question ro me as why does this repo need a package that was added to R in early september 2024 (pcalg) whereas the paper came out on arxiv in June ? Do we really need this package in order to run the script ? If we need R, could you detail your overall installation and R version ?

Also wget and torch_geometric seems to be mandatory dependecies (I got errors or missing packages)

_My version:
Python 3.10.14
gcastle==1.0.3
cdt==0.6.0
wget==3.2
torch==2.4.1
torch-geometric==2.6.0

Merci pour le repo,
Best,
Hugo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant