Simplex tree reference manual¶

class
gudhi.
SimplexTree
¶ Bases:
object
The simplex tree is an efficient and flexible data structure for representing general (filtered) simplicial complexes. The data structure is described in JeanDaniel Boissonnat and Clément Maria. The Simplex Tree: An Efficient Data Structure for General Simplicial Complexes. Algorithmica, pages 1–22, 2014.
This class is a filtered, with keys, and non contiguous vertices version of the simplex tree.

__init__
()¶ SimplexTree constructor.

assign_filtration
()¶ This function assigns a new filtration value to a given Nsimplex.
 Parameters
Note
Beware that after this operation, the structure may not be a valid filtration anymore, a simplex could have a lower filtration value than one of its faces. Callers are responsible for fixing this (with more
assign_filtration()
ormake_filtration_non_decreasing()
for instance) before calling any function that relies on the filtration property, likepersistence()
.

betti_numbers
()¶ This function returns the Betti numbers of the simplicial complex.
 Returns
The Betti numbers ([B0, B1, …, Bn]).
 Return type
list of int
 Note
betti_numbers function requires
compute_persistence()
function to be launched first.

collapse_edges
()¶ Assuming the simplex tree is a 1skeleton graph, this method collapse edges (simplices of higher dimension are ignored) and resets the simplex tree from the remaining edges. A good candidate is to build a simplex tree on top of a
RipsComplex
of dimension 1 before collapsing edges (cf.rips_complex_edge_collapse_example.py
). For implementation details, please refer to [6]. Parameters
nb_iterations¶ (int) – The number of edge collapse iterations to perform. Default is 1.

compute_persistence
()¶ This function computes the persistence of the simplicial complex, so it can be accessed through
persistent_betti_numbers()
,persistence_pairs()
, etc. This function is equivalent topersistence()
when you do not want the listpersistence()
returns. Parameters
homology_coeff_field¶ (int) – The homology coefficient field. Must be a prime number. Default value is 11.
min_persistence¶ (float) – The minimum persistence value to take into account (strictly greater than min_persistence). Default value is 0.0. Sets min_persistence to 1.0 to see all values.
persistence_dim_max¶ (bool) – If true, the persistent homology for the maximal dimension in the complex is computed. If false, it is ignored. Default is false.
 Returns
Nothing.

dimension
()¶ This function returns the dimension of the simplicial complex.
 Returns
the simplicial complex dimension.
 Return type
int
Note
This function is not constant time because it can recompute dimension if required (can be triggered by
remove_maximal_simplex()
orprune_above_filtration()
methods).

expansion
()¶ Expands the Simplex_tree containing only its one skeleton until dimension max_dim.
The expanded simplicial complex until dimension \(d\) attached to a graph \(G\) is the maximal simplicial complex of dimension at most \(d\) admitting the graph \(G\) as \(1\)skeleton. The filtration value assigned to a simplex is the maximal filtration value of one of its edges.
The Simplex_tree must contain no simplex of dimension bigger than 1 when calling the method.
 Parameters
max_dim¶ (int) – The maximal dimension.

extend_filtration
()¶ Extend filtration for computing extended persistence. This function only uses the filtration values at the 0dimensional simplices, and computes the extended persistence diagram induced by the lowerstar filtration computed with these values.
Note
Note that after calling this function, the filtration values are actually modified within the Simplex_tree. The function
extended_persistence()
retrieves the original values.Note
Note that this code creates an extra vertex internally, so you should make sure that the Simplex_tree does not contain a vertex with the largest possible value (i.e., 4294967295).

extended_persistence
()¶ This function retrieves good values for extended persistence, and separate the diagrams into the Ordinary, Relative, Extended+ and Extended subdiagrams.
 Parameters
homology_coeff_field¶ (int) – The homology coefficient field. Must be a prime number. Default value is 11.
min_persistence¶ (float) – The minimum persistence value (i.e., the absolute value of the difference between the persistence diagram point coordinates) to take into account (strictly greater than min_persistence). Default value is 0.0. Sets min_persistence to 1.0 to see all values.
 Returns
A list of four persistence diagrams in the format described in
persistence()
. The first one is Ordinary, the second one is Relative, the third one is Extended+ and the fourth one is Extended. See https://link.springer.com/article/10.1007/s102080089027z and/or section 2.2 in https://link.springer.com/article/10.1007/s102080179370z for a description of these subtypes.
Note
This function should be called only if
extend_filtration()
has been called first!Note
The coordinates of the persistence diagram points might be a little different than the original filtration values due to the internal transformation (scaling to [2,1]) that is performed on these values during the computation of extended persistence.

filtration
()¶ This function returns the filtration value for a given Nsimplex in this simplicial complex, or +infinity if it is not in the complex.
 Parameters
simplex¶ (list of int) – The Nsimplex, represented by a list of vertex.
 Returns
The simplicial complex filtration value.
 Return type
float

find
()¶ This function returns if the Nsimplex was found in the simplicial complex or not.
 Parameters
simplex¶ (list of int) – The Nsimplex to find, represented by a list of vertex.
 Returns
true if the simplex was found, false otherwise.
 Return type
bool

flag_persistence_generators
()¶ Assuming this is a flag complex, this function returns the persistence pairs, where each simplex is replaced with the vertices of the edges that gave it its filtration value.
 Returns
First the regular persistence pairs of dimension 0, with one vertex for birth and two for death; then the other regular persistence pairs, grouped by dimension, with 2 vertices per extremity; then the connected components, with one vertex each; finally the other essential features, grouped by dimension, with 2 vertices for birth.
 Return type
