Esempio n. 1
0
def locHomTable(toplexes,graph,ascdict={},neighborhood = 1,outfile = 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)

    sh.printAS(toplexes,"Flag complex from SH")
    sh.printAS(ASC,"ASC")
    
    
    ofile = open(outfile, 'w')
    ofile.write("Local Homology (neighborhood=%d) of flag complex generated by %s\n" % (neighborhood, graph))
    
    if outfile == 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 splx in ASC:

        if neighborhood == 0:
            complx = [splx]
        elif neighborhood == 1:
            complx = closure([splx])
        else:
            complx = closure(sstar(toplexes, closure([splx])))
        A = sstar(toplexes, complx)

        H1=sh.localHomology(toplexes,1,A).shape[1]
        H2=sh.localHomology(toplexes,2,A).shape[1]
        H3=sh.localHomology(toplexes,3,A).shape[1]


        name = ""
        if ascdict != {}:
            for idx in range(len(A[0])):
                name += ascdict[A[0][idx]]

        if name == "":
            name = ','.join(map(str,splx))

        if outfile == 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

    ofile.close()
Esempio n. 2
0
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)

        H1=sh.localHomology(1,toplexes,A,True)
        H2=sh.localHomology(2,toplexes,A,True)
        H3=sh.localHomology(3,toplexes,A,True)

        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
Esempio n. 3
0
def locHomTable(toplexes, ascdict={}):
    
    ASC = closure(toplexes)
    print "FACE" , "\t\t\t" , "H0" , "\t" , "H1" , "\t" , "H2"
    print "-"*50
    
    for splx in ASC:
    
        complx = [splx]
        A = sstar(toplexes,closure(complx))
        
        H0=sh.localHomology(0,toplexes,A,True)
        H1=sh.localHomology(1,toplexes,A,True)
        H2=sh.localHomology(2,toplexes,A,True)
         
        name = ""
        if ascdict != {}:
            for idx in range(len(complx[0])):
                name += ascdict[complx[0][idx]]
                
        if name == "":
            name = ','.join(map(str,splx))
             
        print name, "\t\t\t" , H0 , "\t" , H1 , "\t" , H2
Esempio n. 4
0
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"
cplx_grph=sh.ksimplices(cplx,0)+sh.ksimplices(cplx,1)+sh.ksimplices(cplx,2)+sh.ksimplices(cplx,3)
print "creating colors1"
colors_grph_1=[sh.localHomology(1,cplx,[spx],True) for spx in cplx_grph]
print "creating colors2"
colors_grph_2=[sh.localHomology(2,cplx,[spx],True) for spx in cplx_grph]
print "creating colors3"
colors_grph_3=[sh.localHomology(3,cplx,[spx],True) for spx in cplx_grph]

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

plt.figure(figsize=(24,16), tight_layout=True)
#plt.figure()
plt.hold(True)
Esempio n. 5
0
                          i * len(angles)]]
            else:
                cplx += [[
                    i * len(angles) + j, i * len(angles) + j + 1,
                    (i - 1) * len(angles) + j
                ],
                         [(i - 1) * len(angles) + j + 1,
                          (i - 1) * len(angles) + j, i * len(angles) + j + 1]]

startTime = tm.time()

cplx_annulus = cplx + sh.ksimplices(cplx, 1) + sh.ksimplices(cplx, 0)

print 'colors_annulus_1'
colors_annulus_1 = [
    sh.localHomology(1, cplx, [spx], True) for spx in cplx_annulus
]
print 'colors_annulus_2'
colors_annulus_2 = [
    sh.localHomology(2, cplx, [spx], True) for spx in cplx_annulus
]

endTime = tm.time()
print "\n**** Total time = %f s ****\n" % (endTime - startTime)

plt.figure()
plt.hold(True)
plt.subplot(121)
pc.plot_complex(locations_annulus, cplx_annulus, colors_annulus_1)
plt.subplot(122)
pc.plot_complex(locations_annulus, cplx_annulus, colors_annulus_2)
Esempio n. 6
0
                cplx += [
                    [i * len(angles) + j, i * len(angles), (i - 1) * len(angles) + j],
                    [(i - 1) * len(angles), (i - 1) * len(angles) + j, i * len(angles)],
                ]
            else:
                cplx += [
                    [i * len(angles) + j, i * len(angles) + j + 1, (i - 1) * len(angles) + j],
                    [(i - 1) * len(angles) + j + 1, (i - 1) * len(angles) + j, i * len(angles) + j + 1],
                ]


startTime = tm.time()

cplx_annulus = cplx + sh.ksimplices(cplx, 1) + sh.ksimplices(cplx, 0)

print "colors_annulus_1"
colors_annulus_1 = [sh.localHomology(1, cplx, [spx], True) for spx in cplx_annulus]
print "colors_annulus_2"
colors_annulus_2 = [sh.localHomology(2, cplx, [spx], True) for spx in cplx_annulus]

endTime = tm.time()
print "\n**** Total time = %f s ****\n" % (endTime - startTime)

