import numpy as np
from networkx import barabasi_albert_graph
from causaldag import DAG
def directed_random_graph(nnodes, random_graph_model):
edges = random_graph_model(nnodes).edges
random_permutation = np.arange(nnodes)
np.random.shuffle(random_permutation)
arcs = []
for edge in edges:
node1, node2 = edge
node1_position = np.where(random_permutation == node1)[0][0]
node2_position = np.where(random_permutation == node2)[0][0]
if node1_position < node2_position:
source = node1
endpoint = node2
else:
source = node2
endpoint = node1
arcs.append((source, endpoint))
return DAG(nodes=set(range(nnodes)), arcs=arcs)
def directed_barbasi(nnodes, nattach):
random_graph_model = lambda nnodes: barabasi_albert_graph(nnodes, nattach)
return directed_random_graph(nnodes, random_graph_model)
import numpy as np
from networkx import barabasi_albert_graph
from causaldag import DAG
def directed_random_graph(nnodes, random_graph_model):
edges = random_graph_model(nnodes).edges
random_permutation = np.arange(nnodes)
np.random.shuffle(random_permutation)
arcs = []
for edge in edges:
node1, node2 = edge
node1_position = np.where(random_permutation == node1)[0][0]
node2_position = np.where(random_permutation == node2)[0][0]
if node1_position < node2_position:
source = node1
endpoint = node2
else:
source = node2
endpoint = node1
arcs.append((source, endpoint))
return DAG(nodes=set(range(nnodes)), arcs=arcs)
def directed_barbasi(nnodes, nattach):
random_graph_model = lambda nnodes: barabasi_albert_graph(nnodes, nattach)
return directed_random_graph(nnodes, random_graph_model)