I'm working with complex networks and I have this algorithm that I'm using to generate my networks, which I use to compare with empirical results. The idea of the algorithm is kind simple: I started from the Barabasi-Albert algorithm, which I used as a base for my model. The model starts with a complete graph with (m+1) nodes, where m is the same parameter used in the BA Model (number of links that the new node will have), and then I create a new node. This node will be add to the network following one of the two processes:
- duplication: where I choose a node from the network to duplicate, and the new node will have the same neighbours as the parent node; the probability used to choose this node is similar to the preferential attachment probability defined by Barabasi.
- preferential attachment: new node will follow the rule defined by Barabasi, choosing one of the most connected nodes in the network and connecting to m different nodes.
model[n_, m_, r_] /; n >= 3 :=
Module[{g = CompleteGraph[m + 1], vc, vl, el, el2, node, newnode},
Do[
vc = VertexCount[g];
vl = VertexList[g];
el = EdgeList[g];
If[RandomReal[] <= p,
node = RandomChoice[(VertexDegree[g]^(r)) -> vl];
newnode = AdjacencyList[g, node];
el = ParallelMap[UndirectedEdge[vc + 1, #] &, newnode];
,
el = ParallelMap[
UndirectedEdge[vc + 1, #] &,
RandomSample[VertexDegree[g] -> vl, m]
]
];
g = Graph[Join[EdgeList[g], el]];
,
{n - m - 1}
];
g
]
In the code, n is the size of the network, m is the BA model parameter, r is the expoent I'm using in the probability to choose the node to duplicate and p is tha probability that the new node will either duplicate an existing one or follow the preferential attachment rule.
Since I'm working with large networks (around 10000 nodes) and with high values of p (from 0.5 to 0.9), I'm trying to find a way, if there is, to write this code more efficient, because it takes almost a week to genereta a network with n=11711, m=5, r=1 and p =0.5.