08-extended-persistence.py
 author Dmitriy Morozov Tue, 12 Jun 2012 22:35:53 -0700 changeset 1 a0e045bf9248 parent 0 337c84a13184 child 2 4b3728f0d920 permissions -rw-r--r--
Uncommented tutorial.py
```
# Extended persistence (FIXME)
cone = [Simplex([-1] + [v for v in s.vertices]) for s in elephant_complex]
cone.append(Simplex([-1]))

def ep_compare(points):
def max_vertex(s):
return max(points[v][2] for v in s.vertices if v != -1)

def min_vertex(s):
return max(points[v][2] for v in s.vertices if v != -1)

def compare(s1, s2):
if s1.dimension() != s2.dimension():
return cmp(s1.dimension(), s2.dimension())

if (-1 in s1.vertices) ^ (-1 in s2.vertices):
return -1 if -1 in s1.vertices else 1
elif -1 in s1.vertices:
return cmp(min_vertex(s1), min_vertex(s2))
else:
return cmp(max_vertex(s1), max_vertex(s2))

return compare

f = Filtration(elephant_complex + cone)
f.sort(ep_compare(elephant_points))

persistence = StaticPersistence(f)
persistence.pair_simplices()

def eval_ep(points):
def eval(s):
if -1 in s.vertices:
return min(elephant_points[v][2] for v in s.vertices)
else:
return max(elephant_points[v][2] for v in s.vertices)

return eval

dgms = init_diagrams(persistence, f, eval_ep(elephant_points), lambda i: i)

#show_diagram(dgms)
print dgms
print len(dgms)
```