Investigate PageRank in a DAG


In [6]:
import igraph as ig
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
from math import *

%load_ext autoreload
%autoreload 2
%matplotlib inline


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

In [45]:
N = int(1e5)
M = 1


# uniform attachment
ua = ig.Graph.Growing_Random(n=N, m=M,
                             directed=True, citation=True)

# preferential attachment
pa = ig.Graph.Barabasi(n=N, m=M,
                       directed=True)

Time vs indegree


In [49]:
plt.figure(figsize=[20, 10])

plt.subplot(1, 2, 1)
indegrees_u = ua.indegree()
plt.scatter(range(N), indegrees_u,
            marker='.',
            color='black')
plt.xlabel('node age')
plt.ylabel('in degree')

plt.xlim([0, N])
plt.ylim([0, max(indegrees_u)])
plt.title('uniform attachment')


plt.subplot(1, 2, 2)
indegrees_p = pa.indegree()
plt.scatter(range(N), indegrees_p,
            marker='.',
            color='black')
plt.xlabel('node age')
plt.ylabel('in degree')

plt.xlim([0, N])
plt.ylim([0, max(indegrees_p)])
plt.title('preferential attachment')


Out[49]:
<matplotlib.text.Text at 0x114866590>

time vs. page rank


In [57]:
plt.figure(figsize=[20, 10])

# uniforma ttachment
plt.subplot(1, 2, 1)
pageranks_u = ua.pagerank()
plt.scatter(range(N), [log(v) for v in  pageranks_u],
            marker='.',
            color='black')
plt.xlabel('node age')
plt.ylabel('log PageRank')

plt.xlim([0, N])
# plt.ylim([0, max(pageranks_u)])
# plt.ylim([0, .0003])
plt.title('uniform attachment')

# preferential attachment
plt.subplot(1, 2, 2)
pageranks_p = pa.pagerank()
plt.scatter(range(N), [log(v) for v in  pageranks_p],
            marker='.',
            color='black')

plt.xlabel('node age')
plt.ylabel('log PageRank')

plt.xlim([0, N])
# plt.ylim([0, max(pageranks_p)])
# plt.ylim([0, .0003])
plt.title('preferential attachment')


Out[57]:
<matplotlib.text.Text at 0x11251ff50>

In [ ]: