causal-learn icon indicating copy to clipboard operation
causal-learn copied to clipboard

how to visualize the FCM based approaches

Open priamai opened this issue 2 years ago • 3 comments

Hi there, I noticed that the FCM methods don't produce a Graph object.

from causallearn.search.FCMBased import lingam
model = lingam.DirectLiNGAM(random_state=None, prior_knowledge=None, apply_prior_knowledge_softly=False, measure='pwling')
model.fit(dataset)

print(model.causal_order_)
print(model.adjacency_matrix_)

Why they are not following the other approach like in Constrained based and in Score Based? Cheers.

priamai avatar Oct 30 '23 10:10 priamai

Yea you are right, at least for these LiNGAM-based methods we could definitely visualize them in a similar way as follows:

from causallearn.search.FCMBased import lingam
model = lingam.ICALiNGAM()
model.fit(data)

from causallearn.search.FCMBased.lingam.utils import make_dot
make_dot(model.adjacency_matrix_, labels=labels)

We will include these usages into the doc, and preferably make the visualization way consistent with other methods. For ANM or PNL, the multivariate version could be a little bit more tricky, see e.g. https://proceedings.mlr.press/v177/uemura22a/uemura22a.pdf.

kunwuz avatar Nov 03 '23 16:11 kunwuz

Hello, that worked: https://colab.research.google.com/drive/1BZ2idQWgr7Ed6d09fk9bYi4a5RoOiu3g?usp=sharing is there a way to save it into a file?

priamai avatar Nov 16 '23 07:11 priamai

Quick solution

from causallearn.search.FCMBased.lingam.utils import make_dot
my_dot = make_dot(model.adjacency_matrix_,labels=df.columns.to_list())
my_dot.filename="test"
my_dot.name="test"
my_dot.render(format='png')
my_dot.save(filename="test.dot")

maybe add to the docs.

priamai avatar Nov 16 '23 10:11 priamai