Beispiel #1
0
    def clusterFromIterator(self, graphListIterator, timeIter=False):
        """
        Find a set of clusters for the graphs given by the iterator. 
        """
        clustersList = []
        timeList = [] 

        for subW in graphListIterator:
            logging.debug("Clustering graph of size " + str(subW.shape))
            #Create a SparseGraph
            startTime = time.time()
            graph = SparseGraph(GeneralVertexList(subW.shape[0]))
            graph.setWeightMatrixSparse(subW)
            iGraph = graph.toIGraph()

            vertexCluster = iGraph.community_leading_eigenvector(self.k)
            clustersList.append(vertexCluster.membership)
            timeList.append(time.time()-startTime)

        if timeIter:
            return clustersList, timeList
        else:
            return clustersList