# Import packages
import igraph
# create an empty graph
freshGraph = igraph.Graph()
# add three nodes or vertices and add labels to them
freshGraph.add_vertices(3)
myGraph.vs["label"] = ["0","1","2"]
# create three edges among these nodes
myGraph.add_edges([(0,1),(1,2),(2,0)])
# draw the graph
igraph.plot(myGraph, layout = myGraph.layout_random(), bbox=(200,200))
import igraph
freshGraph =igraph.Graph()
freshGraph.add_vertices(4)
freshGraph.vs["label"] = ["0","1","2","3"]
freshGraph.add_edges([(0,1),(1,2),(2,0),(3,1),(3,2)])
igraph.plot(freshGraph, layout =freshGraph.layout_random(), bbox=(200,200))
myGraph.summary()
# Use igraph to compute the density and diameter of the network
myDensity = myGraph.density()
myDiameter = myGraph.diameter()
# Display the density and diameter of the graph
print "Graph density: ", myDensity
print "Graph diameter: ", myDiameter
Density = if all nodes were connected, density shows us how many connections there would be. It shows us how connected a graph is. Diameter = Is the largest geodesic distance in the graph. Diameter tells us how to travel the farthest distance between two nodes using the fewest number of edges. Diameter shows how nodes are connected across the network.
myDegreeList = myGraph.degree()
myBetweenessList = myGraph.betweenness()
myClusteringCoefficientList = myGraph.transitivity_local_undirected()
print "Degree of all nodes: ", myDegreeList
print "Betweenness of all nodes: ", myBetweenessList
print "Clustering Coefficient of all nodes:", myClusteringCoefficientList
Degree = the number of nodes that a node is connected to, or the number of neighbors it has. Degree is important to show how connected a node is to the other nodes. Betweeness = betweeness is the total number of shortest paths between all pairs of nodes that pass through node i. Betweeness is important in findng out which nodes are highly relevant to the graph and are often used in these shortest paths. Clustering coefficient = subset of node i's neighbors that are connected. Clustering coefficient is important because it is indicative of the relationships existing between i's neighbors, which in turn details the nature and depth of the relationships amongst i's neighbors
degreeListLength = len(myDegreeList)
print "The length of the degree list: ", degreeListLength
myBetweenessList = myGraph.betweenness()
betweenessListLength = len(myBetweenessList)
print "The length of the betweeness list: ", betweenessListLength
myClusteringCoefficientList = myGraph.transitivity_local_undirected()
print "Clustering Coefficient of all nodes:", myClusteringCoefficientList
clusteringCoefficientListLength = len(myClusteringCoefficientList)
print "The length of the clustering coefficent list: ", clusteringCoefficientListLength
# See if the graph is a weighted graph
myGraph.is_weighted()
# Add weights to the graph
myGraph.es["weight"] = 1
# Check to see if the graph is a weighted graph
myGraph.is_weighted()
# Print all the edge weights
myGraph.es["weight"]
# Make edge(0,1) an edge weight of 2
myGraph[0, 1]=2
# Print all the edge weights
myGraph.es["weight"]
freshGraph.es["weight"] = 3
freshGraph.is_weighted()
freshGraph.es["weight"]
freshGraph [0,1]=4
freshGraph [1,2]=2
freshGraph [2,0]=5
freshGraph [3,1]=.5
freshGraph [3,2]=3.5
freshGraph.es["weight"]
Yes,introducing different weights alters the importance of existing nodes in the network. Given that weights correspond to the strength of relationships, new weights directly relate to changed strength of relationships, which, in turn, lessens the importance of some nodes while increasing the importance of other nodes. An edge weight that changes from 3 to 5 would become more important becuase the network is emphasizing that edge more that others in the network.