-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General regularisation #66
base: master
Are you sure you want to change the base?
Changes from all commits
42a31ac
f809e19
4e758f8
3e8a3c8
71c3378
f345878
5adf635
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -94,7 +94,7 @@ sinkhorn2(μ, ν, C, ε) | |||||
# resulting transport plan $\gamma$ is *sparse*. We take advantage of this and represent it as | ||||||
# a sparse matrix. | ||||||
|
||||||
quadreg(μ, ν, C, ε; maxiter=500); | ||||||
ot_reg_plan(μ, ν, C, ε; reg_func = "L2", method = "lorenz", maxiter=500); | ||||||
|
||||||
# ## Stabilized Sinkhorn algorithm | ||||||
# | ||||||
|
@@ -190,7 +190,7 @@ heatmap( | |||||
# Notice how the "edges" of the transport plan are sharper if we use quadratic regularisation | ||||||
# instead of entropic regularisation: | ||||||
|
||||||
γquad = Matrix(quadreg(μ, ν, C, 5; maxiter=500)) | ||||||
γquad = Matrix(ot_reg_plan(μ, ν, C, 5; reg_func = "L2", method = "lorenz", maxiter=500)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
heatmap( | ||||||
μsupport, | ||||||
νsupport, | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -13,7 +13,7 @@ export sinkhorn, sinkhorn2 | |||||
export emd, emd2 | ||||||
export sinkhorn_stabilized, sinkhorn_stabilized_epsscaling, sinkhorn_barycenter | ||||||
export sinkhorn_unbalanced, sinkhorn_unbalanced2 | ||||||
export quadreg | ||||||
export ot_reg_plan, ot_reg_cost | ||||||
|
||||||
const MOI = MathOptInterface | ||||||
|
||||||
|
@@ -506,6 +506,53 @@ function sinkhorn_barycenter( | |||||
return u_all[1, :] .* (K_all[1] * v_all[1, :]) | ||||||
end | ||||||
|
||||||
""" | ||||||
ot_reg_plan(mu, nu, C, eps; reg_func = "L2", method = "lorenz", kwargs...) | ||||||
|
||||||
Compute the optimal transport plan between `mu` and `nu` for optimal transport with a | ||||||
general choice of regulariser `math Ω(γ)`. Solves for `gamma` that minimises | ||||||
|
||||||
```math | ||||||
\\inf_{γ ∈ Π(μ, ν)} \\langle γ, C \\rangle + ε Ω(γ) | ||||||
``` | ||||||
|
||||||
Supported choices of `math Ω` are: | ||||||
- L2: ``Ω(γ) = \\frac{1}{2} \\| γ \\|_2^2``, `reg_func = "L2"` | ||||||
|
||||||
Supported solution methods are: | ||||||
- L2: `method = "lorenz"` for the semi-smooth Newton method of Lorenz et al. | ||||||
|
||||||
References | ||||||
|
||||||
Lorenz, D.A., Manns, P. and Meyer, C., 2019. Quadratically regularized optimal transport. Applied Mathematics & Optimization, pp.1-31. | ||||||
""" | ||||||
function ot_reg_plan(mu, nu, C, eps; reg_func="L2", method="lorenz", kwargs...) | ||||||
if (reg_func == "L2") && (method == "lorenz") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This approach is problematic in my opinion: it is not possible to add support for other methods or regularization types for users or downstream packages, one always has to modify this function here. I guess this could be avoided with the suggestion in #63 (comment) - everyone could just add other regularizations and/or algorithms. |
||||||
return quadreg(mu, nu, C, eps; kwargs...) | ||||||
else | ||||||
@warn "Unimplemented" | ||||||
end | ||||||
end | ||||||
|
||||||
""" | ||||||
ot_reg_cost(mu, nu, C, eps; reg_func = "L2", method = "lorenz", kwargs...) | ||||||
|
||||||
Compute the optimal transport cost between `mu` and `nu` for optimal transport with a | ||||||
general choice of regulariser `math Ω(γ)`. | ||||||
|
||||||
See also: [`ot_reg_plan`](@ref) | ||||||
|
||||||
""" | ||||||
function ot_reg_cost(mu, nu, C, eps; reg_func="L2", method="lorenz", kwargs...) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
γ = if (reg_func == "L2") && (method == "lorenz") | ||||||
quadreg(mu, nu, C, eps; kwargs...) | ||||||
else | ||||||
@warn "Unimplemented" | ||||||
nothing | ||||||
end | ||||||
return dot(γ, C) | ||||||
end | ||||||
|
||||||
""" | ||||||
quadreg(mu, nu, C, ϵ; θ = 0.1, tol = 1e-5,maxiter = 50,κ = 0.5,δ = 1e-5) | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