-
Notifications
You must be signed in to change notification settings - Fork 202
Open
Description
π Bug: Wrong expected degree in init_dag for dag_type='erdos'
In init_dag, we currently have:
elif self.dag_type == 'erdos':
nb_edges = self.expected_degree * self.nodesHowever, it should be:
nb_edges = (self.expected_degree * self.nodes) / 2The current implementation roughly doubles the expected number of edges per node.
Example:
import numpy as np
import networkx as nx
from cdt.data import AcyclicGraphGenerator
def avg_undirected_degree(G: nx.DiGraph) -> float:
"""Average degree of the undirected version of a directed graph."""
Gu = G.to_undirected()
return sum(dict(Gu.degree()).values()) / Gu.number_of_nodes()
obs = []
for _ in range(100):
gen = AcyclicGraphGenerator(
causal_mechanism='linear',
dag_type='erdos',
nodes=100,
expected_degree=5,
npoints=1,
)
_, G = gen.generate()
obs.append(avg_undirected_degree(G))
print(float(np.mean(obs)))Expected: β 5
Observed β 10
Metadata
Metadata
Assignees
Labels
No labels