From a303cc6b483d3cd958c399621e22e40574bcbbc8 Mon Sep 17 00:00:00 2001 From: Rémi Flamary Date: Tue, 21 Apr 2020 17:48:37 +0200 Subject: [MRG] Actually run sphinx-gallery (#146) * generate gallery * remove mock * add sklearn to requirermnt?txt for example * remove latex from fgw example * add networks for graph example * remove all * add requirement.txt rtd * rtd debug * update readme * eradthedoc with redirection * add conf rtd --- docs/source/auto_examples/plot_barycenter_1D.py | 160 ------------------------ 1 file changed, 160 deletions(-) delete mode 100644 docs/source/auto_examples/plot_barycenter_1D.py (limited to 'docs/source/auto_examples/plot_barycenter_1D.py') diff --git a/docs/source/auto_examples/plot_barycenter_1D.py b/docs/source/auto_examples/plot_barycenter_1D.py deleted file mode 100644 index 6864301..0000000 --- a/docs/source/auto_examples/plot_barycenter_1D.py +++ /dev/null @@ -1,160 +0,0 @@ -# -*- coding: utf-8 -*- -""" -============================== -1D Wasserstein barycenter demo -============================== - -This example illustrates the computation of regularized Wassersyein Barycenter -as proposed in [3]. - - -[3] Benamou, J. D., Carlier, G., Cuturi, M., Nenna, L., & Peyré, G. (2015). -Iterative Bregman projections for regularized transportation problems -SIAM Journal on Scientific Computing, 37(2), A1111-A1138. - -""" - -# Author: Remi Flamary -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot -# necessary for 3d plot even if not used -from mpl_toolkits.mplot3d import Axes3D # noqa -from matplotlib.collections import PolyCollection - -############################################################################## -# Generate data -# ------------- - -#%% parameters - -n = 100 # nb bins - -# bin positions -x = np.arange(n, dtype=np.float64) - -# Gaussian distributions -a1 = ot.datasets.make_1D_gauss(n, m=20, s=5) # m= mean, s= std -a2 = ot.datasets.make_1D_gauss(n, m=60, s=8) - -# creating matrix A containing all distributions -A = np.vstack((a1, a2)).T -n_distributions = A.shape[1] - -# loss matrix + normalization -M = ot.utils.dist0(n) -M /= M.max() - -############################################################################## -# Plot data -# --------- - -#%% plot the distributions - -pl.figure(1, figsize=(6.4, 3)) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') -pl.tight_layout() - -############################################################################## -# Barycenter computation -# ---------------------- - -#%% barycenter computation - -alpha = 0.2 # 0<=alpha<=1 -weights = np.array([1 - alpha, alpha]) - -# l2bary -bary_l2 = A.dot(weights) - -# wasserstein -reg = 1e-3 -bary_wass = ot.bregman.barycenter(A, M, reg, weights) - -pl.figure(2) -pl.clf() -pl.subplot(2, 1, 1) -for i in range(n_distributions): - pl.plot(x, A[:, i]) -pl.title('Distributions') - -pl.subplot(2, 1, 2) -pl.plot(x, bary_l2, 'r', label='l2') -pl.plot(x, bary_wass, 'g', label='Wasserstein') -pl.legend() -pl.title('Barycenters') -pl.tight_layout() - -############################################################################## -# Barycentric interpolation -# ------------------------- - -#%% barycenter interpolation - -n_alpha = 11 -alpha_list = np.linspace(0, 1, n_alpha) - - -B_l2 = np.zeros((n, n_alpha)) - -B_wass = np.copy(B_l2) - -for i in range(0, n_alpha): - alpha = alpha_list[i] - weights = np.array([1 - alpha, alpha]) - B_l2[:, i] = A.dot(weights) - B_wass[:, i] = ot.bregman.barycenter(A, M, reg, weights) - -#%% plot interpolation - -pl.figure(3) - -cmap = pl.cm.get_cmap('viridis') -verts = [] -zs = alpha_list -for i, z in enumerate(zs): - ys = B_l2[:, i] - verts.append(list(zip(x, ys))) - -ax = pl.gcf().gca(projection='3d') - -poly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list]) -poly.set_alpha(0.7) -ax.add_collection3d(poly, zs=zs, zdir='y') -ax.set_xlabel('x') -ax.set_xlim3d(0, n) -ax.set_ylabel('$\\alpha$') -ax.set_ylim3d(0, 1) -ax.set_zlabel('') -ax.set_zlim3d(0, B_l2.max() * 1.01) -pl.title('Barycenter interpolation with l2') -pl.tight_layout() - -pl.figure(4) -cmap = pl.cm.get_cmap('viridis') -verts = [] -zs = alpha_list -for i, z in enumerate(zs): - ys = B_wass[:, i] - verts.append(list(zip(x, ys))) - -ax = pl.gcf().gca(projection='3d') - -poly = PolyCollection(verts, facecolors=[cmap(a) for a in alpha_list]) -poly.set_alpha(0.7) -ax.add_collection3d(poly, zs=zs, zdir='y') -ax.set_xlabel('x') -ax.set_xlim3d(0, n) -ax.set_ylabel('$\\alpha$') -ax.set_ylim3d(0, 1) -ax.set_zlabel('') -ax.set_zlim3d(0, B_l2.max() * 1.01) -pl.title('Barycenter interpolation with Wasserstein') -pl.tight_layout() - -pl.show() -- cgit v1.2.3