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

How to transform the output of SAM #95

Closed ConnLiu closed 3 years ago

ConnLiu commented 3 years ago

Oh my I've just noticed your problem !

The fact is that SAM returns a confidence score for each edge of the graph ( even if it's close to 0). You would be able to see it with the adjacency matrix (networkx.adjacency_matrix(output).todense() i think). Therefore, it plots each edge as it is present in the graph (even if the associated weight is low.)

You must first proceed to threshold the confidence level of the graph before trying to plot it. From experience, thresholding to .6 or .7 leads to obtaining the best results.

Best, Diviyan

Hi, @Diviyan-Kalainathan Your algorithm is really awesome, and I am wondering about how you transform the output of SAM( the confidence score matrix) to a causal graph which is DAG. I have tried thresholding to .6 or .7, but it returns a bad result. As the picture shows below, there are only several edges but a loop.

image

Originally posted by @ConnLiu in https://github.com/FenTechSolutions/CausalDiscoveryToolbox/issues/65#issuecomment-811597438

diviyank commented 3 years ago

Hello @ConnLiu, Thank you for the kind words. If having a high threshold and still not obtaining a DAG, it means that the algorithm is not able to distinguish betwen the cause and the effect between these two variables; but thresholding so high and still obtaining no DAG might be strange:

Best regards, Diviyan

ConnLiu commented 3 years ago

Thanks for you detailed replies.

lr:0.01 dlr:0.001 mixed_data:False lambda1:10 lambda2:0.001 nh:10 dnh:10 train:2500 test:1000 batch_size:-1 dagstart:0.5 dagloss:True dagpenalization:0 dagpenalization_increase:0.01 losstype:fgan functionalComplexity:l2_norm sampletype:sigmoidproba linear:False numberHiddenLayersG:2 numberHiddenLayersD:2 njobs:10 gpus:0 verbose:False nruns:2

Best regards, Conn

ConnLiu commented 3 years ago

Oh my I've just noticed my problem! It is because the confusing figure, in which it look likes a cycle. But actually when I check it by codes[nx.find_cycle(ugraph)], it do not show a cycle.

Really thanks for your help, and sorry about my oversight!