examples/triangle/triangle.py
author Dmitriy Morozov <dmitriy@mrzv.org>
Thu, 09 Jul 2009 02:42:47 -0700
branchdev
changeset 138 96030f8d2f2c
parent 129 95454ea3f9c0
child 181 1ee6edc17cb6
permissions -rw-r--r--
Rips pairwise cohomology produces output necessary for 1-cocycle parametrization

from dionysus import Simplex, Filtration, StaticPersistence, \
                     vertex_cmp, data_cmp, data_dim_cmp \

complex = [Simplex((0,),        0),                 # A
           Simplex((1,),        1),                 # B
           Simplex((2,),        2),                 # C
           Simplex((0,1),       2.5),               # AB
           Simplex((1,2),       2.9),               # BC
           Simplex((0,2),       3.5),               # CA
           Simplex((0,1,2),     5)]                 # ABC

print "Complex:", complex
print "Vertex: ", sorted(complex, vertex_cmp)
print "Data:   ", sorted(complex, data_cmp)
print "DataDim:", sorted(complex, data_dim_cmp)

complex.sort(vertex_cmp)        # put complex in the lexicographic order; required for persistence computation

f = Filtration(complex, data_cmp)
print "Complex in the filtration order:", ', '.join((str(complex[i]) for i in f))

p = StaticPersistence(f)
p.pair_simplices()
for i in p:
    print "%s (%d) - %s (%d)" % (complex[f[p(i)]], i.sign(), 
                                 complex[f[p(i.pair)]], i.pair.sign())
    print "Cycle (%d):" % len(i.cycle()), " + ".join((str(complex[f[p(ii)]]) for ii in i.cycle()))

print "Number of unpaired simplices:", len([i for i in p if i == i.pair])