Hi, I am currently trying to use the bregman barycenter algorithm to interpolate between 2D floating point arrays. I am getting some odds results and was hoping to better understand what's happening. The example I've attached illustrates the main issue. In this example, I'm trying to interpolate between two 2D arrays, one with 1s in the upper-right quadrant, and 0s elsewhere, the other with 1s in the lower left quadrant, and 0s elsewhere. I'm then using barycenter with different weights ([1-t, …
[View More]t] for t in {0, 0.25, 0.5, 0.75, 1}). What I would have expected is that each output would have the same number of 1s, just in different locations. for t = 0, I'd expect to get my first input, for t = 1, my second input. For t=0.5, one quadrant's-worth of 1s at the center of the output image. Instead, the output I'm getting is fuzzy, and also significantly offset from where I'd expect for all t other than 0.5. At the very least, I can't imaging why I would get anything other than my original input for t = 0 or 1. Do I misunderstand the function, or have I made an error somewhere? If anyone could help me to better understand what's happening here, I would appreciate it.
Here the code I'm using: https://pastebin.com/EuW2sAUM
And here's the output of the above code: https://imgur.com/a/H9AK9
[View Less]
Hello , I am following these two papers- Optimal Transport for Domain adaptation Courty et al in TPAMI [1] and Large scale OT and Mapping estimation -Seguey et al in ICLR[2]
The papers say that they use Nearest Neighbor classifier as the baseline and I am confused about it.
As in [1] I took 1800 Usps and 2000 MNIST dataset and using the OTDA examples found the transported source.
I am struck after this for the classification i.e., do I now compute a 2000 X 1800 distance matrix between target …
[View More]and source and use nearest neighbors?
Here is the code that I am using. Can you please tell me how to proceed from here
##% experiment with domain adaptation
import ot
import numpy as np
import sklearn
import matplotlib.pyplot as plt
from scipy.io import loadmat
#%% data
u_m=loadmat('USPS_vs_MNIST.mat')
Xs= u_m['X_src']
Ys=u_m['Y_src']
Xt=u_m['X_tar']
Yt=u_m['Y_tar']
#%% DA
ot_sinkhorn_un = ot.da.SinkhornTransport(reg_e=1)
ot_sinkhorn_un.fit(Xs=Xs.T, Xt=Xt.T)
transp_Xs_sinkhorn_un = ot_sinkhorn_un.transform(Xs=Xs.T).T
#%% nearest neigbor classifier
from sklearn.metrics import confusion_matrix as CM
import scipy
M=scipy.spatial.distance.cdist(Xt.T,transp_Xs_sinkhorn_un.T,'sqeuclidean')# not correct
a=np.argmin(M,axis=1)
labels_test= Yt[a]
conf= CM(Yt,labels_test)
acc= np.sum(np.diag(conf))/np.sum(conf)
acc
[View Less]
Hello,
I am using the following modified code from the tutorial
examples/plot_barycenter_1D.py. I have just modified it to compute
barycenters between bimodal 1-D distributions.
I expected to see the barycenter to also contain only two peaks however it
contains 3 which is not very intuitive geometrically speaking .
I have attached the resultant figure showing that the barycenter computed
has three peaks.
Is there a way to intuitively understand why this is happening. The
results dont show …
[View More]this if weights computed using \alpha when \alpha =
{0,0.1,0.8,0.9,1}
Thanks
Kowshik
The code is here - https://pastebin.com/bgMgrBMd
The result image is here- https://imgur.com/a/o3ptZ8U
<https://imgur.com/a/o3ptZ8U>
ᐧ
[View Less]
Hello,
I am using the following modified code from the tutorial
examples/plot_barycenter_1D.py. I have just modified it to compute
barycenters between bimodal 1-D distributions.
I expected to see the barycenter to also contain only two peaks however it
contains 3 which is not very intuitive geometrically speaking .
I have attached the resultant figure showing that the barycenter computed
has three peaks.
Is there a way to intuitively understand why this is happening. The
results dont show …
[View More]this if weights computed using \alpha when \alpha =
{0,0.1,0.8,0.9,1}
Thanks
Kowshik
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
import os
##############################################################################
# Generate data
# -------------
#%% parameters
n = 200 # nb bins
# bin positions
x = np.arange(n, dtype=np.float64)
# Gaussian distributions
a1 = ot.datasets.get_1D_gauss(n, m=10, s=5) # m= mean, s= std
a2 = ot.datasets.get_1D_gauss(n, m=60, s=5)
# creating matrix A - a bimodal distriution
A = a1+0.5*a2
b1 = ot.datasets.get_1D_gauss(n, m=100, s=8) # m= mean, s= std
b2 = ot.datasets.get_1D_gauss(n, m=150, s=8)
# creating matrix B another bimodal
B=0.5*b1+b2
distributions=np.vstack((A,B)).T
n_distributions = distributions.shape[1]
# loss matrix + normalization
M =ot.dist(x.reshape(n,1),x.reshape(n,1),metric= 'sqeuclidean')
M /= M.max()
##############################################################################
# Plot data
# ---------
#%% plot the distributions
pl.figure(1, figsize=(6.4, 3))
for i in range(n_distributions):
pl.plot(x, distributions[:,i])
pl.title('Distributions')
pl.tight_layout()
##############################################################################
# Barycenter computation
# ----------------------
#%% barycenter computation
alpha = 0.5 # 0<=alpha<=1
weights = np.array([1 - alpha, alpha])
# l2bary
bary_l2 = distributions.dot(weights)
# wasserstein
reg = 0.001
bary_wass = ot.bregman.barycenter(distributions, M, reg, weights)
pl.figure(2)
pl.clf()
pl.subplot(2, 1, 1)
for i in range(n_distributions):
pl.plot(x, distributions[:, 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()
[View Less]
Hi,
Thanks for a great tool box.
In the example as well in documentation – the method ot.bregman.barycenter(A,M..) calculates the entropic regularized wasserstein barycenter of distributions A where each column of A is considered a distribution implying – that it computes Barycenters for 1-D distributions.
I want to ask if there is an easy way to extend this to more than 1-D distributions, say 2 or 3 or to arbitrary dimensions.
I have read the convolutional Wasserstein distance paper by …
[View More]Solomon et al (SIGGRAPH 2015). I also want to ask if it will be implemented in this toolbox as well?
Thanks
Kowshik Thopalli
[View Less]