Tuple[numpy.array[int] of shape (n,3), List[numpy.array[int] of shape (m,4)], numpy.array[int] of shape (l,), List[numpy.array[int] of shape (k,2)]]
 Note
flag_persistence_generators requires that persistence() be called first.

get_cofaces
()¶ This function returns the cofaces of a given Nsimplex with a given codimension.
 Parameters
 Returns
The (simplices of the) cofaces of a simplex
 Return type
list of tuples(simplex, filtration)

get_filtration
()¶ This function returns a generator with simplices and their given filtration values sorted by increasing filtration values.
 Returns
The simplices sorted by increasing filtration values.
 Return type
generator with tuples(simplex, filtration)

get_simplices
()¶ This function returns a generator with simplices and their given filtration values.
 Returns
The simplices.
 Return type
generator with tuples(simplex, filtration)

get_skeleton
()¶ This function returns a generator with the (simplices of the) skeleton of a maximum given dimension.
 Parameters
dimension¶ (int) – The skeleton dimension value.
 Returns
The (simplices of the) skeleton of a maximum dimension.
 Return type
generator with tuples(simplex, filtration)

get_star
()¶ This function returns the star of a given Nsimplex.
 Parameters
simplex¶ (list of int) – The Nsimplex, represented by a list of vertex.
 Returns
The (simplices of the) star of a simplex.
 Return type
list of tuples(simplex, filtration)

initialize_filtration
()¶ This function initializes and sorts the simplicial complex filtration vector.
Deprecated since version 3.2.0.

insert
()¶ This function inserts the given Nsimplex and its subfaces with the given filtration value (default value is ‘0.0’). If some of those simplices are already present with a higher filtration value, their filtration value is lowered.

lower_star_persistence_generators
()¶ Assuming this is a lowerstar filtration, this function returns the persistence pairs, where each simplex is replaced with the vertex that gave it its filtration value.
 Returns
First the regular persistence pairs, grouped by dimension, with one vertex per extremity, and second the essential features, grouped by dimension, with one vertex each
 Return type
Tuple[List[numpy.array[int] of shape (n,2)], List[numpy.array[int] of shape (m,)]]
 Note
lower_star_persistence_generators requires that persistence() be called first.

make_filtration_non_decreasing
()¶ This function ensures that each simplex has a higher filtration value than its faces by increasing the filtration values.
 Returns
True if any filtration value was modified, False if the filtration was already nondecreasing.
 Return type
bool

num_simplices
()¶ This function returns the number of simplices of the simplicial complex.
 Returns
the simplicial complex number of simplices.
 Return type
int

num_vertices
()¶ This function returns the number of vertices of the simplicial complex.
 Returns
The simplicial complex number of vertices.
 Return type
int

persistence
()¶ This function computes and returns the persistence of the simplicial complex.
 Parameters
homology_coeff_field¶ (int) – The homology coefficient field. Must be a prime number. Default value is 11.
min_persistence¶ (float) – The minimum persistence value to take into account (strictly greater than min_persistence). Default value is 0.0. Set min_persistence to 1.0 to see all values.
persistence_dim_max¶ (bool) – If true, the persistent homology for the maximal dimension in the complex is computed. If false, it is ignored. Default is false.
 Returns
The persistence of the simplicial complex.
 Return type
list of pairs(dimension, pair(birth, death))

persistence_intervals_in_dimension
()¶ This function returns the persistence intervals of the simplicial complex in a specific dimension.
 Parameters
dimension¶ (int) – The specific dimension.
 Returns
The persistence intervals.
 Return type
numpy array of dimension 2
 Note
intervals_in_dim function requires
compute_persistence()
function to be launched first.

persistence_pairs
()¶ This function returns a list of persistence birth and death simplices pairs.
 Returns
A list of persistence simplices intervals.
 Return type
list of pair of list of int
 Note
persistence_pairs function requires
compute_persistence()
function to be launched first.

persistent_betti_numbers
()¶ This function returns the persistent Betti numbers of the simplicial complex.
 Parameters
 Returns
The persistent Betti numbers ([B0, B1, …, Bn]).
 Return type
list of int
 Note
persistent_betti_numbers function requires
compute_persistence()
function to be launched first.

prune_above_filtration
()¶ Prune above filtration value given as parameter.
 Parameters
filtration¶ (float) – Maximum threshold value.
 Returns
The filtration modification information.
 Return type
bool
Note
Note that the dimension of the simplicial complex may be lower after calling
prune_above_filtration()
than it was before. However,upper_bound_dimension()
will return the old value, which remains a valid upper bound. If you care, you can calldimension()
method to recompute the exact dimension.

remove_maximal_simplex
()¶ This function removes a given maximal Nsimplex from the simplicial complex.
 Parameters
simplex¶ (list of int) – The Nsimplex, represented by a list of vertex.
Note
The dimension of the simplicial complex may be lower after calling remove_maximal_simplex than it was before. However,
upper_bound_dimension()
method will return the old value, which remains a valid upper bound. If you care, you can calldimension()
to recompute the exact dimension.

set_dimension
()¶ This function sets the dimension of the simplicial complex.
 Parameters
dimension¶ (int) – The new dimension value.
Note
This function must be used with caution because it disables dimension recomputation when required (this recomputation can be triggered by
remove_maximal_simplex()
orprune_above_filtration()
).

upper_bound_dimension
()¶ This function returns a valid dimension upper bound of the simplicial complex.
 Returns
an upper bound on the dimension of the simplicial complex.
 Return type
int

write_persistence_diagram
()¶ This function writes the persistence intervals of the simplicial complex in a user given file name.
 Parameters
persistence_file¶ (string) – Name of the file.
 Note
intervals_in_dim function requires
compute_persistence()
function to be launched first.
