In [1]:
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 [5]:
G1 = nx.erdos_renyi_graph(5,0.4)
nx.draw_shell(G1)



In [6]:
print "Dist. media: ", nx.average_shortest_path_length(G1)
print "Diametro: ", nx.diameter(G1)
print "Coef. Agrupamento médio: ", nx.average_clustering(G1)


Dist. media:  1.4
Diametro:  2
Coef. Agrupamento médio:  0.6

In [7]:
G2 = nx.barabasi_albert_graph(6,3)
nx.draw_shell(G2)



In [8]:
print "Dist. media: ", nx.average_shortest_path_length(G2)
print "Diametro: ", nx.diameter(G2)
print "Coef. Agrupamento médio: ", nx.average_clustering(G2)


Dist. media:  1.4
Diametro:  2
Coef. Agrupamento médio:  0.761111111111

In [9]:
G3 = nx.barabasi_albert_graph(6,4)
nx.draw_shell(G3)



In [10]:
print "Dist. media: ", nx.average_shortest_path_length(G3)
print "Diametro: ", nx.diameter(G3)
print "Coef. Agrupamento médio: ", nx.average_clustering(G3)


Dist. media:  1.46666666667
Diametro:  2
Coef. Agrupamento médio:  0.633333333333

Exercício 02: Calcule a centralidade de grau, betweenness e proximidade dos nós das redes abaixo:


In [11]:
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[11]:
(-1.5, 1.5, -1.5, 1.5)

In [12]:
print "Centralidades de grau:"
for ni,dc in nx.degree_centrality(G4).items():
    print ni, dc


Centralidades de grau:
0 0.4
1 0.4
2 0.4
3 1.0
4 0.8
5 0.6

In [13]:
print "Centralidades de proximidade:"
for ni,dc in nx.closeness_centrality(G4).items():
    print ni, dc


Centralidades de proximidade:
0 0.625
1 0.625
2 0.625
3 1.0
4 0.833333333333
5 0.714285714286

In [14]:
print "Centralidades de betweenness:"
for ni,dc in nx.betweenness_centrality(G4).items():
    print ni, dc


Centralidades de betweenness:
0 0.0
1 0.0
2 0.0
3 0.4
4 0.15
5 0.05