期望度序列#

给定度序列的随机图。

出:

Degree histogram
degree (#nodes) ****
 0 ( 0)
 1 ( 0)
 2 ( 0)
 3 ( 0)
 4 ( 0)
 5 ( 0)
 6 ( 0)
 7 ( 0)
 8 ( 0)
 9 ( 0)
10 ( 0)
11 ( 0)
12 ( 0)
13 ( 0)
14 ( 0)
15 ( 0)
16 ( 0)
17 ( 0)
18 ( 0)
19 ( 0)
20 ( 0)
21 ( 0)
22 ( 0)
23 ( 0)
24 ( 0)
25 ( 0)
26 ( 0)
27 ( 0)
28 ( 0)
29 ( 0)
30 ( 0)
31 ( 1) *
32 ( 1) *
33 ( 0)
34 ( 3) ***
35 ( 1) *
36 ( 2) **
37 ( 3) ***
38 ( 3) ***
39 (14) **************
40 (12) ************
41 (16) ****************
42 (22) **********************
43 (16) ****************
44 (23) ***********************
45 (31) *******************************
46 (23) ***********************
47 (34) **********************************
48 (29) *****************************
49 (27) ***************************
50 (23) ***********************
51 (28) ****************************
52 (32) ********************************
53 (33) *********************************
54 (22) **********************
55 (13) *************
56 (16) ****************
57 (13) *************
58 (13) *************
59 (10) **********
60 (12) ************
61 ( 4) ****
62 ( 4) ****
63 ( 5) *****
64 ( 0)
65 ( 2) **
66 ( 3) ***
67 ( 3) ***
68 ( 0)
69 ( 0)
70 ( 0)
71 ( 1) *
72 ( 0)
73 ( 0)
74 ( 1) *
75 ( 1) *

import networkx as nx

# make a random graph of 500 nodes with expected degrees of 50
n = 500  # n nodes
p = 0.1
w = [p * n for i in range(n)]  # w = p*n for all nodes
G = nx.expected_degree_graph(w)  # configuration model
print("Degree histogram")
print("degree (#nodes) ****")
dh = nx.degree_histogram(G)
for i, d in enumerate(dh):
    print(f"{i:2} ({d:2}) {'*'*d}")

Total running time of the script: ( 0 minutes 0.024 seconds)

Gallery generated by Sphinx-Gallery