-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fgw barycenter often returns matrix with same entries #547
Comments
Hello @youssef62, |
I am not sure of that because i don't get integers as output this time. |
By default, I would advise to set input structure and feature matrices as np.array with float types. To be sure that you do not have degenerated intermediate transport plans because of the type. Then, indeed it can be a matter of poor local optimum because of poor initialization of the barycenter.
|
Thank you for your answer and tips.
n = 5
g1 = nx.erdos_renyi_graph(n,0.5)
g2 = nx.erdos_renyi_graph(n,0.5)
c1 = nx.adjacency_matrix(g1).toarray().astype(np.float64)
c2 = nx.adjacency_matrix(g2).toarray().astype(np.float64)
init_c = np.random.random((n,n)).astype(np.float64)
f = np.random.random((2,n,2)).astype(np.float64)
_,bary1,log = fgw_barycenters( n , f, np.array([c1,c2]) , alpha = .5 , init_C= init_c , symmetric=True , log=True)
print(bary1)
print(log) the ouput is
for 'Ts_iter' I have 3 matrices with 0.04 in all the entries , for the transport map 'T' it is also a matrix with only 0.04. For 'Ms' i get
I don't think this is particularly useful to you. |
Hello @youssef62, Thank you for your feedback. Remark: you should not provide an asymmetric matrix init_C while setting 'symmetric=True'. Best, |
I like the ability to use kmeans init, we should do thator at least provide this as possible init! |
I ran some more tests and this issue comes up much less in version 0.8.2 than in 0.9.1 ( approximately half the of the time as exposed to always , using the code above ). |
We did some debugging of optimization around 0.9 so it should work better (maybe it staus stuck in initilization place more because of this), @cedricvincentcuaz we need to look into this please (in addition to the new init). |
Hello @youssef62 and @rflamary, So building on the previous examples, I compared in many settings the GW and FGW barycenter solvers in both versions 0.82 and 0.91. potential Improvements:
|
Thanks @cedricvincentcuaz , I think your analysis is spot on. The way it is now is that In my tests , locally I updated T before C so the new T takes init_C into account. I put the following block : if warmstartT:
T = [fused_gromov_wasserstein(
Ms[s], C, Cs[s], p, ps[s], loss_fun=loss_fun, alpha=alpha, armijo=armijo, symmetric=symmetric,
G0=T[s], max_iter=max_iter, tol_rel=1e-5, tol_abs=0., verbose=verbose, **kwargs) for s in range(S)]
else:
T = [fused_gromov_wasserstein(
Ms[s], C, Cs[s], p, ps[s], loss_fun=loss_fun, alpha=alpha, armijo=armijo, symmetric=symmetric,
G0=None, max_iter=max_iter, tol_rel=1e-5, tol_abs=0., verbose=verbose, **kwargs) for s in range(S)]
Before this one : if not fixed_structure:
T_temp = [t.T for t in T]
if loss_fun == 'square_loss':
C = update_square_loss(p, lambdas, T_temp, Cs)
elif loss_fun == 'kl_loss':
C = update_kl_loss(p, lambdas, T_temp, Cs) And then I did some experiments and the bug seems to be gone now. |
The PR has been merged, I'm closing the issue, thanks to you both. |
Describe the bug
fgw_barycenters function often ( more than half of my tests) returns a matrix whose entries are the same. Is this considered to be the normal behavior ? In the case of the application on graphs, I always get a complete graph with self loops.
Screenshots
Code sample
Expected behavior
To have a non homogeneous matrix more often.
Environment (please complete the following information):
pip
,conda
):pipOutput of the following code snippet:
macOS-12.5.1-arm64-arm-64bit
Python 3.11.5 (main, Aug 24 2023, 15:09:32) [Clang 14.0.0 (clang-1400.0.29.202)]
NumPy 1.26.0
SciPy 1.11.3
POT 0.9.1
Additional context
I tried to test it with different values of alpha , even 1 which completely ignores the feature. I also tested with different features (not only all ones) and I still have the same issue. I suppose this has to do with the fact that it can converge to a local minima but I don't think it is supposed to happen this often.
I did not really know if this should have been reported as an issue or as a discussion post.
The text was updated successfully, but these errors were encountered: