# Must be used on directed graphs # node is the node to find the input domain for # pathLimit is the maximal path length to be considered # if pathLimit = 0, there is no limit def inputDomainPrestige(node, pathLimit): prestige = 0.0 for nodeTwo in g.nodes: path = nodeTwo.unweightedShortestPath(node) if((len(path) > 0 )and ((len(path) <= pathLimit) or (pathLimit ==0))): prestige += 1 return prestige # More complex version that calculates input domain for all nodes and stores # it as a node attribute. Also calculates average distance to each node # in that domain def inputDomainPrestige(pathLimit): numNodes = len(g.nodes) if(Node.getField("inputdomain" + str(pathLimit)) == None): addNodeField("inputdomain" + str(pathLimit), Types.INTEGER, 0) addNodeField("idaveragedistance" + str(pathLimit), Types.DOUBLE, 0.0) for node in g.nodes: domainSize = 0 summedPathLength = 0.0 for nodeTwo in g.nodes: path = nodeTwo.unweightedShortestPath(node) if((len(path) > 0 )and ((len(path) <= pathLimit) or (pathLimit ==0))): domainSize += 1 summedPathLength += len(path) interp.exec(node.name + ".inputdomain" + str(pathLimit) + " = " + str(domainSize)); average = 0.0 if summedPathLength != 0: average = summedPathLength/domainSize interp.exec(node.name + ".idaveragedistance" + str(pathLimit) + " = " + str(average)) # Also only works with directd graphs. # Does the following: # 1. Finds the proportion of vertices in the parameter's input domain # 2. Finds the mean of all path distances to the vertices in the input domain # 3. Divides #1 by #2 def simplePrestigeProximity(node): domainSize = 0.0 summedPathLength = 0 for nodeTwo in g.nodes: path = nodeTwo.unweightedShortestPath(node) if(len(path) > 0): domainSize += 1 summedPathLength += len(path) average = 0.0 if summedPathLength == 0: return average average = summedPathLength/domainSize return (domainSize/(len(g.nodes)-1.0))/average # Uses the more complex input domain function def prestigeProximity(node): proxPrestige = 0.0 inputDomainPrestige(0) if node.idaveragedistance0 == 0: return 0.0 proxPrestige = (node.inputdomain0/(len(g.nodes)-1.0))/node.idaveragedistance0 return proxPrestige #This version finds the proximity prestige for all nodes based on an # input domain of the given maximum distance def allProximityPrestige(pathLimit): proxPrestige = 0.0 numNodes = len(g.nodes) if(Node.getField("proximityprestige" + str(pathLimit)) == None): addNodeField("proximityprestige" + str(pathLimit), Types.DOUBLE, 0.0) inputDomainPrestige(pathLimit); for node in g.nodes: proxPrestige = node.__getattr__("inputDomain" + str(pathLimit)) proxPrestige = (proxPrestige*1.0)/(numNodes -1.0) if node.__getattr__("idaveragedistance" + str(pathLimit)) == 0: proxPrestige = 0.0 else: proxPrestige = proxPrestige/(node.__getattr__("idaveragedistance"+str(pathLimit))) node.__setattr__("proximityprestige" + str(pathLimit), proxPrestige)