4 from dionysus import Rips, PairwiseDistances, StaticPersistence, Filtration, points_file, \
5 ExplicitDistances, data_dim_cmp
6 from sys import argv, exit
9 def main(filename, skeleton, max):
10 points = [p for p in points_file(filename)]
11 distances = PairwiseDistances(points)
12 # distances = ExplicitDistances(distances) # speeds up generation of the Rips complex at the expense of memory usage
13 rips = Rips(distances)
14 print time.asctime(), "Rips initialized"
17 rips.generate(skeleton, max, simplices.append)
18 print time.asctime(), "Generated complex: %d simplices" % len(simplices)
20 # While this step is unnecessary (Filtration below can be passed rips.cmp),
21 # it greatly speeds up the running times
22 for s in simplices: s.data = rips.eval(s)
23 print time.asctime(), simplices[0], '...', simplices[-1]
25 f = Filtration(simplices, data_dim_cmp) # could be rips.cmp if s.data for s in simplices is not set
26 print time.asctime(), "Set up filtration"
28 p = StaticPersistence(f)
29 print time.asctime(), "Initialized StaticPersistence"
32 print time.asctime(), "Simplices paired"
34 print "Outputting persistence diagram"
37 b = simplices[f[p(i)]]
39 if b.dimension() >= skeleton: continue
42 print b.dimension(), b.data, "inf"
45 d = simplices[f[p(i.pair)]]
46 print b.dimension(), b.data, d.data
48 if __name__ == '__main__':
50 print "Usage: %s POINTS SKELETON MAX" % argv[0]
54 skeleton = int(argv[2])
57 main(filename, skeleton, max)