Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing Barabasi-Albert Method for Creating Scale-Free Networks
    primarykey
    data
    text
    <p>I'm trying to implement a very simple preferential attachment algorithm for creating scale-free networks. These have degree distributions that follow a power-law, i.e. P(k) ~ k^-g, where g is the exponent. The algorithm below should produce degree distributions with the exponent equal 3 +/- 0.1, my implementation does not the exponents are closer to 2.5 +/- 0.1. I'm clearly not understanding something somewhere and continue to get it wrong.</p> <p>I'm sorry if this is in the wrong place, I couldn't decide whether it should be in stackoverflow or maths.stackexchange.com.</p> <pre><code>The Algorithm: Input: Number of Nodes N; Minimum degree d &gt;= 1. Output: scale-free multigraph G = ({0,....,N-1}, E) M: array of length 2Nd for (v=0,...,n-1) for (i=0,...,d-1) M[2(vd+i)] = v; r = random number selected uniformly at random from {0,.....,2(vd+i)}; M[2(vd+i)+1] = M[r]; end end E = {}; for (i=0,...,nd-1) E[i] = {M[2i], M[2i+1]} end </code></pre> <p>My Implementation in C/C++:</p> <pre><code>void SF_LCD(std::vector&lt; std::vector&lt;int&gt; &gt;&amp; graph, int N, int d) { if(d &lt; 1 || d &gt; N - 1) { std::cerr &lt;&lt; "Error: SF_LCD: k_min is out of bounds: " &lt;&lt; d; } std::vector&lt;int&gt; M; M.resize(2 * N * d); int r = -1; //Use Batagelj's implementation of the LCD model for(int v = 0; v &lt; N; v++) { for(int i = 0; i &lt; d; i++) { M[2 * (v * d + i)] = v; r = mtr.randInt(2 * (v * d + i)); M[2 * (v * d + i) + 1] = M[r]; } } //create the adjacency list graph.resize(N); bool exists = false; for(int v = 0; v &lt; M.size(); v += 2) { int m = M[v]; int n = M[v + 1]; graph[m].push_back(n); graph[n].push_back(m); } } </code></pre> <p>Here's an example of a degree distribution I get for N = 10,000 and d = 1:</p> <pre><code>1 6674 2 1657 3 623 4 350 5 199 6 131 7 79 8 53 9 57 10 27 11 17 12 20 13 15 14 12 15 5 16 8 17 5 18 10 19 7 20 6 21 5 22 6 23 4 25 4 26 2 27 1 28 6 30 2 31 1 33 1 36 2 37 2 43 1 47 1 56 1 60 1 63 1 64 1 67 1 70 1 273 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload