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



In [40]:
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.62222222222
Diametro:  3
Coef. Agrupamento médio:  0.39

In [41]:
G2 = nx.barabasi_albert_graph(10,3)
nx.draw_shell(G2)



In [42]:
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.55555555556
Diametro:  3
Coef. Agrupamento médio:  0.688095238095

In [43]:
G3 = nx.barabasi_albert_graph(10,4)
nx.draw_shell(G3)



In [44]:
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.51111111111
Diametro:  3
Coef. Agrupamento médio:  0.581904761905

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


In [45]:
G4 = nx.barabasi_albert_graph(10,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[45]:
(-1.5, 1.5, -1.5, 1.5)

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


Centralidades de grau:
0 0.222222222222
1 0.555555555556
2 0.555555555556
3 0.555555555556
4 0.666666666667
5 0.777777777778
6 0.333333333333
7 0.333333333333
8 0.333333333333
9 0.333333333333

In [47]:
print "Centralidades de pagerank:"
for ni,dc in nx.pagerank(G4).items():
    print ni, dc


Centralidades de pagerank:
0 0.0570507248055
1 0.115363838484
2 0.115363838484
3 0.117272794136
4 0.137876312144
5 0.158699755898
6 0.073494186233
7 0.0780491519162
8 0.0734146989498
9 0.0734146989498

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


Centralidades de betweenness:
0 0.00925925925926
1 0.0634259259259
2 0.0634259259259
3 0.149074074074
4 0.154166666667
5 0.23287037037
6 0.00694444444444
7 0.0615740740741
8 0.00462962962963
9 0.00462962962963

In [ ]:


In [ ]: