Exemple #1
0
 def test_degree_mixing_dict_multigraph(self):
     d=nx.degree_mixing_dict(self.M)
     d_result={1:{2:1},
               2:{1:1,3:3},
               3:{2:3}
               }
     assert_equal(d,d_result)
 def test_degree_mixing_dict_undirected_normalized(self):
     d = nx.degree_mixing_dict(self.P4, normalized=True)
     d_result = {
         1: {2: 1.0 / 3},
         2: {1: 1.0 / 3, 2: 1.0 / 3},
     }
     assert d == d_result
 def test_degree_mixing_dict_undirected(self):
     d = nx.degree_mixing_dict(self.P4)
     d_result = {
         1: {2: 2},
         2: {1: 2, 2: 2},
     }
     assert d == d_result
Exemple #4
0
 def test_degree_mixing_dict_directed(self):
     d=nx.degree_mixing_dict(self.D)
     print(d)
     d_result={1:{3:2},
               2:{1:1,3:1},
               3:{}
               }
     assert_equal(d,d_result)
Exemple #5
0
def test_directedjointdegreemodel(n=15, m=100, ntimes=1000):
    import time
    for _ in range(ntimes):
        seed = time.time()

        # generate gnm random graph and calculate its joint degree.
        g = nx.gnm_random_graph(n, m, seed, directed=True)

        in_degrees = dict(g.in_degree()).values()
        out_degrees = dict(g.out_degree()).values()
        nkk = nx.degree_mixing_dict(g)

        # generate simple directed graph with given degree sequence and joint
        # degree matrix.
        G = directed_joint_degree_model(in_degrees, out_degrees, nkk)

        # assert degree sequence correctness.
        assert (in_degrees == dict(g.in_degree()).values())
        assert (out_degrees == dict(g.out_degree()).values())
        # assert joint degree matrix correctness.
        assert (nkk == nx.degree_mixing_dict(G))
def degree_mixing(graph, probability):
    d = nx.degree_mixing_dict(graph, normalized=probability)
    od = collections.OrderedDict(sorted(d.items()))
    for key, value in od.items():
        print("------------------------------------")
        print("Degree1: " + str(key))
        print("------------------------------------")
        ovalue = collections.OrderedDict(sorted(value.items()))
        for k, v in ovalue.items():
            print("Degree2: " + str(k), end='\t')
            if probability == True:
                print("Probability: " + str(v))
            else:
                print("Count: " + str(v))
Exemple #7
0
 def test_degree_mixing_dict_multigraph(self):
     d = nx.degree_mixing_dict(self.M)
     d_result = {1: {2: 1}, 2: {1: 1, 3: 3}, 3: {2: 3}}
     assert d == d_result
Exemple #8
0
 def test_degree_mixing_dict_directed(self):
     d = nx.degree_mixing_dict(self.D)
     print(d)
     d_result = {1: {3: 2}, 2: {1: 1, 3: 1}, 3: {}}
     assert d == d_result
Exemple #9
0
 def test_degree_mixing_dict_undirected(self):
     d=nx.degree_mixing_dict(self.P4)
     d_result={1:{2:2},
               2:{1:2,2:2},
               }
     assert_equal(d,d_result)
# Wyświetl wykres średniej stopnia sąsiedztwa
val = neighbour_assortativity(statistics.mean)
plt.plot(list(map(lambda i: i[0], val.items())), list(map(lambda i: i[1], val.items())), 'ro', numpy.arange(0, 100),
         numpy.arange(0, 100))
plt.axis([0, 150, 0, 40])
plt.show()

# Wyświetl wykres mediany stopnia sąsiedztwa
val = neighbour_assortativity(statistics.median)
plt.plot(list(map(lambda i: i[0], val.items())), list(map(lambda i: i[1], val.items())), 'ro', numpy.arange(0, 100),
         numpy.arange(0, 100))
plt.axis([0, 150, 0, 20])
plt.show()

degrees = [Edge(s, d, n) for s, sub in sorted(nx.degree_mixing_dict(G).items(), key=lambda k: k) for d, n in
           sorted(sub.items(), key=lambda k: k)]
degrees = list(set(degrees))

x = numpy.array([])
y = numpy.array([])
s = numpy.array([])
for edge in degrees:
    x = numpy.append(x, edge.source)
    y = numpy.append(y, edge.destination)
    s = numpy.append(s, edge.weight)

cm = plt.cm.get_cmap('jet')

fig, ax = plt.subplots()
sc = ax.scatter(x, y, s=s, cmap=cm, linewidth=0, alpha=0.5)
Exemple #11
0
 def test_degree_mixing_dict_undirected_normalized(self):
     d = nx.degree_mixing_dict(self.P4, normalized=True)
     d_result = {1: {2: 1.0 / 3},
                 2: {1: 1.0 / 3, 2: 1.0 / 3},
                 }
     assert_equal(d, d_result)
Exemple #12
0
 def test_degree_mixing_dict_weighted(self):
     d = nx.degree_mixing_dict(self.W, weight="weight")
     d_result = {0.5: {1.5: 1}, 1.5: {1.5: 6, 0.5: 1}}