In [2]:
import networkx as nx
import matplotlib as plt
%matplotlib inline
Exercício 01: Calcule a distância média, o diâmetro e o coeficiente de agrupamento das redes abaixo.
In [12]:
G1 = nx.erdos_renyi_graph(5,0.4)
nx.draw_shell(G1)
In [13]:
print "Dist. media: ", nx.average_shortest_path_length(G1)
print "Diametro: ", nx.diameter(G1)
print "Coef. Agrupamento médio: ", nx.average_clustering(G1)
In [15]:
G2 = nx.barabasi_albert_graph(6,3)
nx.draw_shell(G2)
In [16]:
print "Dist. media: ", nx.average_shortest_path_length(G2)
print "Diametro: ", nx.diameter(G2)
print "Coef. Agrupamento médio: ", nx.average_clustering(G2)
In [17]:
G3 = nx.barabasi_albert_graph(6,4)
nx.draw_shell(G3)
In [18]:
print "Dist. media: ", nx.average_shortest_path_length(G3)
print "Diametro: ", nx.diameter(G3)
print "Coef. Agrupamento médio: ", nx.average_clustering(G3)
Exercício 02: Calcule a centralidade de grau, betweenness e pagerank dos nós das redes abaixo:
In [19]:
G4 = nx.barabasi_albert_graph(6,3)
plt.pyplot.figure(figsize=(10,10))
pos = nx.shell_layout(G4)
nx.draw_networkx_nodes(G4,pos);
nx.draw_networkx_edges(G4,pos);
nx.draw_networkx_labels(G4,pos);
plt.pyplot.axis('off')
Out[19]:
In [20]:
print "Centralidades de grau:"
for ni,dc in nx.degree_centrality(G4).items():
print ni, dc
In [21]:
print "Centralidades de pagerank:"
for ni,dc in nx.pagerank(G4).items():
print ni, dc
In [22]:
print "Centralidades de betweenness:"
for ni,dc in nx.betweenness_centrality(G4).items():
print ni, dc
In [ ]:
In [ ]: