2828"""
2929 emd(μ, ν, C, optimizer)
3030
31- Compute the optimal transport map `γ` for the Monge-Kantorovich problem with source
31+ Compute the optimal transport plan `γ` for the Monge-Kantorovich problem with source
3232histogram `μ`, target histogram `ν`, and cost matrix `C` of size `(length(μ), length(ν))`
3333which solves
3434```math
@@ -84,15 +84,15 @@ function emd(μ, ν, C, model::MOI.ModelLike)
8484 # compute optimal solution
8585 MOI. optimize! (model)
8686 status = MOI. get (model, MOI. TerminationStatus ())
87- status === MOI. OPTIMAL || error (" failed to compute optimal transport map : " , status)
87+ status === MOI. OPTIMAL || error (" failed to compute optimal transport plan : " , status)
8888 p = MOI. get (model, MOI. VariablePrimal (), x)
8989 γ = reshape (p, nμ, nν)
9090
9191 return γ
9292end
9393
9494"""
95- emd2(μ, ν, C, optimizer; map =nothing)
95+ emd2(μ, ν, C, optimizer; plan =nothing)
9696
9797Compute the optimal transport cost (a scalar) for the Monge-Kantorovich problem with source
9898histogram `μ`, target histogram `ν`, and cost matrix `C` of size `(length(μ), length(ν))`
@@ -105,20 +105,25 @@ The corresponding linear programming problem is solved with the user-provided `o
105105Possible choices are `Tulip.Optimizer()` and `Clp.Optimizer()` in the `Tulip` and `Clp`
106106packages, respectively.
107107
108- A pre-computed optimal transport `map ` may be provided.
108+ A pre-computed optimal transport `plan ` may be provided.
109109"""
110- function emd2 (μ, ν, C, optimizer; map= nothing )
111- γ = if map === nothing
112- # compute optimal transport map
110+ function emd2 (μ, ν, C, optimizer; map= nothing , plan= map)
111+ # check deprecation
112+ if map != = nothing
113+ Base. depwarn (" the keyword argument `map` is deprecated, please use `plan`" , :emd2 )
114+ end
115+
116+ γ = if plan === nothing
117+ # compute optimal transport plan
113118 emd (μ, ν, C, optimizer)
114119 else
115120 # check dimensions
116121 size (C) == (length (μ), length (ν)) ||
117122 error (" cost matrix `C` must be of size `(length(μ), length(ν))`" )
118- size (map ) == size (C) || error (
119- " optimal transport map `map ` and cost matrix `C` must be of the same size" ,
123+ size (plan ) == size (C) || error (
124+ " optimal transport plan `plan ` and cost matrix `C` must be of the same size" ,
120125 )
121- map
126+ plan
122127 end
123128 return dot (γ, C)
124129end
@@ -130,7 +135,7 @@ Compute dual potentials `u` and `v` for histograms `mu` and `nu` and Gibbs kerne
130135the Sinkhorn algorithm (Peyre et al., 2019)
131136
132137The Gibbs kernel `K` is given by `K = exp.(- C / eps)` where `C` is the cost matrix and
133- `eps` the entropic regularization parameter. The optimal transport map for histograms `u`
138+ `eps` the entropic regularization parameter. The optimal transport plan for histograms `u`
134139and `v` and cost matrix `C` with regularization parameter `eps` can be computed as
135140`Diagonal(u) * K * Diagonal(v)`.
136141"""
181186"""
182187 sinkhorn(mu, nu, C, eps; tol=1e-9, check_marginal_step=10, maxiter=1000)
183188
184- Compute entropically regularised transport map of histograms `mu` and `nu` with cost matrix `C` and entropic
189+ Compute entropically regularised transport plan of histograms `mu` and `nu` with cost matrix `C` and entropic
185190regularization parameter `eps`.
186191
187192Return optimal transport coupling `γ` of the same dimensions as `C` which solves
@@ -204,7 +209,7 @@ function sinkhorn(mu, nu, C, eps; kwargs...)
204209end
205210
206211"""
207- sinkhorn2(mu, nu, C, eps; tol=1e-9, check_marginal_step=10, maxiter=1000 )
212+ sinkhorn2(mu, nu, C, eps; plan=nothing, kwargs... )
208213
209214Compute entropically regularised transport cost of histograms `mu` and `nu` with cost matrix `C` and entropic
210215regularization parameter `eps`.
@@ -217,27 +222,36 @@ Return optimal value of
217222
218223where ``H`` is the entropic regulariser, ``H(\\ gamma) = -\\ sum_{i, j} \\ gamma_{ij} \\ log(\\ gamma_{ij})``.
219224
220- A pre-computed optimal transport `map` may be provided.
225+ A pre-computed optimal transport `plan` may be provided.
226+
227+ See also: [`sinkhorn`](@ref)
221228"""
222- function sinkhorn2 (μ, ν, C, ε; map= nothing , kwargs... )
223- γ = if map === nothing
229+ function sinkhorn2 (μ, ν, C, ε; map= nothing , plan= map, kwargs... )
230+ # check deprecation
231+ if map != = nothing
232+ Base. depwarn (
233+ " the keyword argument `map` is deprecated, please use `plan`" , :sinkhorn2
234+ )
235+ end
236+
237+ γ = if plan === nothing
224238 sinkhorn (μ, ν, C, ε; kwargs... )
225239 else
226240 # check dimensions
227241 size (C) == (length (μ), length (ν)) ||
228242 error (" cost matrix `C` must be of size `(length(μ), length(ν))`" )
229- size (map ) == size (C) || error (
230- " optimal transport map `map ` and cost matrix `C` must be of the same size" ,
243+ size (plan ) == size (C) || error (
244+ " optimal transport plan `plan ` and cost matrix `C` must be of the same size" ,
231245 )
232- map
246+ plan
233247 end
234248 return dot (γ, C)
235249end
236250
237251"""
238252 sinkhorn_unbalanced(mu, nu, C, lambda1, lambda2, eps; tol = 1e-9, max_iter = 1000, verbose = false, proxdiv_F1 = nothing, proxdiv_F2 = nothing)
239253
240- Computes the optimal transport map of histograms `mu` and `nu` with cost matrix `C` and entropic regularization parameter `eps`,
254+ Computes the optimal transport plan of histograms `mu` and `nu` with cost matrix `C` and entropic regularization parameter `eps`,
241255using the unbalanced Sinkhorn algorithm [Chizat 2016] with KL-divergence terms for soft marginal constraints, with weights `(lambda1, lambda2)`
242256for the marginals `mu`, `nu` respectively.
243257
@@ -313,35 +327,43 @@ function sinkhorn_unbalanced(
313327end
314328
315329"""
316- sinkhorn_unbalanced2(mu, nu, C, lambda1, lambda2, eps; tol = 1e-9, max_iter = 1000, verbose = false, proxdiv_F1 = nothing, proxdiv_F2 = nothing )
330+ sinkhorn_unbalanced2(mu, nu, C, lambda1, lambda2, eps; plan= nothing, kwargs... )
317331
318332Computes the optimal transport cost of histograms `mu` and `nu` with cost matrix `C` and entropic regularization parameter `eps`,
319333using the unbalanced Sinkhorn algorithm [Chizat 2016] with KL-divergence terms for soft marginal constraints, with weights `(lambda1, lambda2)`
320334for the marginals mu, nu respectively.
321335
322- See documentation for `sinkhorn_unbalanced` for additional details .
336+ A pre-computed optimal transport `plan` may be provided .
323337
324- A pre-computed optimal transport `map` may be provided.
338+ See also: [`sinkhorn_unbalanced`](@ref)
325339"""
326- function sinkhorn_unbalanced2 (μ, ν, C, λ1, λ2, ε; map= nothing , kwargs... )
327- γ = if map === nothing
340+ function sinkhorn_unbalanced2 (μ, ν, C, λ1, λ2, ε; map= nothing , plan= map, kwargs... )
341+ # check deprecation
342+ if map != = nothing
343+ Base. depwarn (
344+ " the keyword argument `map` is deprecated, please use `plan`" ,
345+ :sinkhorn_unbalanced2 ,
346+ )
347+ end
348+
349+ γ = if plan === nothing
328350 sinkhorn_unbalanced (μ, ν, C, λ1, λ2, ε; kwargs... )
329351 else
330352 # check dimensions
331353 size (C) == (length (μ), length (ν)) ||
332354 error (" cost matrix `C` must be of size `(length(μ), length(ν))`" )
333- size (map ) == size (C) || error (
334- " optimal transport map `map ` and cost matrix `C` must be of the same size" ,
355+ size (plan ) == size (C) || error (
356+ " optimal transport plan `plan ` and cost matrix `C` must be of the same size" ,
335357 )
336- map
358+ plan
337359 end
338360 return dot (γ, C)
339361end
340362
341363"""
342364 sinkhorn_stabilized_epsscaling(mu, nu, C, eps; absorb_tol = 1e3, max_iter = 1000, tol = 1e-9, lambda = 0.5, k = 5, verbose = false)
343365
344- Compute optimal transport map of histograms `mu` and `nu` with cost matrix `C` and entropic regularisation parameter `eps`.
366+ Compute optimal transport plan of histograms `mu` and `nu` with cost matrix `C` and entropic regularisation parameter `eps`.
345367Uses stabilized Sinkhorn algorithm with epsilon-scaling (Schmitzer et al., 2019).
346368
347369`k` epsilon-scaling steps are used with scaling factor `lambda`, i.e. sequentially solve Sinkhorn with regularisation parameters
382404"""
383405 sinkhorn_stabilized(mu, nu, C, eps; absorb_tol = 1e3, max_iter = 1000, tol = 1e-9, alpha = nothing, beta = nothing, return_duals = false, verbose = false)
384406
385- Compute optimal transport map of histograms `mu` and `nu` with cost matrix `C` and entropic regularisation parameter `eps`.
407+ Compute optimal transport plan of histograms `mu` and `nu` with cost matrix `C` and entropic regularisation parameter `eps`.
386408Uses stabilized Sinkhorn algorithm (Schmitzer et al., 2019).
387409"""
388410function sinkhorn_stabilized (
520542"""
521543 quadreg(mu, nu, C, ϵ; θ = 0.1, tol = 1e-5,maxiter = 50,κ = 0.5,δ = 1e-5)
522544
523- Computes the optimal transport map of histograms `mu` and `nu` with cost matrix `C` and quadratic regularization parameter `ϵ`,
545+ Computes the optimal transport plan of histograms `mu` and `nu` with cost matrix `C` and quadratic regularization parameter `ϵ`,
524546using the semismooth Newton algorithm [Lorenz 2016].
525547
526548This implementation makes use of IterativeSolvers.jl and SparseArrays.jl.
0 commit comments