TensorFlow layer for lower-star persistence on simplex trees#
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=) with tf.GradientTape() as tape: dgm = sl.call(F) loss = tf.math.reduce_sum(tf.square(.5*(dgm[:,1]-dgm[:,0]))) grads = tape.gradient(loss, [F]) print(grads.indices.numpy()) print(grads.values.numpy())
[2 4] [-1. 1.]
Documentation for LowerStarSimplexTreeLayer#
- class gudhi.tensorflow.LowerStarSimplexTreeLayer[source]#
TensorFlow layer for computing lower-star persistence out of a simplex tree
- __init__(simplextree, homology_dimensions, min_persistence=None, homology_coeff_field=11, **kwargs)[source]#
Constructor for the LowerStarSimplexTreeLayer class
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.
Compute lower-star persistence diagram associated to a function defined on the vertices of the simplex tree
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
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: