TensorFlow layer for Vietoris-Rips persistence#

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 Vietoris-Rips persistence#

from gudhi.tensorflow import RipsLayer
import tensorflow as tf

X = tf.Variable([[1.,1.],[2.,2.]], dtype=tf.float32, trainable=True)
rl = RipsLayer(maximum_edge_length=2., homology_dimensions=[0])

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

grads = tape.gradient(loss, [X])
print(grads[0].numpy())
[[-0.5 -0.5]
 [ 0.5  0.5]]

Documentation for RipsLayer#

class gudhi.tensorflow.RipsLayer[source]#

Bases: Layer

TensorFlow layer for computing Rips persistence out of a point cloud

__init__(homology_dimensions, maximum_edge_length=inf, min_persistence=None, homology_coeff_field=11, **kwargs)[source]#

Constructor for the RipsLayer class

Parameters:
  • maximum_edge_length (float) – maximum edge length for the Rips complex

  • 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.

call(X)[source]#

Compute Rips persistence diagram associated to a point cloud

Parameters:

X (TensorFlow variable) – point cloud of shape [number of points, number of dimensions]

Returns:

List of Rips 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]]