summaryrefslogtreecommitdiff
path: root/src/python/doc/rips_complex_tflow_itf_ref.rst
blob: 3ce75868ae47cd2bc94bbf9ba25c25fd3f4a3b86 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
: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
-----------------------------------------------------------

.. testsetup::

    import numpy
    numpy.set_printoptions(precision=4)

.. testcode::

    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())

.. testcleanup::

    numpy.set_printoptions(precision=8)

.. testoutput::

    [[-0.5 -0.5]
     [ 0.5  0.5]]

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

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