Closed WilliamsToTo closed 5 months ago
I don't think there is an existing function to save the CausalGraph object, but perhaps you could try to save the adjacency matrix of the graph (cg.G.graph), which is a numpy array so np.save( ) works.
What about using the pickle module, so you save a binary representation? I didn't test it but it should work.
@WilliamsToTo try this it works for me
from causallearn.search.ConstraintBased.PC import pc
import pickle
# default parameters
cg = pc(data)
print(len(cg.G.nodes))
with open('myG.pkl', 'wb') as f:
pickle.dump(cg.G, f, pickle.HIGHEST_PROTOCOL)
with open('myG.pkl', 'rb') as f:
myG = pickle.load(f)
print(len(myG.nodes))
@priamai Thanks a lot.
Hey, just wanna know how to save and reload the CausalGraph return by PC algorithm.