You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use the functionality of attributing anomalies of a node to its parents and ancestors in GCM for root cause analysis. Sometimes, I need to add a new node to the graph and some edges between the new node and existing nodes. I would then like to learn the causal mechanism for the nodes affected by the change.
I have tried the following. I have an exiting causal graph and the associated causal model that has been learned. I modified the causal graph by adding the new node and associated new edges. I created a new causal model from the modified causal graph. I would like to copy the learned causal mechanisms in the existing causal model to the new causal model. Afterwards, I would learn the causal mechanisms on the nodes affected by the change in the causal graph.
But when I tried to assign the learned causal mechanism in the existing causal model to the new causal model, I received an error that said I couldn't do this assignment.
Is it possible to incrementally change the causal graph and learn the causal function only on the nodes affected? I looked up the documentation of DoWhy but I didn't find a way to achieve this. Let me know if you need more information.
DoWhy version 0.11.1
The text was updated successfully, but these errors were encountered:
yes that is possible, you can use the functions on single nodes directly. Here is an example:
import networkx as nx
import numpy as np
import pandas as pd
import dowhy.gcm as gcm
X = np.random.normal(loc=0, scale=1, size=1000)
Y = 2 * X + np.random.normal(loc=0, scale=1, size=1000)
Z = 3 * Y + np.random.normal(loc=0, scale=1, size=1000)
data = pd.DataFrame(data=dict(X=X, Y=Y, Z=Z))
causal_model = gcm.StructuralCausalModel(nx.DiGraph([('X', 'Y'), ('Y', 'Z')]))
gcm.auto.assign_causal_mechanisms(causal_model, data)
gcm.fit(causal_model, data)
# Generate data for a new node 'W'
W = 2 * Z + X + np.random.normal(loc=0, scale=0.1, size=1000)
data["W"] = W
# Add the new node to the existing graph
causal_model.graph.add_edges_from([("Z", "W"), ("X", "W")])
# Automatically assign a model to the new node only (or assign one manually)
gcm.auto.assign_causal_mechanism_node(causal_model, "W", data, gcm.auto.AssignmentQuality.GOOD)
# Alternatively, we can also call the assign_causal_mechanisms function, but need to make sure that override_models is false
# gcm.auto.assign_causal_mechanisms(causal_model, data, override_models=False)
# Fit only the new node
gcm.fitting_sampling.fit_causal_model_of_target(causal_model, "W", data)
print(gcm.draw_samples(causal_model, 5).head())
I use the functionality of attributing anomalies of a node to its parents and ancestors in GCM for root cause analysis. Sometimes, I need to add a new node to the graph and some edges between the new node and existing nodes. I would then like to learn the causal mechanism for the nodes affected by the change.
I have tried the following. I have an exiting causal graph and the associated causal model that has been learned. I modified the causal graph by adding the new node and associated new edges. I created a new causal model from the modified causal graph. I would like to copy the learned causal mechanisms in the existing causal model to the new causal model. Afterwards, I would learn the causal mechanisms on the nodes affected by the change in the causal graph.
But when I tried to assign the learned causal mechanism in the existing causal model to the new causal model, I received an error that said I couldn't do this assignment.
Is it possible to incrementally change the causal graph and learn the causal function only on the nodes affected? I looked up the documentation of DoWhy but I didn't find a way to achieve this. Let me know if you need more information.
The text was updated successfully, but these errors were encountered: