def setSampleReplace(self, sampleReplace): """ :param sampleReplace: A boolean to decide whether to sample with replacement. :type sampleReplace: :class:`bool` """ Parameter.checkBoolean(sampleReplace) self.sampleReplace = sampleReplace
def setSampleReplace(self, sampleReplace): """ :param sampleReplace: A boolean to decide whether to sample with replacement. :type sampleReplace: :class:`bool` """ Parameter.checkBoolean(sampleReplace) self.sampleReplace = sampleReplace
def setIsLeafNode(self, leafNode): Parameter.checkBoolean(leafNode) self.leafNode = leafNode
def setPure(self, pure): Parameter.checkBoolean(pure) self.pure = pure
def setIsLeafNode(self, leafNode): Parameter.checkBoolean(leafNode) self.leafNode = leafNode
def setPure(self, pure): Parameter.checkBoolean(pure) self.pure = pure
def scalarStatistics(self, graph, slowStats=True, treeStats=False): """ Find a series of statistics for the given input graph which can be represented as scalar values. Return results as a vector. """ if graph.is_directed(): raise ValueError("Only works on undirected graphs") #This method is a bit of a mess Parameter.checkBoolean(slowStats) Parameter.checkBoolean(treeStats) statsArray = numpy.ones(self.numStats)*-1 statsArray[self.numVerticesIndex] = graph.vcount() statsArray[self.numEdgesIndex] = graph.ecount() statsArray[self.numDirEdgesIndex] = graph.as_directed().ecount() statsArray[self.densityIndex] = graph.density() logging.debug("Finding connected components") subComponents = graph.components() logging.debug("Done") statsArray[self.numComponentsIndex] = len(subComponents) nonSingletonSubComponents = [c for c in subComponents if len(c) > 1] statsArray[self.numNonSingletonComponentsIndex] = len(nonSingletonSubComponents) triOrMoreSubComponents = [c for c in subComponents if len(c) > 2] statsArray[self.numTriOrMoreComponentsIndex] = len(triOrMoreSubComponents) componentSizes = numpy.array([len(c) for c in subComponents]) inds = numpy.flipud(numpy.argsort(componentSizes)) logging.debug("Studying max component") if len(subComponents) != 0: maxCompGraph = graph.subgraph(subComponents[inds[0]]) statsArray[self.maxComponentSizeIndex] = len(subComponents[inds[0]]) if len(subComponents) >= 2: statsArray[self.secondComponentSizeIndex] = len(subComponents[inds[1]]) statsArray[self.maxComponentEdgesIndex] = maxCompGraph.ecount() statsArray[self.meanComponentSizeIndex] = componentSizes.mean() statsArray[self.maxCompMeanDegreeIndex] = numpy.mean(maxCompGraph.degree(mode=igraph.OUT)) else: statsArray[self.maxComponentSizeIndex] = 0 statsArray[self.maxComponentEdgesIndex] = 0 statsArray[self.meanComponentSizeIndex] = 0 statsArray[self.geodesicDistMaxCompIndex] = 0 if graph.vcount() != 0: statsArray[self.meanDegreeIndex] = numpy.mean(graph.degree(mode=igraph.OUT)) else: statsArray[self.meanDegreeIndex] = 0 if slowStats: logging.debug("Computing diameter") statsArray[self.diameterIndex] = graph.diameter() #statsArray[self.effectiveDiameterIndex] = graph.effectiveDiameter(self.q, P=P) #statsArray[self.powerLawIndex] = graph.fitPowerLaw()[0] logging.debug("Computing geodesic distance") statsArray[self.geodesicDistanceIndex] = graph.average_path_length() if len(subComponents) != 0: statsArray[self.geodesicDistMaxCompIndex] = graph.average_path_length(P=P, vertexInds=list(subComponents[inds[0]])) return statsArray