geomloss icon indicating copy to clipboard operation
geomloss copied to clipboard

Inconsistency with OT with Non Uniforme Weights ? What are we doing wrong ?

Open PierreColombo opened this issue 4 years ago • 1 comments

Hello, Thanks a lot for your great librairy ! We are trying to compute the transportation cost with Geomloss and we obtain inconsitent results when compared with ot. We want to use non uniforme weight with a custom cost function. Maybe you could help us to spot the error ?

OT

import numpy as np 
import ot.gpu as otgpu
size = 10000
weight = np.random.rand(size)
D_1 = weight / np.linalg.norm(weight, 1)
M = np.random.rand(size,size)
X =otgpu.sinkhorn(D_1,D_2,M_cupy, reg=0.05)
transportation_cost = np.sum(np.multiply(X,M))

We have transportation_cost=0.05004567861659549

Geomloss

def cost_function_custom(X,Y): 
    return torch.tensor(M).unsqueeze(0).cuda()

w_x = torch.tensor(D_1).cuda().clone() 
w_y = torch.tensor(D_2).cuda().clone() 
loss = SamplesLoss(loss="sinkhorn", p=2, blur=.05,backend="tensorized",cost=cost_function_custom,debias =False,scaling = 0.9999)
loss = loss(w_x,w_x.unsqueeze(1),w_y,w_y.unsqueeze(1))

We obtain loss=tensor(0.0150, device='cuda:0', dtype=torch.float64)

Are we missing something ?

Thanks a lot for your time. Cheers

PierreColombo avatar Feb 22 '21 13:02 PierreColombo

Hey, I had the same issue when playing with the library for early tests of one of my papers. The regularisation param does not have the same meaning in pot and geomloss (reg = blur^p).

Hope that helps

Adrien

AdrienCorenflos avatar Mar 06 '21 20:03 AdrienCorenflos