r""" Compute the transportation matrix to solve the regularized discrete measures optimal transport dual problem The function solves the following optimization problem: .. math:: \gamma = \mathop{\arg \min}_\gamma \quad \langle \gamma, \mathbf{M} \rangle_F + \mathrm{reg
(a, b, M, reg, batch_size, numItermax=10000, lr=1, log=False)
| 535 | |
| 536 | |
| 537 | def solve_dual_entropic(a, b, M, reg, batch_size, numItermax=10000, lr=1, log=False): |
| 538 | r""" |
| 539 | Compute the transportation matrix to solve the regularized discrete measures optimal transport dual problem |
| 540 | |
| 541 | The function solves the following optimization problem: |
| 542 | |
| 543 | .. math:: |
| 544 | \gamma = \mathop{\arg \min}_\gamma \quad \langle \gamma, \mathbf{M} \rangle_F + |
| 545 | \mathrm{reg} \cdot\Omega(\gamma) |
| 546 | |
| 547 | s.t. \ \gamma \mathbf{1} = \mathbf{a} |
| 548 | |
| 549 | \gamma^T \mathbf{1} = \mathbf{b} |
| 550 | |
| 551 | \gamma \geq 0 |
| 552 | |
| 553 | Where : |
| 554 | |
| 555 | - :math:`\mathbf{M}` is the (`ns`, `nt`) metric cost matrix |
| 556 | - :math:`\Omega` is the entropic regularization term with :math:`\Omega(\gamma)=\sum_{i,j} \gamma_{i,j}\log(\gamma_{i,j})` |
| 557 | - :math:`\mathbf{a}` and :math:`\mathbf{b}` are source and target weights (sum to 1) |
| 558 | |
| 559 | Parameters |
| 560 | ---------- |
| 561 | a : ndarray, shape (ns,) |
| 562 | source measure |
| 563 | b : ndarray, shape (nt,) |
| 564 | target measure |
| 565 | M : ndarray, shape (ns, nt) |
| 566 | cost matrix |
| 567 | reg : float |
| 568 | Regularization term > 0 |
| 569 | batch_size : int |
| 570 | size of the batch |
| 571 | numItermax : int |
| 572 | number of iteration |
| 573 | lr : float |
| 574 | learning rate |
| 575 | log : bool, optional |
| 576 | record log if True |
| 577 | |
| 578 | Returns |
| 579 | ------- |
| 580 | pi : ndarray, shape (ns, nt) |
| 581 | transportation matrix |
| 582 | log : dict |
| 583 | log dictionary return only if log==True in parameters |
| 584 | |
| 585 | References |
| 586 | ---------- |
| 587 | .. [19] Seguy, V., Bhushan Damodaran, B., Flamary, R., Courty, N., Rolet, A.& Blondel, M. Large-scale Optimal Transport and Mapping Estimation. International Conference on Learning Representation (2018) |
| 588 | """ |
| 589 | |
| 590 | opt_alpha, opt_beta = sgd_entropic_regularization( |
| 591 | a, b, M, reg, batch_size, numItermax, lr |
| 592 | ) |
| 593 | pi = ( |
| 594 | np.exp((opt_alpha[:, None] + opt_beta[None, :] - M[:, :]) / reg) |
nothing calls this directly
no test coverage detected