def contactsGraph(): fileName = path + "connections-28-11-12" vertexIdDict = {} vertexIdSet = set([]) edgeSet = set([]) edgeArray = [] graph = igraph.Graph() i = 0 j = 0 with open(fileName) as f: f.readline() for line in f: if i % 50000 == 0: print(i) words = line.split() vId1 = int(words[0]) vId2 = int(words[1]) if vId1 not in vertexIdSet: vertexIdDict[vId1] = j vertexIdSet.add(vId1) j += 1 if vId2 not in vertexIdSet: vertexIdDict[vId2] = j vertexIdSet.add(vId2) j += 1 if (vertexIdDict[vId1], vertexIdDict[vId2]) not in edgeSet and (vertexIdDict[vId2], vertexIdDict[vId1]) not in edgeSet: edgeArray.append([vertexIdDict[vId1], vertexIdDict[vId2]]) edgeSet.add((vertexIdDict[vId1], vertexIdDict[vId2])) i += 1 print("Read " + str(i) + " lines with " + str(j) + " vertices") graph.add_vertices(j) graph.add_edges(edgeArray) print(igraph.summary(graph)) graphStats = GraphStatistics() statsArray = graphStats.scalarStatistics(graph, slowStats=False) print(graphStats.strScalarStatsArray(statsArray)) xs, ys = zip(*[(left, count) for left, _, count in graph.degree_distribution().bins()]) plt.figure(0) plt.bar(xs[0:30], ys[0:30]) plt.xlabel("Degree") xs, ys = zip(*[(left, count) for left, _, count in graph.components().size_histogram().bins()]) plt.figure(1) plt.bar(xs[0:30], ys[0:30]) plt.xlabel("Component size") plt.show()
def fullCoauthorGraph(): fileName = path + "coauthorsGraph" graph = igraph.Graph() graph = graph.Read_Edgelist(fileName) graph = graph.as_undirected() print(igraph.summary(graph)) graphStats = GraphStatistics() statsArray = graphStats.scalarStatistics(graph, slowStats=False) print(graphStats.strScalarStatsArray(statsArray))
def articleGroupsGraph(): fileName = path + "articleGroupMembership-28-11-12" graph = readBipartiteGraph(fileName) print(igraph.summary(graph)) graphStats = GraphStatistics() statsArray = graphStats.scalarStatistics(graph, slowStats=False) print(graphStats.strScalarStatsArray(statsArray)) xs, ys = zip(*[(left, count) for left, _, count in graph.degree_distribution().bins()]) plt.figure(0) plt.bar(xs[0:30], ys[0:30]) plt.xlabel("Degree") xs, ys = zip(*[(left, count) for left, _, count in graph.components().size_histogram().bins()]) plt.figure(1) plt.bar(xs[0:30], ys[0:30]) plt.xlabel("Component size") plt.show()