Skip to content

Commit

Permalink
Trac #34759: some details in filtered simplicial complexes
Browse files Browse the repository at this point in the history
- some pep8 changes
- fix details in documentation

URL: https://trac.sagemath.org/34759
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): John Palmieri
  • Loading branch information
Release Manager committed Nov 21, 2022
2 parents dfc299b + 71cc4e9 commit f41abf6
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/sage/topology/filtered_simplicial_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
from sage.rings.infinity import infinity
from sage.misc.cachefunc import cached_method


class FilteredSimplicialComplex(SageObject):
r"""
Define a filtered complex.
Expand Down Expand Up @@ -321,7 +322,7 @@ def filtration(self, s, filtration_value=None):
If ``filtration_value`` is set, this function inserts the
simplex into the complex with the specified value.
See documentation of ``insert`` for more details.
See documentation of :meth:`insert` for more details.
EXAMPLES::
Expand All @@ -338,7 +339,7 @@ def filtration(self, s, filtration_value=None):
else:
self._insert(s, filtration_value)

def prune(self,threshold):
def prune(self, threshold):
r"""
Return a copy of the filtered complex, where simplices above
the threshold value have been removed.
Expand Down Expand Up @@ -367,7 +368,7 @@ def prune(self,threshold):

return result_complex

@cached_method(key=lambda self,f,s,v:(f,s))
@cached_method(key=lambda self, f, s, v: (f, s))
def _persistent_homology(self, field=2, strict=True, verbose=False):
"""
Compute the homology intervals of the complex.
Expand Down Expand Up @@ -445,7 +446,7 @@ def key(s):
# Initialize data structures for the algo
self._marked = [False] * n
self._T = [None] * n
intervals = [[] for i in range(self._dimension+1)]
intervals = [[] for i in range(self._dimension + 1)]
self.pairs = []

self._strict = strict
Expand Down Expand Up @@ -491,7 +492,7 @@ def _add_interval(self, s, t, intervals):
Add a new interval (i.e. homology element).
This method should not be called by users, it is used in
the ``_compute_persistence`` method. The simplex of
the :meth:`_persistent_homology` method. The simplex of
death may be ``None``, in which case the interval is infinite.
INPUT:
Expand Down Expand Up @@ -544,7 +545,7 @@ def _remove_pivot_rows(self, s, simplices):
This method implements the subroutine of the same name
in [ZC2005]_. This method should not be called by users,
it is used in the ``compute_persistence`` method.
it is used in the :meth:`_persistent_homology` method.
TESTS::
Expand All @@ -565,11 +566,11 @@ def _remove_pivot_rows(self, s, simplices):
return d

# Initialize the boundary chain
for (i, f) in enumerate(s.faces()):
for i, f in enumerate(s.faces()):
d += (-1)**i * self._chaingroup(f)

# Remove all unmarked elements
for (s, x_s) in d:
for s, x_s in d:
j = self._index_of_simplex[s]
if not self._marked[j]:
d = d - x_s * self._chaingroup(s)
Expand All @@ -586,7 +587,7 @@ def _remove_pivot_rows(self, s, simplices):

c = self._T[max_index][1]
q = c[t]
d = d - ((q**(-1))*c)
d = d - ((q**(-1)) * c)

return d

Expand All @@ -595,8 +596,8 @@ def _max_index(self, d):
Return the maximal index of all simplices with nonzero
coefficient in ``d``.
This method is called in ``_remove_pivot_rows`` and
``compute_persistence``. It should not be called by users
This method is called in :meth:`_remove_pivot_rows` and
:meth:`_persistent_homology`. It should not be called by users
outside of those methods.
TESTS::
Expand All @@ -611,7 +612,7 @@ def _max_index(self, d):
6
"""
currmax = -1
for (s, x_s) in d:
for s, x_s in d:
j = self._index_of_simplex[s]
if j > currmax:
currmax = j
Expand Down Expand Up @@ -664,7 +665,7 @@ def betti_number(self, k, a, b, field=2, strict=True, verbose=None):
persistent homology computation; the default is the verbosity
of ``self``
The Betti number ``\beta_k^{a,a+b}`` counts the number of
The Betti number `\beta_k^{a,a+b}` counts the number of
homology elements which are alive throughout the whole
duration ``[a, a+b]``.
Expand All @@ -686,7 +687,7 @@ def betti_number(self, k, a, b, field=2, strict=True, verbose=None):
if verbose is None:
verbose = self._verbose
intervals = self._persistent_homology(field, strict, verbose=verbose)
return Integer(sum(1 for (i, j) in intervals[k]
return Integer(sum(1 for i, j in intervals[k]
if (i <= a and a + b < j) and a >= 0))

def _repr_(self):
Expand Down Expand Up @@ -720,7 +721,7 @@ def _repr_(self):

def _simplicial_(self):
"""
Return the associated simplicial complex
Return the associated simplicial complex.
All simplices of the filtered simplicial complex are
included in the resulting simplicial complex.
Expand Down

0 comments on commit f41abf6

Please sign in to comment.