diff options
author | Gard Spreemann <gspr@nonempty.org> | 2020-07-09 08:50:11 +0200 |
---|---|---|
committer | Gard Spreemann <gspr@nonempty.org> | 2020-07-09 08:50:11 +0200 |
commit | 616c6039614e96b6cfd88eb7db25ce11c7302c30 (patch) | |
tree | a745ec24604f660b256dbaee214affa497c9c21e /docs/source/auto_examples/plot_free_support_barycenter.py | |
parent | d62f05daf348b4e554056f298c66cbd64f5e3c6e (diff) | |
parent | a16b9471d7114ec08977479b7249efe747702b97 (diff) |
Merge branch 'dfsg/latest' into debian/sid
Diffstat (limited to 'docs/source/auto_examples/plot_free_support_barycenter.py')
-rw-r--r-- | docs/source/auto_examples/plot_free_support_barycenter.py | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/docs/source/auto_examples/plot_free_support_barycenter.py b/docs/source/auto_examples/plot_free_support_barycenter.py deleted file mode 100644 index b6efc59..0000000 --- a/docs/source/auto_examples/plot_free_support_barycenter.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -""" -==================================================== -2D free support Wasserstein barycenters of distributions -==================================================== - -Illustration of 2D Wasserstein barycenters if discributions that are weighted -sum of diracs. - -""" - -# Author: Vivien Seguy <vivien.seguy@iip.ist.i.kyoto-u.ac.jp> -# -# License: MIT License - -import numpy as np -import matplotlib.pylab as pl -import ot - - -############################################################################## -# Generate data -# ------------- -#%% parameters and data generation -N = 3 -d = 2 -measures_locations = [] -measures_weights = [] - -for i in range(N): - - n_i = np.random.randint(low=1, high=20) # nb samples - - mu_i = np.random.normal(0., 4., (d,)) # Gaussian mean - - A_i = np.random.rand(d, d) - cov_i = np.dot(A_i, A_i.transpose()) # Gaussian covariance matrix - - x_i = ot.datasets.make_2D_samples_gauss(n_i, mu_i, cov_i) # Dirac locations - b_i = np.random.uniform(0., 1., (n_i,)) - b_i = b_i / np.sum(b_i) # Dirac weights - - measures_locations.append(x_i) - measures_weights.append(b_i) - - -############################################################################## -# Compute free support barycenter -# ------------- - -k = 10 # number of Diracs of the barycenter -X_init = np.random.normal(0., 1., (k, d)) # initial Dirac locations -b = np.ones((k,)) / k # weights of the barycenter (it will not be optimized, only the locations are optimized) - -X = ot.lp.free_support_barycenter(measures_locations, measures_weights, X_init, b) - - -############################################################################## -# Plot data -# --------- - -pl.figure(1) -for (x_i, b_i) in zip(measures_locations, measures_weights): - color = np.random.randint(low=1, high=10 * N) - pl.scatter(x_i[:, 0], x_i[:, 1], s=b * 1000, label='input measure') -pl.scatter(X[:, 0], X[:, 1], s=b * 1000, c='black', marker='^', label='2-Wasserstein barycenter') -pl.title('Data measures and their barycenter') -pl.legend(loc=0) -pl.show() |