This excercise assumes you have Python and the corredponding NetworkX package installed, if not, go back to Computing Environment Setup
This part of the excercise tests your NetworkX and iGraph installations by exploring a Network Science dataset.
Step 1: Download a sub-sampled NetScience dataset from this link and place it in your working directory. This is part of a coauthorship network of scientists working on network theory and experiment, as compiled by M. Newman in May 20061.
Step 2: Load and examine the NetSci dataset
import networkx as nx
import matplotlib.pyplot as plt
gs = nx.read_gml('./netsci_subgraph.gml', relabel = True)
nx.draw_spring(gs)
if you’re not in an ipython shell, then you’ll also need to type
plt.show()
You should see a graph drawing like this:
Each node is a person, an edge means that the two people have co-authored at least one academic paper on network science.
Now let’s look at a few teaser questions about graphs.
What is the size of this graph?
A) 14
B) 19
C) 23
D) 30
Try typing the following commonads in python:
gs.number_of_nodes()
or
len(gs)
or
gs.number_of_edges()
Does Watts and Kleinberg know each other?
Yes No
nx.shortest_path(gs, source = 'KLEINBERG, J', target = 'WATTS, D')
If not, who can introduce them?
How many introductions does “NEWMAN, M” need to reach any one in the graph?
A) 1
B) 4
C) 2
D) 5
[nx.shortest_path(gs, source = 'NEWMAN, M', target = x) for x in gs.nodes()]
How many introductions does “MATTHEWS, P” need to reach any one in the graph?
max( [len(nx.shortest_path(gs, source = 'MATTHEWS, P', target = x)) - 1 for x in newman_n] )
What are the differences between nodes “NEWMAN, M” and “MATTHEWS, P”? Can you think of rwo different ways to measure the maximum distance on a network?
nx.radius(gs)
nx.diameter(gs)
nx.eccentricity(gs)
Who is the “center” of this graph? How can you define this?
"""we will talk about ways to measure centered-ness in a graph in class, stay tuned!
"""
What are “communities” in a network?
One way is to look for K people who have co-authored at least one paper with each other. Who is in the community with HOPCROFT? What is K?
nx.cliques_containing_node(gs, 'HOPCROFT, J')
M. E. J. Newman, Phys. Rev. E 74, 036104 (2006) [netsci]:http://www.casos.cs.cmu.edu/computational_tools/datasets/external/netscience/netscience.gml↩