Cleaned up simplex comparison functions, rip-pairwise.py outputs a diagram, auxilliary add_simplices() + remove_simplices() for zigzags
--- a/bindings/python/dionysus/__init__.py Thu Apr 16 00:23:01 2009 -0700
+++ b/bindings/python/dionysus/__init__.py Wed Apr 29 10:16:03 2009 -0700
@@ -1,5 +1,6 @@
from _dionysus import *
from distances import *
+from zigzag import *
def init_with_data(self, v, d = None):
@@ -23,6 +24,7 @@
return cmp(s1.data, s2.data)
def data_dim_cmp(s1,s2):
- dim_cmp = cmp(s1.dimension(), s2.dimension())
- if dim_cmp: return dim_cmp
- else: return data_cmp(s1,s2)
+ return cmp(s1.dimension(), s2.dimension()) or data_cmp(s1,s2)
+
+def vertex_dim_cmp(s1, s2):
+ return cmp(s1.dimension(), s2.dimension()) or vertex_cmp(s1, s2)
--- a/bindings/python/dionysus/distances.py Thu Apr 16 00:23:01 2009 -0700
+++ b/bindings/python/dionysus/distances.py Wed Apr 29 10:16:03 2009 -0700
@@ -15,7 +15,7 @@
return len(self.points)
def __call__(self, p1, p2):
- return self.norm([x - y for (x,y) in zip(self.points[p1], self.points[p2])])
+ return self.norm((x - y for (x,y) in zip(self.points[p1], self.points[p2])))
# Caches all distances specified by `distances`
class ExplicitDistances:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/python/dionysus/zigzag.py Wed Apr 29 10:16:03 2009 -0700
@@ -0,0 +1,20 @@
+def add_simplices(zz, simplices, complex, birth, report_local = False):
+ deaths = []
+ for s in simplices:
+ i,d = zz.add([complex[sb] for sb in s.boundary], (s.dimension(), birth))
+ complex[s] = i
+ if d is not None:
+ if report_local or not d == birth:
+ deaths.append(d)
+ return deaths
+
+
+def remove_simplices(zz, simplices, complex, birth, report_local = False):
+ deaths = []
+ for s in simplices:
+ d = zz.remove(complex[s], (s.dimension(), birth))
+ complex[s] = None
+ if d is not None:
+ if report_local or not d == birth:
+ deaths.append(d)
+ return deaths
--- a/examples/rips/rips-pairwise.py Thu Apr 16 00:23:01 2009 -0700
+++ b/examples/rips/rips-pairwise.py Wed Apr 29 10:16:03 2009 -0700
@@ -17,7 +17,7 @@
points = [p for p in points_file(filename)]
distances = PairwiseDistances(points)
-#distances = ExplicitDistances(distances) # speeds up generation of the Rips complex at the expense of memory usage
+distances = ExplicitDistances(distances) # speeds up generation of the Rips complex at the expense of memory usage
rips = Rips(distances)
print time.asctime(), "Rips initialized"
@@ -38,3 +38,17 @@
p.pair_simplices()
print time.asctime(), "Simplices paired"
+
+print "Outputting persistence diagram"
+for i in p:
+ if i.sign():
+ b = simplices[f[p(i)]]
+
+ if b.dimension() >= skeleton: continue
+
+ if i == i.pair:
+ print b.dimension(), b.data, "inf"
+ continue
+
+ d = simplices[f[p(i.pair)]]
+ print b.dimension(), b.data, d.data