TensorFlow layer for cubical 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 cubical persistence#

from gudhi.tensorflow import CubicalLayer
import tensorflow as tf

X = tf.Variable([[0.,2.,2.],[2.,2.,2.],[2.,2.,1.]], dtype=tf.float32, trainable=True)
cl = CubicalLayer(homology_dimensions=[0])

with tf.GradientTape() as tape:
    dgm = cl.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.   0.   0. ]
 [ 0.   0.5  0. ]
 [ 0.   0.  -0.5]]

Documentation for CubicalLayer#

class gudhi.tensorflow.CubicalLayer[source]#

Bases: Layer

TensorFlow layer for computing the persistent homology of a cubical complex

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

Constructor for the CubicalLayer class

Parameters:
  • 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 persistence diagram associated to a cubical complex filtered by some pixel values

Parameters:

X (TensorFlow variable) – pixel values of the cubical complex

Returns:

List of cubical 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. Note that the essential part is always empty in cubical persistence diagrams, except in homology dimension zero, where the essential part always contains a single point, with abscissa equal to the smallest value in the complex, and infinite ordinate

Return type:

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