TensorFlow layer for lower-star persistence on simplex trees#

Since:

GUDHI 3.6.0

License:

MIT

Requires:

TensorFlow

We provide TensorFlow 2 models that can handle automatic differentiation for the computation of persistence diagrams from complexes available in the Gudhi library. This includes simplex trees, cubical complexes and Vietoris-Rips complexes. Detailed example on how to use these layers in practice are available in the following notebook. Note that even if TensorFlow GPU is enabled, all internal computations using Gudhi will be done on CPU.

Example of gradient computed from lower-star filtration of a simplex tree#

from gudhi.tensorflow import LowerStarSimplexTreeLayer
import tensorflow as tf
import gudhi as gd

st = gd.SimplexTree()
st.insert([0, 1])
st.insert([1, 2])
st.insert([2, 3])
st.insert([3, 4])
st.insert([4, 5])
st.insert([5, 6])
st.insert([6, 7])
st.insert([7, 8])
st.insert([8, 9])
st.insert([9, 10])

F = tf.Variable([6.,4.,3.,4.,5.,4.,3.,2.,3.,4.,5.], dtype=tf.float32, trainable=True)
sl = LowerStarSimplexTreeLayer(simplextree=st, homology_dimensions=[0])

with tf.GradientTape() as tape:
    dgm = sl.call(F)[0][0]
    loss = tf.math.reduce_sum(tf.square(.5*(dgm[:,1]-dgm[:,0])))

grads = tape.gradient(loss, [F])
print(grads[0].indices.numpy())
print(grads[0].values.numpy())
[2 4]
[-1.  1.]

Documentation for LowerStarSimplexTreeLayer#

class gudhi.tensorflow.LowerStarSimplexTreeLayer[source]#

Bases: Layer

TensorFlow layer for computing lower-star persistence out of a simplex tree

__init__(simplextree, homology_dimensions, min_persistence=None, homology_coeff_field=11, persistence_dim_max=False, **kwargs)[source]#

Constructor for the LowerStarSimplexTreeLayer class

Parameters:
  • simplextree (gudhi.SimplexTree) – underlying simplex tree. Its vertices MUST be named with integers from 0 to n-1, where n is its number of vertices. Note that its filtration values are modified in each call of the class.

  • homology_dimensions (List[int]) – list of homology dimensions

  • min_persistence (List[float]) – minimum distance-to-diagonal of the points in the output persistence diagrams (default None, in which case 0. is used for all dimensions)

  • homology_coeff_field (int) – homology field coefficient. Must be a prime number. Default value is 11. Max is 46337.

  • persistence_dim_max (bool) – if true, the persistent homology for the maximal dimension in the simplex tree is computed. If false, it is ignored. Default is false.

call(filtration)[source]#

Compute lower-star persistence diagram associated to a function defined on the vertices of the simplex tree

Parameters:

F (TensorFlow variable) – filter function values over the vertices of the simplex tree. The ith entry of F corresponds to vertex i in self.simplextree

Returns:

List of lower-star persistence diagrams. The length of this list is the same than that of dimensions, i.e., there is one persistence diagram per homology dimension provided in the input list dimensions. Moreover, the finite and essential parts of the persistence diagrams are provided separately: each element of this list is a tuple of size two that contains the finite and essential parts of the corresponding persistence diagram, of shapes [num_finite_points, 2] and [num_essential_points, 1] respectively

Return type:

List[Tuple[tf.Tensor,tf.Tensor]]