Beispiel #1
0
def closure(complx):
    n = max([len(lst) for lst in complx])
    k = n-1
    A1 = []     # A1 will contain the closure of A0 
    while k >= 0: 
        A1 += sh.ksimplices(complx,k)
        k += -1
    return A1
Beispiel #2
0
def closure(complx):
    ## returns the closure of the given complex - adds all of the sublists
    n = max([len(lst) for lst in complx])
    k = n-1
    A1 = []
    while k >= 0:
        A1 += sh.ksimplices(complx,k)
        k += -1
    return A1
Beispiel #3
0
    "ND" : [935,225]
}

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)
Beispiel #4
0
                    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)
Beispiel #5
0
        if i > 0:
            if j == len(angles) - 1:
                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)
Beispiel #6
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')