Lesson 3
Introduction to lists & local network properties
Author: Alissa Tripodoro, Michael Coyne, Naaz Modan
Version: 1
Date: September 23, 2015
Import the igraph package. This package can be used to create, manipulate, and compute metrics and functions related to the structure of a network or graph.
GOOD CODING PRACTICE - Import all your packages before you begin writing your program code.
Recall from last time that we created a graph with 3 nodes.
GOOD CODING PRACTICE - Comment different parts of your code.
Your turn! Add another node to the graph and 2 edges from the new node to one of the other nodes.
myGraph.summary()
Last time, we also learned how to compute some global graph properties, density and diameter. We stored the results in a variable and then printed the density and diameter on the screen.
Your turn! Explain what density and diameter tell us.
Density is the ratio between the actual connections between nodes in a graph and the maximum potential number of connections that could exist between those same nodes.
Diameter is the "longest shortest distance;" or the shortest possible path between the two furthest nodes in a graph.
We can also compute local graph properties. Here we compute degree, betweenness and clustering coefficient for all the nodes in the graph.
GOOD CODING PRACTICE - Use meaningful variable names.
The clustering coefficient shows the number of neighbors a node has, and how many of those neighbors are connected to each other. A greater clustering coefficient signifies a stronger network.
Betweeness refers to the number of geodesic (shortest) paths between two nodes in a graph that pass through a given node.
Degree refers to the number of neighbors an individual node has, indicated by edges linking a node to another node(s).
The variables myDegreeList, myBetweenessList, myClusteringCoefficientList are all variables that store a list of values. Each of these variables are lists of size four since there are 4 nodes in the graph (assuming you added a node). If we did not know the size of the list, we would use the len() function to determine it.
Your turn! Write code to determine the length of the betweeness list and the clustering coefficient list.
To determine the degree of a particular node, you need to access a particular cell in the list. You do this by identifying the cell of interest with the list variable.
Your turn! Determine the betweeness and clustering coefficient for all the nodes in the network.
Our current graph is an unweighted graph. If we did not know that, we could check to see if it is weighted.
Let's add weights to the graph. We do this by adding an attribute "weight" to the set of edges (es) in the graph (myGraph).
Let's change the weight of the edge between nodes 0 and 1 to a weight of 2.
Your turn! Change the edge weights for all the other edges in the network. Then print the edge weights.
Your turn! Now that the edges have different weights, does that change the importance of the different nodes in the network. Explain.
Yes, weighted edges indicate connections of different significance between differnt nodes. For example, the average weight of a connection between node 3 and another node is ((4+1.5)/2)=2.75. In contrast, node 0, though it has the same amount of connections, has a lower average weight of ((2+2)/2)=2.00. As such, node 3 has stronger average connections within this network, and may as such be more significant to the network as a whole–it may be a station with more traffic, a student who has older friendships, an enzyme that is more crucial to various processes, et cetera.