Exemplo n.º 1
0
                graphIterator = ThreeClustIterator(p, numClusters, r).getIterator()
                clustListNings = ningsClusterer.cluster(graphIterator)
                
            logging.debug("Running random SVD method")
            graphIterator = ThreeClustIterator(p, numClusters, r).getIterator()
            clustListRandSVD = randSvdCluster.clusterFromIterator(graphIterator, False)
    
            # computer rand index error for each iteration
            # error: proportion of pairs of vertices (x,y) s.t.
            #    (cl(x) == cl(y)) != (learned_cl(x) == learned_cl(y))
            for it in range(len(ThreeClustIterator().subgraphIndicesList)):
                  indicesList = ThreeClustIterator().subgraphIndicesList[it]
                  numUsedVertices = len(indicesList)
                  
                  for i in range(len(k2s)): 
                      clustErrApprox[t, it, r, i] += GraphUtils.randIndex(clustListApprox[i][it], indicesList)
                  clustErrExact[t, it, r] += GraphUtils.randIndex(clustListExact[it], indicesList)
                  clustErrNystrom[t, it, r] += GraphUtils.randIndex(clustListNystrom[it], indicesList)
                  if do_Nings:
                      clustErrNings[t, it, r] += GraphUtils.randIndex(clustListNings[it], indicesList)
                      
                  clustErrRandSvd[t, it, r] += GraphUtils.randIndex(clustListRandSVD[it], indicesList)
    
    numpy.savez(fileName, clustErrApprox, clustErrExact, clustErrNystrom, clustErrNings, clustErrRandSvd)
    logging.debug("Saved results as " + fileName)
else:  
    errors = numpy.load(fileName)
    clustErrApprox, clustErrExact, clustErrNystrom, clustErrNings, clustErrRandSvd = errors["arr_0"], errors["arr_1"], errors["arr_2"], errors["arr_3"], errors["arr_4"]
    
    meanClustErrExact = clustErrExact.mean(2)
    meanClustErrApprox = clustErrApprox.mean(2)
Exemplo n.º 2
0
             
         logging.debug("Running random SVD method")
         resRandSVDList = []
         for i in range(len(k4s)): 
             graphIterator = ThreeClustIterator(p, numClusters, r).getIterator()
             resRandSVDList.append(randSvdClusterers[i].clusterFromIterator(graphIterator, True))
 
         # computer rand index error for each iteration
         # error: proportion of pairs of vertices (x,y) s.t.
         #    (cl(x) == cl(y)) != (learned_cl(x) == learned_cl(y))
         for it in range(len(ThreeClustIterator().subgraphIndicesList)):
               indicesList = ThreeClustIterator().subgraphIndicesList[it]
               numUsedVertices = len(indicesList)
               
               for k in range(len(k2s)): 
                   clustErrApprox[t, it, r, k] = GraphUtils.randIndex(resApproxList[k][0][it], indicesList)
               clustErrExact[t, it, r] = GraphUtils.randIndex(resExact[0][it], indicesList)
               for k in range(len(k3s)): 
                   clustErrNystrom[t, it, r, k] = GraphUtils.randIndex(resNystromList[k][0][it], indicesList)
               if do_Nings:
                   clustErrNings[t, it, r] = GraphUtils.randIndex(resNings[0][it], indicesList)
               for k in range(len(k4s)): 
                   clustErrRandSvd[t, it, r, k] = GraphUtils.randIndex(resRandSVDList[k][0][it], indicesList)
 
         # store sin(Theta)
         for k in range(len(k2s)): 
             sinThetaApprox[t, :, r, k] = resApproxList[k][2]["sinThetaList"]
         sinThetaExact[t, :, r] = resExact[2]["sinThetaList"]
         for k in range(len(k3s)): 
             sinThetaNystrom[t, :, r, k] = resNystromList[k][2]["sinThetaList"]
         if do_Nings: