We are interested in the edge ages for preferential attachment. Edge age = (age of source node) - (age of target node)
In [1]:
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
In [2]:
N = int(30000)
M = np.random.poisson(8, N).tolist()
# generate PA graph
g = ig.Graph.Barabasi(n=N,
m=M,
directed=True)
# compute citation ages
citation_ages = []
source_ages = []
for e in g.es:
source = e.source
target = e.target
citation_ages.append(source - target)
source_ages.append(source)
In [3]:
plt.subplot(1,2,1)
plt.hist(citation_ages);
plt.xlim([0, max(citation_ages)])
plt.xlabel('citation age')
plt.ylabel('count')
plt.subplot(1,2,2)
plt.loglog(sorted(citation_ages, reverse=True), '-', marker='.', color='black',
alpha=.7);
plt.ylabel('log age')
plt.xlabel('log count')
Out[3]:
In [4]:
plt.scatter(source_ages, citation_ages)
plt.xlabel('source age')
plt.ylabel('citation age')
plt.xlim([0, N])
plt.ylim([0, max(citation_ages)])
Out[4]:
In [9]:
# np.linspace(0, N, 11)
bins = range(0 , N, 100)
bin_means = stats.binned_statistic(source_ages, citation_ages, statistic='mean', bins=bins).statistic
plt.scatter(bins[:-1], bin_means)
plt.xlim([0, max(bins)])
plt.ylim([0, max(bin_means)])
plt.xlabel('100 days')
plt.ylabel('bin mean')
Out[9]:
In [6]:
indegrees = g.indegree()
plt.scatter(range(N), indegrees,
marker='.',
color='black')
plt.xlabel('node age')
plt.ylabel('in degree')
plt.xlim([0, N])
plt.ylim([0, 200])
Out[6]:
In [7]:
plt.figure(figsize = [20, 10])
plt.subplot(1,2,1)
dmax = 100
binwidth = 1
plt.hist(indegrees, bins=range(0, dmax + binwidth, binwidth));
plt.xlim([0, dmax])
# plt.ylim([0, 2e5])
plt.subplot(1,2,2)
plt.loglog(sorted(indegrees, reverse=True), '-', marker='.', color='black',
alpha=.7);
plt.ylabel('log degree')
plt.xlabel('log count')
Out[7]:
In [70]:
# layout = []
# indegs = g.indegree()
# for n in range(N):
# x = n
# y = - .5 * indegs[n]
# # y = np.random.uniform()
# layout.append([x, y])
# # vertices
# visual_style = {}
# visual_style['layout'] = layout
# # visual_style['vertex_label'] = range(N)
# # visual_style['vertex_label_size'] = 10
# visual_style['vertex_size'] = 10
# visual_style['vertex_color'] = 'black'
# visual_style['vertex_frame_color'] = 'black'
# visual_style["edge_width"] = .5
# visual_style["edge_arrow_size"] = .5
# visual_style["bbox"] = (300, 300)
# visual_style["margin"] = 20
# ig.plot(g, **visual_style)