examples/rips/rips.py
 author Dmitriy Morozov Wed, 16 Dec 2009 15:39:06 -0800 branch dev changeset 179 d15c6d144645 parent 130 580eaa850c4f child 181 1ee6edc17cb6 permissions -rw-r--r--
Resurrected vineyard code: * Switched StaticPersistence + (serializable) Filtration to Boost.MultiIndex * Updated DynamicPersistenceTrails to work with the new MultiIndex way * Created LSVineyard class, and fixed the grid examples
```
from    math        import fabs
from    dionysus    import Rips, Filtration, StaticPersistence #, enable_log

# Simple minded pairwise distance functor distance
class Distances:
def __len__(self):
return 5

def __call__(self, x, y):
return fabs(y-x)

dist = Distances()
r = Rips(dist)
lst = []
lst2 = []

#enable_log('rips')

r.generate(1, 3, lst.append)
r.generate(1, 3, lst2.append, [0,2,4])

print "Rips complex on all vertices:", lst
print "Rips complex on vertices [0,2,4]):", lst2

print "Values:", [map(r.eval, lst)]
print "Sorted:", sorted(lst, r.cmp)

cofaces = []
r.vertex_cofaces(2, 1, 3, cofaces.append)
print "Cofaces of vertex 2:", cofaces

cofaces = []
r.vertex_cofaces(2, 1, 3, cofaces.append, [0,2,4])
print "Cofaces of vertex 2 on vertices [0,2,4]:", cofaces

f = Filtration(lst, r.cmp)
p = StaticPersistence(f)
p.pair_simplices()
for s in p:
print lst[f[p(s)]], s.sign()
```