doc/examples/triangle-zigzag.rst
author Aravindakshan Babu <akshan@stanford.edu>
Thu, 08 Jul 2010 23:50:39 -0700
branchdev
changeset 217 64a272a34cb2
parent 134 c270826fd4a8
permissions -rw-r--r--
Added extra functionality to Point class( an iterator ) and PersistenceDiagram( dimension property and __len__ func ). persistence-diagram.h: Added a new read-only dimension member and member function to access it. With a new constructor that that takes in an int type to initialize dimension. persistence-diagram.cpp: Added new bp::init constructor. Takes in an integer type to initialize the dimension. Exposed the dimension property. Exposed the size property via a __len__ method. __init__.py: Added an iterator for Point objects. This iterates over the coords and then the data( if present ).

.. _triangle-zigzag-example:

Triangle zigzag example
=======================

Simple example of a filtered triangle where simplices are first inserted in a
given order, and then removed in the reverse order is in
:sfile:`examples/triangle/triangle-zigzag.cpp`. Its Python equivalent
(:sfile:`examples/triangle/triangle-zigzag.py`) is described next.

.. literalinclude:: ../../examples/triangle/triangle-zigzag.py
   :language: python

Unlike the :ref:`triangle-example`, here we use :class:`ZigzagPersistence` to
compute the pairings, and therefore need to store the internal representations
of the simplicies used by the class. These representation are stored in the
dictionary ``complex``, which maps the simplices to their representations for
:class:`ZigzagPersistence`.

The first for loop processes the simplices sorted with respect to
:func:`data_cmp`. :meth:`ZigzagPersistence.add` invoked within the loop accepts
the boundary of the newly added cell in its internal representation, which is
computed by looking up each simplex in the dictionary ``complex``:
``[complex[ss] for ss in s.boundary]``. If there is a birth, the value to be
associated with the newly created class is ``b`` (which in this case is simply a
counter).  :meth:`~ZigzagPersistence.add` returns a pair ``(i,d)``. The former
is an internal representation of the newly added cell, which we immediately
record with ``complex[s] = i``. The latter is an indicator of whether a death
has occurred, which happens iff ``d is not None``, in which case ``d`` is the
birth value passed to :meth:`~ZigzagPersistence.add` whenever the class that
just died was born. If the death occurred, then we outut the interval ``(d,
b-1)``.

The second for loop removes simplices in the reverse order of their insertion.
:meth:`~ZigzagPersistence.remove` takes the index of the cells to be removed
(looked up in the ``complex`` dictionary: ``complex[s]``), and takes a birth
value in case a class is born. It return only a death indicator (which again is
``None`` if no death occurred).