summaryrefslogtreecommitdiff
path: root/src/python/doc/rips_complex_tflow_itf_ref.rst
blob: 15ba4c8e85c18507d9ea9ff8576a52608a60d86a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
:orphan:

.. To get rid of WARNING: document isn't included in any toctree

TensorFlow layer for Vietoris-Rips persistence
##############################################

.. include:: differentiation_sum.inc

Example of gradient computed from Vietoris-Rips persistence
-----------------------------------------------------------

.. code-block:: python

    from gudhi.tensorflow import *
    import numpy as np
    import tensorflow as tf

    Xinit = np.array([[1.,1.],[2.,2.]], dtype=np.float32)
    X = tf.Variable(initial_value=Xinit, trainable=True)
    rl = RipsLayer(maximum_edge_length=2., dimension=0)

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

Documentation for RipsLayer
---------------------------

.. autoclass:: gudhi.tensorflow.RipsLayer
   :members:
   :special-members: __init__
   :show-inheritance: