|
| 1 | +module Smooth |
| 2 | + |
| 3 | +using ..PythonOT: PythonOT |
| 4 | +using ..PyCall: PyCall |
| 5 | + |
| 6 | +export smooth_ot_dual |
| 7 | + |
| 8 | +""" |
| 9 | + smooth_ot_dual(μ, ν, C, ε; reg_type="l2", kwargs...) |
| 10 | +
|
| 11 | +Compute the optimal transport plan for a regularized optimal transport problem |
| 12 | +with source and target marginals `μ` and `ν`, cost matrix `C` of size |
| 13 | +`(length(μ), length(ν))`, and regularization parameter `ε`. |
| 14 | +
|
| 15 | +The optimal transport map `γ` is of the same size as `C` and solves |
| 16 | +```math |
| 17 | +\\inf_{\\gamma \\in \\Pi(\\mu, \\nu)} \\langle \\gamma, C \\rangle |
| 18 | ++ \\varepsilon \\Omega(\\gamma), |
| 19 | +``` |
| 20 | +where ``\\Omega(\\gamma)`` is the L2-regularization term |
| 21 | +``\\Omega(\\gamma) = \\|\\gamma\\|_F^2/2`` if `reg_type="l2"` (the default) or |
| 22 | +the entropic regularization term |
| 23 | +``\\Omega(\\gamma) = \\sum_{i,j} \\gamma_{i,j} \\log \\gamma_{i,j}`` if `reg_type="kl"`. |
| 24 | +
|
| 25 | +The function solves the dual formulation[^BSR2018] |
| 26 | +```math |
| 27 | +\\max_{\\alpha, \\beta} \\mu^{\\mathsf{T}} \\alpha + \\nu^{\\mathsf{T}} \\beta − |
| 28 | +\\sum_{j} \\delta_{\\Omega}(\\alpha + \\beta_j - C_j), |
| 29 | +``` |
| 30 | +where ``C_j`` is the ``j``th column of the cost matrix and ``\\delta_{\\Omega}`` is the |
| 31 | +conjugate of the regularization term ``\\Omega``. |
| 32 | +
|
| 33 | +This function is a wrapper of the function |
| 34 | +[`smooth_ot_dual`](https://pythonot.github.io/gen_modules/ot.smooth.html#ot.smooth.smooth_ot_dual) |
| 35 | +in the Python Optimal Transport package. Keyword arguments are listed in the documentation |
| 36 | +of the Python function. |
| 37 | +
|
| 38 | +# Examples |
| 39 | +
|
| 40 | +```jldoctest; setup=:(using PythonOT.Smooth) |
| 41 | +julia> μ = [0.5, 0.2, 0.3]; |
| 42 | +
|
| 43 | +julia> ν = [0.0, 1.0]; |
| 44 | +
|
| 45 | +julia> C = [0.0 1.0; |
| 46 | + 2.0 0.0; |
| 47 | + 0.5 1.5]; |
| 48 | +
|
| 49 | +julia> smooth_ot_dual(μ, ν, C, 0.01) |
| 50 | +3×2 Matrix{Float64}: |
| 51 | + 0.0 0.5 |
| 52 | + 0.0 0.2 |
| 53 | + 0.0 0.300001 |
| 54 | +``` |
| 55 | +
|
| 56 | +[^BSR2018]: Blondel, M., Seguy, V., & Rolet, A. (2018). Smooth and Sparse Optimal Transport. In *Proceedings of the Twenty-First International Conference on Artificial Intelligence and Statistics (AISTATS)*. |
| 57 | +""" |
| 58 | +function smooth_ot_dual(μ, ν, C, ε; kwargs...) |
| 59 | + return PythonOT.pot.smooth.smooth_ot_dual(μ, ν, C, ε; kwargs...) |
| 60 | +end |
| 61 | +end |
0 commit comments