plt.figure()
plt.hold(True)
plt.subplot(121)
pc.plot_complex(locations_annulus, cplx_annulus, colors_annulus_1)
plt.subplot(122)
pc.plot_complex(locations_annulus, cplx_annulus, colors_annulus_2)
plt.savefig("annulus.png")
Esempio n. 7
0
import numpy.random as random
import matplotlib.pyplot as plt
import simplicialHomology as sh
import plotComplex as pc

# Example: A "thick" graph
startTime = tm.time()
random.seed(100)

locations = []
while len(locations) < 100:
    loc = random.rand(2)
    if np.sqrt((loc[0] - 0.5)**2 + (loc[1] - 0.5)**2) < 0.5:
        locations.append(loc)
cplx = sh.vietorisRips(locations, 0.1, maxdim=2)
cplx_grph = sh.ksimplices(cplx, 0) + sh.ksimplices(cplx, 1) + sh.ksimplices(
    cplx, 2)
colors_grph_1 = [sh.localHomology(1, cplx, [spx], True) for spx in cplx_grph]
colors_grph_2 = [sh.localHomology(2, cplx, [spx], True) for spx in cplx_grph]

endTime = tm.time()
print "\n**** Total time = %f s ****\n" % (endTime - startTime)

plt.figure()
plt.hold(True)
plt.subplot(121)
pc.plot_complex(locations, cplx_grph, colors_grph_1)
plt.subplot(122)
pc.plot_complex(locations, cplx_grph, colors_grph_2)
plt.savefig('thick_graph.png')
Esempio n. 8
0
# Unit tests for local homology computations
#
# Copyright (c) 2015-2017, Michael Robinson, Chris Capraro
# Distribution of unaltered copies permitted for noncommercial use only
# All other uses require express permission of the author
# This software comes with no warrantees express or implied

import simplicialHomology as sh

# Test 1: line segment localized to the edge
toplexes = [[1, 2]]

H0 = sh.localHomology(0, toplexes, [[1, 2]], True)
H1 = sh.localHomology(1, toplexes, [[1, 2]], True)
H2 = sh.localHomology(2, toplexes, [[1, 2]], True)

if H0 != 0 or H1 != 1 or H2 != 0:
    print "Test 1a failed"
    print "H0=" + str(H0)
    print "H1=" + str(H1)
    print "H2=" + str(H2)
else:
    print "Test 1a passed"

H0 = sh.localHomology(0, toplexes, [[1, 2]])
H1 = sh.localHomology(1, toplexes, [[1, 2]])
H2 = sh.localHomology(2, toplexes, [[1, 2]])

if H0.shape[1] != 0 or H1.shape[1] != 1 or H2.shape[1] != 0:
    print "Test 1b failed"
    print "H0=" + H0.__repr__()
Esempio n. 9
0
# Unit tests for local homology computations
#
# Copyright (c) 2015, Michael Robinson
# Distribution of unaltered copies permitted for noncommercial use only
# All other uses require express permission of the author
# This software comes with no warrantees express or implied 

import simplicialHomology as sh
 
# Test 1: line segment localized to the edge
toplexes=[[1,2]]
   
H0=sh.localHomology(0,toplexes,[[1,2]],True)
H1=sh.localHomology(1,toplexes,[[1,2]],True)
H2=sh.localHomology(2,toplexes,[[1,2]],True)
   
if H0 != 0 or H1 != 1 or H2 != 0:
    print "Test 1a failed" 
    print "H0="+ str(H0)
    print "H1="+ str(H1)
    print "H2="+ str(H2)
else:
    print "Test 1a passed"
   
H0=sh.localHomology(0,toplexes,[[1,2]])
H1=sh.localHomology(1,toplexes,[[1,2]])
H2=sh.localHomology(2,toplexes,[[1,2]])
   
if H0.shape[1] != 0 or H1.shape[1] != 1 or H2.shape[1] != 0:
    print "Test 1b failed" 
    print "H0="+ H0.__repr__()
Esempio n. 10
0
# Unit tests for local homology computations
#
# Copyright (c) 2015, Michael Robinson
# Distribution of unaltered copies permitted for noncommercial use only
# All other uses require express permission of the author
# This software comes with no warrantees express or implied 

import numpy as np
import simplicialHomology as sh

# Test 1: line segment localized to the edge
toplexes=[[1,2]]

H0=sh.localHomology(toplexes,0,[[1,2]])
H1=sh.localHomology(toplexes,1,[[1,2]])
H2=sh.localHomology(toplexes,2,[[1,2]])

if H0.shape[1] != 0 or H1.shape[1] != 1 or H2.shape[1] != 0:
    print "Test 1 failed" 
    print "H0="+ H0.__repr__()
    print "H1="+ H1.__repr__()
    print "H2="+ H2.__repr__()
else:
    print "Test 1 passed"

# Test 2: line segment localized to the star over one vertex 
# (using localHomology())
toplexes=[[1,2]]

H0=sh.localHomology(toplexes,0,[[1]])
H1=sh.localHomology(toplexes,1,[[1]])