# ========================================================================= # ========================================================================= # run # ========================================================================= # ========================================================================= numIter = len(range(args.startingIteration, args.endingIteration)) logging.info("compute clusters") exactClusterer = IterativeSpectralClustering(args.k1, alg="exact", computeSinTheta=True) approxClusterer = IterativeSpectralClustering(args.k1, args.k2, T=args.exactFreq, alg="IASC", computeSinTheta=True) nystromClusterer = IterativeSpectralClustering(args.k1, k3=args.k3, alg="nystrom", computeSinTheta=True) RSvdClusterer = IterativeSpectralClustering(args.k1, k4=args.k4, alg="randomisedSvd", computeSinTheta=True) ningsClusterer = NingSpectralClustering(args.k1, T=args.exactFreq, computeSinTheta=True) exactClusterer.nb_iter_kmeans = 20 approxClusterer.nb_iter_kmeans = 20 nystromClusterer.nb_iter_kmeans = 20 RSvdClusterer.nb_iter_kmeans = 20 ningsClusterer.nb_iter_kmeans = 20 # exactClusterer.computeBound = args.computeBound # computeBound not implemented for exactClusterer approxClusterer.computeBound = args.computeBound # nystromClusterer.computeBound = args.computeBound # computeBound not implemented for nystromClusterer # RSvdClusterer.computeBound = args.computeBound # computeBound not implemented for RSvdClusterer # ningsClusterer.computeBound = args.computeBound # computeBound not implemented for ningsClusterer def getGraphIterator(): return itertools.islice(GrowingContrastGraphIterator(), args.startingIteration, args.endingIteration)
vertexArray = graph.getVertexList().getVertices() detections = vertexArray[:, detectionIndex] startYear = 1900 daysInMonth = 30 monthStep = 3 dayList = list(range(int(numpy.min(detections)), int(numpy.max(detections)), daysInMonth*monthStep)) dayList.append(numpy.max(detections)) subgraphIndicesList = [] subgraphIndicesList.append(range(graph.getNumVertices())) k1 = 25 k2 = 2*k1 clusterer = IterativeSpectralClustering(k1, k2) clusterer.nb_iter_kmeans = 20 logging.info("Running exact method") iterator = IncreasingSubgraphListIterator(graph, subgraphIndicesList) clusterListExact, timeListExact, boundList = clusterer.clusterFromIterator(iterator, False, verbose=True) clusters = clusterListExact[0] subgraphIndicesList = [] #minGraphSize = 100 minGraphSize = 500 #Generate subgraph indices list for i in dayList: logging.info("Date: " + str(DateUtils.getDateStrFromDay(i, startYear))) subgraphIndices = numpy.nonzero(detections <= i)[0]
def runExperiment(self): """ Run the selected clustering experiments and save results """ if self.algoArgs.runIASC: logging.debug("Running approximate method") for k2 in self.algoArgs.k2s: logging.debug("k2=" + str(k2)) clusterer = IterativeSpectralClustering(self.algoArgs.k1, k2=k2, T=self.algoArgs.T, alg="IASC", logStep=self.logStep) clusterer.nb_iter_kmeans = 20 clusterer.computeBound = self.algoArgs.computeBound iterator = self.getIterator() clusterList, timeList, boundList = clusterer.clusterFromIterator(iterator, verbose=True) resultsFileName = self.resultsDir + "ResultsIASC_k1=" + str(self.algoArgs.k1) + "_k2=" + str(k2) + "_T=" + str(self.algoArgs.T) + ".npz" self.recordResults(clusterList, timeList, resultsFileName) if self.algoArgs.runExact: logging.debug("Running exact method") clusterer = IterativeSpectralClustering(self.algoArgs.k1, alg="exact", logStep=self.logStep) clusterer.nb_iter_kmeans = 20 iterator = self.getIterator() clusterList, timeList, boundList = clusterer.clusterFromIterator(iterator, verbose=True) resultsFileName = self.resultsDir + "ResultsExact_k1=" + str(self.algoArgs.k1) + ".npz" self.recordResults(clusterList, timeList, resultsFileName) if self.algoArgs.runNystrom: logging.debug("Running Nystrom method") for k3 in self.algoArgs.k3s: logging.debug("k3=" + str(k3)) clusterer = IterativeSpectralClustering(self.algoArgs.k1, k3=k3, alg="nystrom", logStep=self.logStep) clusterer.nb_iter_kmeans = 20 clusterer.computeBound = self.algoArgs.computeBound iterator = self.getIterator() clusterList, timeList, boundList = clusterer.clusterFromIterator(iterator, verbose=True) resultsFileName = self.resultsDir + "ResultsNystrom_k1="+ str(self.algoArgs.k1) + "_k3=" + str(k3) + ".npz" self.recordResults(clusterList, timeList, resultsFileName) if self.algoArgs.runRandomisedSvd: logging.debug("Running randomised SVD method") for k4 in self.algoArgs.k4s: logging.debug("k4=" + str(k4)) clusterer = IterativeSpectralClustering(self.algoArgs.k1, k4=k4, alg="randomisedSvd", logStep=self.logStep) clusterer.nb_iter_kmeans = 20 clusterer.computeBound = self.algoArgs.computeBound iterator = self.getIterator() clusterList, timeList, boundList = clusterer.clusterFromIterator(iterator, verbose=True) resultsFileName = self.resultsDir + "ResultsRandomisedSvd_k1="+ str(self.algoArgs.k1) + "_k4=" + str(k4) + ".npz" self.recordResults(clusterList, timeList, resultsFileName) if self.algoArgs.runEfficientNystrom: logging.debug("Running efficient Nystrom method") for k3 in self.algoArgs.k3s: logging.debug("k3=" + str(k3)) clusterer = IterativeSpectralClustering(self.algoArgs.k1, k3=k3, alg="efficientNystrom", logStep=self.logStep) clusterer.nb_iter_kmeans = 20 clusterer.computeBound = self.algoArgs.computeBound iterator = self.getIterator() clusterList, timeList, boundList = clusterer.clusterFromIterator(iterator, verbose=True) resultsFileName = self.resultsDir + "ResultsEfficientNystrom_k1="+ str(self.algoArgs.k1) + "_k3=" + str(k3) + ".npz" self.recordResults(clusterList, timeList, resultsFileName) if self.algoArgs.runModularity: logging.info("Running modularity clustering") clusterer = IterativeModularityClustering(self.algoArgs.k1) iterator = self.getIterator() clusterList, timeList, boundList = clusterer.clusterFromIterator(iterator, verbose=True) resultsFileName = self.resultsDir + "ResultsModularity_k1=" + str(self.algoArgs.k1) + ".npz" self.recordResults(clusterList, timeList, resultsFileName) if self.algoArgs.runNing: logging.info("Running Nings method") iterator = self.getIterator() clusterer = NingSpectralClustering(self.algoArgs.k1, T=self.algoArgs.T) clusterList, timeList, boundList = clusterer.cluster(iterator, verbose=True) resultsFileName = self.resultsDir + "ResultsNing_k1=" + str(self.algoArgs.k1) + "_T=" + str(self.algoArgs.T) + ".npz" self.recordResults(clusterList, timeList, resultsFileName) logging.info("All done: see you around!")