def locHomTable(toplexes, ascdict={}, neighborhood = 1, ofile = None): # Computes the local homology for all faces in the ASC generated by the toplexes # and returns a table of the dimensions of H1, H2, and H3 # Takes a neighborhood size 0,1,2, and an output file name # if nodes are named, this can go in ascdict={nodeNumber:"name"} for the table # otherwise names will be given by the concatenation of the index numbers k = 1 ASC = closure(toplexes) if ofile == None: print " ", "\t\t", "H1" , "\t" , "H2", "\t", "H3", "\t\t", "FACE" print "-"*50 else: ofile.write(" \t\t" + "H1" + "\t" + "H2" + "\t" + "H3" + "\t\t" + "name" + "\n") for cnt,splx in enumerate(ASC): # print cnt+1, len(ASC), splx if neighborhood == 0: complx = [splx] elif neighborhood == 1: complx = closure([splx]) else: complx = closure(sstar(toplexes, closure([splx]))) A = sstar(toplexes, complx) Hks,_=sh.localHomologyMultiproc(3,toplexes,2,A,False,True) H1 = Hks[0] H2 = Hks[1] H3 = Hks[2] name = "" if ascdict != {}: for idx in range(len(A[0])): name += ascdict[A[0][idx]] if name == "": name = ','.join(map(str,splx)) if ofile == None: print k, "\t\t", H1 , "\t" , H2, "\t", H3, "\t\t", name k += 1 else: ofile.write(str(k) + "\t\t" + str(H1) + "\t" + str(H2) + "\t" + str(H3) + "\t\t" + str(name) + "\n") k += 1
graph_file = "usa.txt" # ALL OF THESE ARE FOR N0 NEIGHBORHOODS g = nx.read_edgelist(graph_file, nodetype=int) gflag = None gedgelist = map(list,g.edges(data=False)) startTime = tm.time() print "finding flag complex" cplx = sh.flag(gedgelist,3) print "getting simplices" # Demo multiple processes Hks,cplx_grph=sh.localHomologyMultiproc(3,cplx,2,None,True,True) # Demo multiple threads # Hks,cplx_grph=sh.localHomologyMultithread(3,cplx,2) colors_grph_1=Hks[0] colors_grph_2=Hks[1] colors_grph_3=Hks[2] endTime = tm.time() print "\n**** Total time = %f s ****\n" % (endTime-startTime) print "creating locations array" locations = [[coords[states[i]][0], -coords[states[i]][1]] for i in range(1,50)] locations = [[0,0]] + locations