summaryrefslogtreecommitdiff
path: root/examples/plot_gromov.py
diff options
context:
space:
mode:
authorRémi Flamary <remi.flamary@gmail.com>2017-09-15 13:57:01 +0200
committerRémi Flamary <remi.flamary@gmail.com>2017-09-15 13:57:01 +0200
commitdd3546baf9c59733b2109a971293eba48d2eaed3 (patch)
treedbc9c5dd126eecf537acbe7d205b91250f2bdc9b /examples/plot_gromov.py
parentbad3d95523d005a4fbf64dd009c716b9dd560fe3 (diff)
add all files for doc
Diffstat (limited to 'examples/plot_gromov.py')
-rw-r--r--examples/plot_gromov.py40
1 files changed, 21 insertions, 19 deletions
diff --git a/examples/plot_gromov.py b/examples/plot_gromov.py
index 5132024..d3f724c 100644
--- a/examples/plot_gromov.py
+++ b/examples/plot_gromov.py
@@ -20,13 +20,14 @@ from mpl_toolkits.mplot3d import Axes3D # noqa
import ot
-"""
-Sample two Gaussian distributions (2D and 3D)
-=============================================
-The Gromov-Wasserstein distance allows to compute distances with samples that
-do not belong to the same metric space. For demonstration purpose, we sample
-two Gaussian distributions in 2- and 3-dimensional spaces.
-"""
+##############################################################################
+# Sample two Gaussian distributions (2D and 3D)
+# ---------------------------------------------
+#
+# The Gromov-Wasserstein distance allows to compute distances with samples that
+# do not belong to the same metric space. For demonstration purpose, we sample
+# two Gaussian distributions in 2- and 3-dimensional spaces.
+
n_samples = 30 # nb samples
@@ -42,10 +43,11 @@ P = sp.linalg.sqrtm(cov_t)
xt = np.random.randn(n_samples, 3).dot(P) + mu_t
-"""
-Plotting the distributions
-==========================
-"""
+##############################################################################
+# Plotting the distributions
+# --------------------------
+
+
fig = pl.figure()
ax1 = fig.add_subplot(121)
ax1.plot(xs[:, 0], xs[:, 1], '+b', label='Source samples')
@@ -54,10 +56,10 @@ ax2.scatter(xt[:, 0], xt[:, 1], xt[:, 2], color='r')
pl.show()
-"""
-Compute distance kernels, normalize them and then display
-=========================================================
-"""
+##############################################################################
+# Compute distance kernels, normalize them and then display
+# ---------------------------------------------------------
+
C1 = sp.spatial.distance.cdist(xs, xs)
C2 = sp.spatial.distance.cdist(xt, xt)
@@ -72,10 +74,10 @@ pl.subplot(122)
pl.imshow(C2)
pl.show()
-"""
-Compute Gromov-Wasserstein plans and distance
-=============================================
-"""
+##############################################################################
+# Compute Gromov-Wasserstein plans and distance
+# ---------------------------------------------
+
p = ot.unif(n_samples)
q = ot.unif(n_samples)