summaryrefslogtreecommitdiff
path: root/docs/source/auto_examples/plot_barycenter_fgw.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/source/auto_examples/plot_barycenter_fgw.rst')
-rw-r--r--docs/source/auto_examples/plot_barycenter_fgw.rst110
1 files changed, 81 insertions, 29 deletions
diff --git a/docs/source/auto_examples/plot_barycenter_fgw.rst b/docs/source/auto_examples/plot_barycenter_fgw.rst
index 2c44a65..ad4c275 100644
--- a/docs/source/auto_examples/plot_barycenter_fgw.rst
+++ b/docs/source/auto_examples/plot_barycenter_fgw.rst
@@ -1,6 +1,12 @@
+.. only:: html
+
+ .. note::
+ :class: sphx-glr-download-link-note
+ Click :ref:`here <sphx_glr_download_auto_examples_plot_barycenter_fgw.py>` to download the full example code
+ .. rst-class:: sphx-glr-example-title
-.. _sphx_glr_auto_examples_plot_barycenter_fgw.py:
+ .. _sphx_glr_auto_examples_plot_barycenter_fgw.py:
=================================
@@ -18,15 +24,23 @@ Requires networkx >=2
-
-.. code-block:: python
+.. code-block:: default
# Author: Titouan Vayer <titouan.vayer@irisa.fr>
#
# License: MIT License
- #%% load libraries
+
+
+
+
+
+
+
+
+.. code-block:: default
+
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
@@ -35,7 +49,16 @@ Requires networkx >=2
import matplotlib.colors as mcol
from matplotlib import cm
from ot.gromov import fgw_barycenters
- #%% Graph functions
+
+
+
+
+
+
+
+
+.. code-block:: default
+
def find_thresh(C, inf=0.5, sup=3, step=10):
@@ -138,17 +161,16 @@ Requires networkx >=2
+
Generate data
-------------
+We build a dataset of noisy circular graphs.
+Noise is added on the structures by random connections and on the features by gaussian noise.
-.. code-block:: python
-
+.. code-block:: default
- #%% circular dataset
- # We build a dataset of noisy circular graphs.
- # Noise is added on the structures by random connections and on the features by gaussian noise.
np.random.seed(30)
@@ -162,15 +184,13 @@ Generate data
+
Plot data
---------
+.. code-block:: default
-.. code-block:: python
-
-
- #%% Plot graphs
plt.figure(figsize=(8, 10))
for i in range(len(X0)):
@@ -185,7 +205,17 @@ Plot data
.. image:: /auto_examples/images/sphx_glr_plot_barycenter_fgw_001.png
- :align: center
+ :class: sphx-glr-single-img
+
+
+.. rst-class:: sphx-glr-script-out
+
+ Out:
+
+ .. code-block:: none
+
+ /home/rflamary/PYTHON/POT/examples/plot_barycenter_fgw.py:155: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
+ plt.show()
@@ -193,13 +223,11 @@ Plot data
Barycenter computation
----------------------
+Features distances are the euclidean distances
-.. code-block:: python
+.. code-block:: default
-
- #%% We compute the barycenter using FGW. Structure matrices are computed using the shortest_path distance in the graph
- # Features distances are the euclidean distances
Cs = [shortest_path(nx.adjacency_matrix(x)) for x in X0]
ps = [np.ones(len(x.nodes())) / len(x.nodes()) for x in X0]
Ys = [np.array([v for (k, v) in nx.get_node_attributes(x, 'attr_name').items()]).reshape(-1, 1) for x in X0]
@@ -214,20 +242,27 @@ Barycenter computation
+
Plot Barycenter
-------------------------
+.. code-block:: default
-.. code-block:: python
-
-
- #%% Create the barycenter
bary = nx.from_numpy_matrix(sp_to_adjency(C, threshinf=0, threshsup=find_thresh(C, sup=100, step=100)[0]))
for i, v in enumerate(A.ravel()):
bary.add_node(i, attr_name=v)
- #%%
+
+
+
+
+
+
+
+
+.. code-block:: default
+
pos = nx.kamada_kawai_layout(bary)
nx.draw(bary, pos=pos, node_color=graph_colors(bary, vmin=-1, vmax=1), with_labels=False)
plt.suptitle('Barycenter', fontsize=20)
@@ -236,27 +271,44 @@ Plot Barycenter
.. image:: /auto_examples/images/sphx_glr_plot_barycenter_fgw_002.png
- :align: center
+ :class: sphx-glr-single-img
+
+
+.. rst-class:: sphx-glr-script-out
+
+ Out:
+ .. code-block:: none
+ /home/rflamary/PYTHON/POT/examples/plot_barycenter_fgw.py:184: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
+ plt.show()
-**Total running time of the script:** ( 0 minutes 2.065 seconds)
+.. rst-class:: sphx-glr-timing
+
+ **Total running time of the script:** ( 0 minutes 1.949 seconds)
+
+
+.. _sphx_glr_download_auto_examples_plot_barycenter_fgw.py:
+
+
.. only :: html
.. container:: sphx-glr-footer
+ :class: sphx-glr-footer-example
+
- .. container:: sphx-glr-download
+ .. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: plot_barycenter_fgw.py <plot_barycenter_fgw.py>`
- .. container:: sphx-glr-download
+ .. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_barycenter_fgw.ipynb <plot_barycenter_fgw.ipynb>`
@@ -265,4 +317,4 @@ Plot Barycenter
.. rst-class:: sphx-glr-signature
- `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
+ `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_