Gromov-Wasserstein writes as: GW(T,C1,C2) = sum_ijkl T_ik T_jl l(C1_ij, C2_kl) = < LxT, T > Where L is a cost tensor L[i,j,k,l] = l(C1_ij, C2_kl). For loss function of form l(a,b) = f1(a) + f2(b) - < h1(a), h2(b) > The tensor product LxT can be computed fast using tensor_pr
(f1, f2, h1, h2, a, b, C1, C2, symmetric=True)
| 502 | |
| 503 | |
| 504 | def compute_tensor_batch(f1, f2, h1, h2, a, b, C1, C2, symmetric=True): |
| 505 | """ |
| 506 | Gromov-Wasserstein writes as: |
| 507 | GW(T,C1,C2) = sum_ijkl T_ik T_jl l(C1_ij, C2_kl) = < LxT, T > |
| 508 | Where L is a cost tensor L[i,j,k,l] = l(C1_ij, C2_kl). |
| 509 | |
| 510 | For loss function of form l(a,b) = f1(a) + f2(b) - < h1(a), h2(b) > |
| 511 | The tensor product LxT can be computed fast using tensor_product [12]. |
| 512 | |
| 513 | References |
| 514 | ---------- |
| 515 | .. [12] Gabriel Peyré, Marco Cuturi, and Justin Solomon, |
| 516 | "Gromov-Wasserstein averaging of kernel and distance matrices." |
| 517 | International Conference on Machine Learning (ICML). 2016. |
| 518 | """ |
| 519 | |
| 520 | fC1 = f1(C1) |
| 521 | fC2 = f2(C2) |
| 522 | if not symmetric: |
| 523 | fC1 = 0.5 * (fC1 + transpose(fC1)) |
| 524 | fC2 = 0.5 * (fC2 + transpose(fC2)) |
| 525 | hC1 = h1(C1) |
| 526 | hC2 = h2(C2) |
| 527 | |
| 528 | constC = compute_const_from_marginals(fC1, fC2, a, b) |
| 529 | |
| 530 | L = {"constC": constC, "hC1": hC1, "hC2": hC2, "fC1": fC1, "fC2": fC2} |
| 531 | |
| 532 | return L |
| 533 | |
| 534 | |
| 535 | def tensor_product_batch(L, T, nx=None, recompute_const=False, symmetric=True): |
no test coverage detected