def run(self): self.graph, authorMap, conferenceMap, totalCitationCount = SampleGraphUtility.constructMultiDisciplinaryAuthorExample(indirectAuthor = True) # Get the nodes we care about conferences = [ conferenceMap['VLDB'], conferenceMap['KDD'] ] authors = [ authorMap['A'], authorMap['B'], authorMap['C'], authorMap['D'], authorMap['E'], authorMap['F'], authorMap['G'], authorMap['H'], authorMap['I'], authorMap['J'], ] self.metaPathUtility = EdgeBasedMetaPathUtility() # Build homogeneous projection of network (authors, with edges for times authors cite each other) projectedGraph = self.metaPathUtility.createHomogeneousProjection(self.graph, [Author, Paper, Paper, Author]) authorCitationCounts = {} for author in projectedGraph.getNodes(): authorCitationCounts[author] = {} for otherAuthor in projectedGraph.getNodes(): authorCitationCounts[author][otherAuthor] = projectedGraph.getNumberOfEdges(author, otherAuthor) # Output the adjacency matrix for authors-authors in the graph self.output('\nCitation Matrix:') adjMatrixTable = texttable.Texttable() rows = [['Author'] + [author.name for author in authors]] rows += [[author.name] + [authorCitationCounts[author][otherAuthor] for otherAuthor in authors] for author in authors] adjMatrixTable.add_rows(rows) self.output(adjMatrixTable.draw()) # Output the adjacency matrix for authors & conferences in the graph self.output('\nAdjacency Matrix:') adjMatrixTable = texttable.Texttable() projectedGraph = self.metaPathUtility.createHeterogeneousProjection(self.graph, [Author, Paper, Conference]) rows = [[''] + [conference.name for conference in conferences]] rows += [[author.name] + [projectedGraph.getNumberOfEdges(author, conference) for conference in conferences] for author in authors] adjMatrixTable.add_rows(rows) self.output(adjMatrixTable.draw()) # Output total citation counts self.output('\nTotal Citation Counts:') rows = [[author.name for author in authors],['%d' % totalCitationCount[author.name] for author in authors]] citationCountTable = texttable.Texttable() citationCountTable.add_rows(rows) self.output(citationCountTable.draw()) # Output the PathSim similarity scores pathsimStretegy = PathSimStrategy(self.graph, [Author, Paper, Conference, Paper, Author], True) self.outputSimilarityScores(authorMap, authors, pathsimStretegy, "PathSim") # Output the NeighborSim similarity scores neighborsimStrategy = NeighborSimStrategy(self.graph, [Conference, Paper, Paper, Author]) self.outputSimilarityScores(authorMap, authors, neighborsimStrategy, "NeighborSim (CPPA)") # Output the NeighborSim similarity scores neighborsimStrategy = NeighborSimStrategy(self.graph, [Author, Paper, Paper, Author]) self.outputSimilarityScores(authorMap, authors, neighborsimStrategy, "NeighborSim (APPA)") # Constant weight propagation strategy propagatedNeighborsimStrategy = NeighborSimConstantPropagationStrategy(self.graph, [Author, Paper, Paper, Author], iterations = 2) self.outputSimilarityScores(authorMap, authors, propagatedNeighborsimStrategy, "NeighborSim-ConstantPropagation-2") propagatedNeighborsimStrategy = NeighborSimConstantPropagationStrategy(self.graph, [Author, Paper, Paper, Author], iterations = 3) self.outputSimilarityScores(authorMap, authors, propagatedNeighborsimStrategy, "NeighborSim-ConstantPropagation-3") propagatedNeighborsimStrategy = NeighborSimConstantPropagationStrategy(self.graph, [Author, Paper, Paper, Author], iterations = 4) self.outputSimilarityScores(authorMap, authors, propagatedNeighborsimStrategy, "NeighborSim-ConstantPropagation-4") propagatedNeighborsimStrategy = NeighborSimConstantPropagationStrategy(self.graph, [Author, Paper, Paper, Author], iterations = 50) self.outputSimilarityScores(authorMap, authors, propagatedNeighborsimStrategy, "NeighborSim-ConstantPropagation-50") # Preferential attachment propagation strategy propagatedNeighborsimStrategy = NeighborSimConstantPreferentialAttachmentStrategy(self.graph, [Author, Paper, Paper, Author], iterations = 2) self.outputSimilarityScores(authorMap, authors, propagatedNeighborsimStrategy, "NeighborSim-WeightedPropagation-2") propagatedNeighborsimStrategy = NeighborSimConstantPreferentialAttachmentStrategy(self.graph, [Author, Paper, Paper, Author], iterations = 3) self.outputSimilarityScores(authorMap, authors, propagatedNeighborsimStrategy, "NeighborSim-WeightedPropagation-3") propagatedNeighborsimStrategy = NeighborSimConstantPreferentialAttachmentStrategy(self.graph, [Author, Paper, Paper, Author], iterations = 4) self.outputSimilarityScores(authorMap, authors, propagatedNeighborsimStrategy, "NeighborSim-WeightedPropagation-4") propagatedNeighborsimStrategy = NeighborSimConstantPreferentialAttachmentStrategy(self.graph, [Author, Paper, Paper, Author], iterations = 50) self.outputSimilarityScores(authorMap, authors, propagatedNeighborsimStrategy, "NeighborSim-WeightedPropagation-50") # Neighbor citation count difference strategy citeCountNeighborsimStrategy = NeighborSimStrategy(self.graph, [Paper, Paper, Author], commonNeighbors = False) self.outputSimilarityScores(authorMap, authors, citeCountNeighborsimStrategy, "NeighborSim-CiteCountDiff", citationCounts = totalCitationCount)
def run(self): self.graph, authorMap, conferenceMap, totalCitationCount = SampleGraphUtility.constructMultiDisciplinaryAuthorExample() # Get the nodes we care about conferences = [ conferenceMap['VLDB'], conferenceMap['KDD'] ] authors = [ authorMap['A'], authorMap['B'], authorMap['C'], authorMap['D'], authorMap['E'], authorMap['F'], authorMap['G'], authorMap['H'], authorMap['I'], ] self.metaPathUtility = EdgeBasedMetaPathUtility() # Build homogeneous projection of network (authors, with edges for times authors cite each other) projectedGraph = self.metaPathUtility.createHomogeneousProjection(self.graph, [Author, Paper, Paper, Author]) authorCitationCounts = {} for author in projectedGraph.getNodes(): authorCitationCounts[author] = {} for otherAuthor in projectedGraph.getNodes(): authorCitationCounts[author][otherAuthor] = projectedGraph.getNumberOfEdges(author, otherAuthor) # Output the adjacency matrix for authors-authors in the graph self.output('\nCitation Matrix:') adjMatrixTable = texttable.Texttable() rows = [['Author'] + [author.name for author in authors]] rows += [[author.name] + [authorCitationCounts[author][otherAuthor] for otherAuthor in authors] for author in authors] adjMatrixTable.add_rows(rows) self.output(adjMatrixTable.draw()) # Output the adjacency matrix for authors & conferences in the graph self.output('\nAdjacency Matrix:') adjMatrixTable = texttable.Texttable() projectedGraph = self.metaPathUtility.createHeterogeneousProjection(self.graph, [Author, Paper, Conference]) rows = [[''] + [conference.name for conference in conferences]] rows += [[author.name] + [projectedGraph.getNumberOfEdges(author, conference) for conference in conferences] for author in authors] adjMatrixTable.add_rows(rows) self.output(adjMatrixTable.draw()) # Output total citation counts self.output('\nTotal Citation Counts:') rows = [[author.name for author in authors],['%d' % totalCitationCount[author.name] for author in authors]] citationCountTable = texttable.Texttable() citationCountTable.add_rows(rows) self.output(citationCountTable.draw()) # Output the NeighborSim similarity scores strategy = NeighborSimStrategy(self.graph, [Conference, Paper, Paper, Author]) self.outputSimilarityScores(authorMap, authors, strategy, "NeighborSim") # Output the PathSim similarity scores pathsimStretegy = PathSimStrategy(self.graph, [Author, Paper, Conference, Paper, Author], True) self.outputSimilarityScores(authorMap, authors, pathsimStretegy, "PathSim") # Output SimRank-related scores simrankStrategy = SimRankStrategy(self.graph, [Author, Paper, Paper, Author]) self.outputSimilarityScores(authorMap, authors, simrankStrategy, "SimRank") # Output pathsim - simrank scores combinedNeighborSim = AggregateSimilarityStrategy(self.graph, [simrankStrategy, pathsimStretegy], [0.5, 0.5]) self.outputSimilarityScores(authorMap, authors, combinedNeighborSim, 'APCPA Pathsim, APPA SimRank') # Output the projected PageRank/HITS similarity scores for name, algorithm in zip(['PageRank', 'HITS'], [PageRankDistanceStrategy, HITSDistanceStrategy]): researchAreas = { (authorMap['A'], authorMap['B'], authorMap['C'], authorMap['D'], authorMap['E'], authorMap['I']), (authorMap['F'], authorMap['G'], authorMap['H'], authorMap['D'], authorMap['E'], authorMap['I']), } strategy = algorithm(self.graph, [Author, Paper, Paper, Author], nodeSets=researchAreas, symmetric=True) self.outputSimilarityScores(authorMap, authors, strategy, "%s-Distance" % name)