summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieuCarriere <mathieu.carriere3@gmail.com>2022-11-20 22:10:37 +0100
committerMathieuCarriere <mathieu.carriere3@gmail.com>2022-11-20 22:10:37 +0100
commit8e6c8ac6d6acc818d60cbc15a13af763a36ad03a (patch)
tree8c538e755e569093aed0b6495a539baf823f60f8
parentcf559f6a9ba4c3b8d9fc11111ffd73797769dd46 (diff)
parentdd07d34e91cdfecd539ddc6afa22992fa12d38c6 (diff)
Merge branch 'perslay' of https://github.com/MathieuCarriere/gudhi into perslay
-rw-r--r--src/python/doc/installation.rst14
-rw-r--r--src/python/doc/representations.rst120
2 files changed, 85 insertions, 49 deletions
diff --git a/src/python/doc/installation.rst b/src/python/doc/installation.rst
index c0077e89..7200b2f0 100644
--- a/src/python/doc/installation.rst
+++ b/src/python/doc/installation.rst
@@ -371,14 +371,6 @@ PyTorch
`PyTorch <https://pytorch.org/>`_ is currently only used as a dependency of
`PyKeOps`_, and in some tests.
-TensorFlow
-----------
-
-:class:`~gudhi.tensorflow.perslay` from the :doc:`persistence representations </representations>` module
-requires `TensorFlow <https://https://www.tensorflow.org/install/>`_.
-
-`TensorFlow <https://www.tensorflow.org>`_ is also used in some automatic differentiation tests.
-
Scikit-learn
------------
@@ -404,11 +396,13 @@ mathematics, science, and engineering.
TensorFlow
----------
+:class:`~gudhi.tensorflow.perslay.Perslay` from the :doc:`persistence representations </representations>` module
+requires `TensorFlow <https://www.tensorflow.org/>`_.
The :doc:`cubical complex </cubical_complex_tflow_itf_ref>`, :doc:`simplex tree </ls_simplex_tree_tflow_itf_ref>`
-and :doc:`Rips complex </rips_complex_tflow_itf_ref>` modules require `TensorFlow <https://www.tensorflow.org>`_
+and :doc:`Rips complex </rips_complex_tflow_itf_ref>` modules require `TensorFlow`_
for incorporating them in neural nets.
-`TensorFlow <https://www.tensorflow.org>`_ is also used in some automatic differentiation tests.
+`TensorFlow`_ is also used in some automatic differentiation tests.
Bug reports and contributions
*****************************
diff --git a/src/python/doc/representations.rst b/src/python/doc/representations.rst
index 2d66fa68..37d3aa53 100644
--- a/src/python/doc/representations.rst
+++ b/src/python/doc/representations.rst
@@ -8,14 +8,14 @@ Representations manual
.. include:: representations_sum.inc
-This module aims at bridging the gap between persistence diagrams and machine learning, by providing implementations of most of the vector representations for persistence diagrams in the literature, in a scikit-learn format. More specifically, it provides tools, using the scikit-learn standard interface, to compute distances and kernels on persistence diagrams, and to convert these diagrams into vectors in Euclidean space. Moreover, this module also contains `PersLay <http://proceedings.mlr.press/v108/carriere20a.html>`_, which is a general neural network layer for performing deep learning with persistence diagrams, implemented in TensorFlow.
+This module aims at bridging the gap between persistence diagrams and machine learning, by providing implementations of most of the vector representations for persistence diagrams in the literature, in a scikit-learn format. More specifically, it provides tools, using the scikit-learn standard interface, to compute distances and kernels on persistence diagrams, and to convert these diagrams into vectors in Euclidean space. Moreover, this module also contains `PersLay <http://proceedings.mlr.press/v108/carriere20a.html>`_, which is a general neural network layer for performing deep learning with persistence diagrams, implemented in TensorFlow.
A diagram is represented as a numpy array of shape (n,2), as can be obtained from :func:`~gudhi.SimplexTree.persistence_intervals_in_dimension` for instance. Points at infinity are represented as a numpy array of shape (n,1), storing only the birth time. The classes in this module can handle several persistence diagrams at once. In that case, the diagrams are provided as a list of numpy arrays. Note that it is not necessary for the diagrams to have the same number of points, i.e., for the corresponding arrays to have the same number of rows: all classes can handle arrays with different shapes.
-This `notebook <https://github.com/GUDHI/TDA-tutorial/blob/master/Tuto-GUDHI-representations.ipynb>`_ explains how to
+This `notebook <https://github.com/GUDHI/TDA-tutorial/blob/master/Tuto-GUDHI-representations.ipynb>`__ explains how to
efficiently combine machine learning and topological data analysis with the
-:doc:`representations module<representations>` in a scikit-learn fashion. This `notebook <https://github.com/MathieuCarriere/tda-tutorials/blob/perslay/Tuto-GUDHI-perslay-expe.ipynb>`_
-and `this one <https://github.com/MathieuCarriere/tda-tutorials/blob/perslay/Tuto-GUDHI-perslay-visu.ipynb>`_ explain how to use PersLay.
+:doc:`representations module<representations>` in a scikit-learn fashion. This `notebook <https://github.com/MathieuCarriere/tda-tutorials/blob/perslay/Tuto-GUDHI-perslay-expe.ipynb>`__
+and `this one <https://github.com/MathieuCarriere/tda-tutorials/blob/perslay/Tuto-GUDHI-perslay-visu.ipynb>`__ explain how to use PersLay.
Examples
@@ -52,7 +52,12 @@ This small example is also provided
PersLay
^^^^^^^
-.. testcode::
+.. testsetup:: perslay
+
+ import numpy
+ numpy.set_printoptions(precision=5)
+
+.. testcode:: perslay
import numpy as np
import tensorflow as tf
@@ -64,47 +69,51 @@ PersLay
diagrams = gdr.DiagramScaler(use=True, scalers=[([0,1], MinMaxScaler())]).fit_transform(diagrams)
diagrams = tf.RaggedTensor.from_tensor(tf.constant(diagrams, dtype=tf.float32))
- rho = tf.identity
- phi = gdtf.GaussianPerslayPhi((100, 100), ((-.5, 1.5), (-.5, 1.5)), .1)
+ rho = tf.identity
+ phi = gdtf.GaussianPerslayPhi((5, 5), ((-.5, 1.5), (-.5, 1.5)), .1)
weight = gdtf.PowerPerslayWeight(1.,0.)
perm_op = tf.math.reduce_sum
-
+
perslay = gdtf.Perslay(phi=phi, weight=weight, perm_op=perm_op, rho=rho)
vectors = perslay(diagrams)
print(vectors)
-.. testoutput::
+.. testcleanup:: perslay
+
+ numpy.set_printoptions(precision=8)
+
+.. testoutput:: perslay
tf.Tensor(
- [[[[1.7266072e-16]
- [4.1706043e-09]
- [1.1336876e-08]
- [8.5738821e-12]
- [2.1243891e-14]]
-
- [[4.1715076e-09]
- [1.0074080e-01]
- [2.7384272e-01]
- [3.0724244e-02]
- [7.6157507e-05]]
-
- [[8.0382870e-06]
- [1.5802664e+00]
- [8.2997030e-01]
- [1.2395413e+01]
- [3.0724116e-02]]
-
- [[8.0269419e-06]
- [1.3065740e+00]
- [9.0923014e+00]
- [6.1664842e-02]
- [1.3949171e-06]]
-
- [[9.0331329e-13]
- [1.4954816e-07]
- [1.5145997e-04]
- [1.0205092e-06]
- [7.8093526e-16]]]], shape=(1, 5, 5, 1), dtype=float32)
+ [[[[1.72661e-16]
+ [4.17060e-09]
+ [1.13369e-08]
+ [8.57388e-12]
+ [2.12439e-14]]
+
+ [[4.17151e-09]
+ [1.00741e-01]
+ [2.73843e-01]
+ [3.07242e-02]
+ [7.61575e-05]]
+
+ [[8.03829e-06]
+ [1.58027e+00]
+ [8.29970e-01]
+ [1.23954e+01]
+ [3.07241e-02]]
+
+ [[8.02694e-06]
+ [1.30657e+00]
+ [9.09230e+00]
+ [6.16648e-02]
+ [1.39492e-06]]
+
+ [[9.03313e-13]
+ [1.49548e-07]
+ [1.51460e-04]
+ [1.02051e-06]
+ [7.80935e-16]]]], shape=(1, 5, 5, 1), dtype=float32)
Preprocessing
-------------
@@ -136,8 +145,41 @@ Metrics
PersLay
-------
-.. automodule:: gudhi.tensorflow.perslay
+.. autoclass:: gudhi.tensorflow.Perslay
+ :members:
+ :special-members:
+ :show-inheritance:
+
+Weight functions
+^^^^^^^^^^^^^^^^
+.. autoclass:: gudhi.tensorflow.GaussianMixturePerslayWeight
+ :members:
+ :special-members:
+ :show-inheritance:
+
+.. autoclass:: gudhi.tensorflow.GridPerslayWeight
:members:
:special-members:
:show-inheritance:
+.. autoclass:: gudhi.tensorflow.PowerPerslayWeight
+ :members:
+ :special-members:
+ :show-inheritance:
+
+Phi functions
+^^^^^^^^^^^^^
+.. autoclass:: gudhi.tensorflow.FlatPerslayPhi
+ :members:
+ :special-members:
+ :show-inheritance:
+
+.. autoclass:: gudhi.tensorflow.GaussianPerslayPhi
+ :members:
+ :special-members:
+ :show-inheritance:
+
+.. autoclass:: gudhi.tensorflow.TentPerslayPhi
+ :members:
+ :special-members:
+ :show-inheritance: