r"""This function gives the regularization path of semi-relaxed l2-UOT problem. The problem to optimize is the Lasso reformulation of the l2-penalized UOT: .. math:: \min_t \gamma \mathbf{c}^T t + 0.5 * \|H_r \mathbf{t} - \mathbf{a}\|_2^2 s.t.
(a: np.array, b: np.array, C: np.array, reg=1e-4, itmax=50000)
| 679 | |
| 680 | |
| 681 | def semi_relaxed_path(a: np.array, b: np.array, C: np.array, reg=1e-4, itmax=50000): |
| 682 | r"""This function gives the regularization path of semi-relaxed |
| 683 | l2-UOT problem. |
| 684 | |
| 685 | The problem to optimize is the Lasso reformulation of the l2-penalized UOT: |
| 686 | |
| 687 | .. math:: |
| 688 | |
| 689 | \min_t \gamma \mathbf{c}^T t |
| 690 | + 0.5 * \|H_r \mathbf{t} - \mathbf{a}\|_2^2 |
| 691 | |
| 692 | s.t. |
| 693 | H_c \mathbf{t} = \mathbf{b} |
| 694 | |
| 695 | \mathbf{t} \geq 0 |
| 696 | |
| 697 | where : |
| 698 | |
| 699 | - :math:`\mathbf{c}` is the flattened version of the cost matrix \ |
| 700 | :math:`C` |
| 701 | - :math:`\gamma = 1/\lambda` is the l2-regularization parameter |
| 702 | - :math:`H_r` is a matrix that computes the sum along the rows of \ |
| 703 | the transport plan :math:`T` |
| 704 | - :math:`H_c` is a matrix that computes the sum along the columns of \ |
| 705 | the transport plan :math:`T` |
| 706 | - :math:`\mathbf{t}` is the flattened version of the transport plan \ |
| 707 | :math:`T` |
| 708 | |
| 709 | Parameters |
| 710 | ---------- |
| 711 | a : np.ndarray (dim_a,) |
| 712 | Histogram of dimension dim_a |
| 713 | b : np.ndarray (dim_b,) |
| 714 | Histogram of dimension dim_b |
| 715 | C : np.ndarray, shape (dim_a, dim_b) |
| 716 | Cost matrix |
| 717 | reg: float (optional) |
| 718 | l2-regularization coefficient |
| 719 | itmax: int (optional) |
| 720 | Maximum number of iteration |
| 721 | |
| 722 | Returns |
| 723 | ------- |
| 724 | t : np.ndarray (dim_a*dim_b, ) |
| 725 | Flattened vector of the (unregularized) optimal transport matrix |
| 726 | t_list : list |
| 727 | List of all the optimal transport vectors of the regularization path |
| 728 | gamma_list : list |
| 729 | List of the regularization parameters in the path |
| 730 | |
| 731 | Examples |
| 732 | -------- |
| 733 | >>> import ot |
| 734 | >>> import numpy as np |
| 735 | >>> n = 3 |
| 736 | >>> xs = np.array([1., 2., 3.]).reshape((n, 1)) |
| 737 | >>> xt = np.array([5., 6., 7.]).reshape((n, 1)) |
| 738 | >>> C = ot.dist(xs, xt) |
no test coverage detected