3 from dionysus import Simplex, Filtration, StaticPersistence, vertex_cmp
4 from sys import argv, exit
7 def max_vertex(s, vertices):
8 return max((vertices[v] for v in s.vertices))
10 def max_vertex_cmp(s1, s2, vertices):
11 m1 = max_vertex(s1, vertices)
12 m2 = max_vertex(s2, vertices)
13 return cmp(m1, m2) or cmp(s1.dimension(), s2.dimension())
15 def lsf(values_filename, simplices_filename):
18 with open(values_filename) as f:
20 if line.startswith('#'): continue 21 vertices.append(float(line.split()[1]))
25 with open(simplices_filename) as f:
27 if line.startswith('#'): continue 28 fltr.append(Simplex(map(int, line.split())))
29 fltr.sort(lambda x,y: max_vertex_cmp(x,y,vertices))
32 p = StaticPersistence(fltr)
35 # Output the persistence diagram
36 smap = p.make_simplex_map(fltr)
38 if not i.sign(): continue
44 print b.dimension(), max_vertex(b, vertices), "inf"
47 print b.dimension(), max_vertex(b, vertices), max_vertex(d, vertices)
50 if __name__ == '__main__':
52 print "Usage: %s VERTICES SIMPLICES" % argv[0]
54 print "Computes persistence of the lower star filtration of the simplicial "
55 print "complex explicitly listed out in SIMPLICES with vertex values given in VERTICES."
61 lsf(values, simplices)