I'm trying to understand how to correctly generate a directed random graph based on Erdős–Rényi model. I have looked at erdos_renyi_graph
function on network x.
I have set as n parameter the number of nodes of my real network (5317) then for p i have calculated:
p = (< k_in > + < k_out >)/(n-1) = (78,302 )/(5317-1) = 0, 014729496
I have calculated the average degree as the sum of in_degree and out_degree.
Applying this probability it has generated a random graph with 5317 nodes and 415.727 edges. Many more edges than my real network(207.167 edges).
Did I do something wrong?
I think it's correct, cause the average degree(as sum of k_in
and k_out
) is reasonably higher than indegree and outdegree. So if you treat the graph as directed in the Erdős–Rényi
model you should have something like average degree/2
because for each edge, there are two vertexes associated to it. So each edge adds two degrees to the graph, according to the degree sum formula:
That's the reason of diving by 2 the result. So in this circumstance it will generate a random graph with around the same number of edges of your real graph.