In [1]:
%pylab inline
%matplotlib inline

import graph as g
import numpy as np
from matplotlib import pyplot as plt


Populating the interactive namespace from numpy and matplotlib

In [2]:
yt = g.graph_from_pickle('../data/youtube.graph')

In [30]:
def freq(walk_func, start=0, length=5, repeat=50):
    freq_dict = dict()
    for _ in range(repeat):
        walk = walk_func(start_node=start, length=length)
        for i in walk:
            if i in freq_dict:
                freq_dict[i] += 1
            else:
                freq_dict[i] = 1
    return freq_dict

In [41]:
n1_r50_r = freq(yt.random_walk, 1, 5, 50)
n1_r50_m = freq(yt.motif_walk, 1, 5, 50)
n1_r50_r.pop(1)
n1_r50_m.pop(1)


Out[41]:
56

In [58]:
norm1 = sum([x for x in n1_r50_r.values()])
norm2 = sum([x for x in n1_r50_m.values()])
freq1 = [x / norm1 for x in n1_r50_r.values()]
freq2 = [x / norm2 for x in n1_r50_m.values()]

In [60]:
plt.bar(n1_r50_r.keys(),freq1)


Out[60]:
<Container object of 166 artists>

In [44]:
plt.bar(n1_r50_m.keys(), freq2)


Out[44]:
<Container object of 169 artists>

In [49]:
n1_r100_r = freq(yt.random_walk, 1, 5, 100)
n1_r100_m = freq(yt.motif_walk, 1, 5, 100)
n1_r100_r.pop(1)
n1_r100_m.pop(1)
norm1 = sum([x for x in n1_r100_r.values()])
norm2 = sum([x for x in n1_r100_m.values()])
freq1 = [x / norm1 for x in n1_r100_r.values()]
freq2 = [x / norm2 for x in n1_r100_m.values()]

In [50]:
plt.bar(n1_r100_r.keys(), freq1)


Out[50]:
<Container object of 328 artists>

In [51]:
plt.bar(n1_r100_m.keys(), freq2)


Out[51]:
<Container object of 302 artists>

In [53]:
n1_r1000_r = freq(yt.random_walk, 1, 5, 1000)
n1_r1000_m = freq(yt.motif_walk, 1, 5, 1000)
n1_r1000_r.pop(1)
n1_r1000_m.pop(1)
norm1 = sum([x for x in n1_r1000_r.values()])
norm2 = sum([x for x in n1_r1000_m.values()])
freq1 = [x / norm1 for x in n1_r1000_r.values()]
freq2 = [x / norm2 for x in n1_r1000_m.values()]

In [54]:
plt.bar(n1_r1000_r.keys(), freq1)


Out[54]:
<Container object of 2309 artists>

In [56]:
plt.bar(n1_r1000_m.keys(), freq2)


Out[56]:
<Container object of 2124 artists>

In [ ]: