Example to demonstrate optimized backdoor variable search for Causal Identification#

This notebook compares the performance between causal identification using vanilla backdoor search and the optimized backdoor search and demonstrates the performance gains obtained by using the latter.

[1]:
import time
import random
from networkx.linalg.graphmatrix import adjacency_matrix
import numpy as np
import pandas as pd
import networkx as nx

import dowhy
from dowhy import CausalModel
from dowhy.utils import graph_operations
import dowhy.datasets

Create Random Graph#

In this section, we create a random graph with the designated number of nodes (10 in this case).

[2]:
n = 10
p = 0.5

G = nx.generators.random_graphs.fast_gnp_random_graph(n, p, directed=True)
graph = nx.DiGraph([(u,v) for (u,v) in G.edges() if u<v])
nodes = []
for i in graph.nodes:
    nodes.append(str(i))
adjacency_matrix = np.asarray(nx.to_numpy_array(graph))
graph_dot = graph_operations.adjacency_matrix_to_graph(adjacency_matrix, nodes)
graph_dot = graph_operations.str_to_dot(graph_dot.source)
print("Graph Generated.")

df = pd.DataFrame(columns=nodes)
print("Dataframe Generated.")
Graph Generated.
Dataframe Generated.