-
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
add davibarreira's sinkhorn_divergence with some modifications #145
Merged
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
ecb81e1
add davibarreira's sinkhorn_divergence with some modifications
zsteve 5e981e7
added documentation entry for sinkhorn_divergence
zsteve 9828028
add statsbase to test deps
zsteve 5c308e9
add empirical measure example for sinkhorn divergence
zsteve 43d7a1d
format
zsteve e3fa3d9
add literate
zsteve 5c347b1
implement symmetric sinkhorn
zsteve 7f737ee
implement sinkhorn_loss
zsteve 44659ae
change formula for obj()
zsteve a0dc59a
make empirical example run faster
zsteve 48baadc
update docstrings
zsteve 2f7179e
Update src/entropic/sinkhorn.jl
zsteve 94055c2
Update src/entropic/sinkhorn.jl
zsteve a43ef32
address review comments
zsteve fefc503
Merge branch 'sinkhorn_divergence' of https://github.com/JuliaOptimal…
zsteve c8c8e9c
fix naming of plan and sinkhorn_plan
zsteve 5cb77be
address comments
zsteve 1026a44
fix sinkhorn_divergence and docs
zsteve edabeee
update docs
zsteve 5b19d3b
format
zsteve 2df1f54
remove sinkhorn_loss
zsteve 440c191
Update examples/empirical_sinkhorn_div/script.jl
zsteve e214a68
Update src/entropic/sinkhorn_divergence.jl
zsteve 5e02240
Update src/entropic/symmetric.jl
zsteve 80dc5fe
Update src/entropic/sinkhorn_gibbs.jl
zsteve fb0277b
Update src/entropic/sinkhorn_gibbs.jl
zsteve ed1b947
Update src/entropic/symmetric.jl
zsteve f4d6474
bump version
zsteve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -219,6 +219,12 @@ function sinkhorn2(μ, ν, C, ε, alg::Sinkhorn; regularization=false, plan=noth | |||||||
return cost | ||||||||
end | ||||||||
|
||||||||
function sinkhorn_loss(μ, ν, C, ε, alg::Sinkhorn; kwargs...) | ||||||||
return error( | ||||||||
"sinkhorn_loss is only implemented for alg::SinkhornGibbs. For other algorithms please use sinkhorn2", | ||||||||
) | ||||||||
end | ||||||||
|
||||||||
""" | ||||||||
sinkhorn_divergence(μ::AbstractVecOrMat, ν::AbstractVecOrMat, C, ε, alg::Sinkhorn = SinkhornGibbs(); regularization = nothing, plan = nothing, kwargs...) | ||||||||
Compute the Sinkhorn Divergence between finite discrete | ||||||||
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.
Suggested change
|
||||||||
|
@@ -251,13 +257,19 @@ function sinkhorn_divergence( | |||||||
alg::Sinkhorn=SinkhornGibbs(), | ||||||||
algμ::Sinkhorn=SymmetricSinkhornGibbs(), | ||||||||
algν::Sinkhorn=SymmetricSinkhornGibbs(); | ||||||||
regularization=nothing, | ||||||||
regularization=true, | ||||||||
plan=nothing, | ||||||||
kwargs..., | ||||||||
) | ||||||||
OTμν = sinkhorn2(μ, ν, C, ε, alg; plan=plan, regularization=false, kwargs...) | ||||||||
OTμ = sinkhorn2(μ, C, ε, algμ; plan=nothing, regularization=false, kwargs...) | ||||||||
OTν = sinkhorn2(ν, C, ε, algν; plan=nothing, regularization=false, kwargs...) | ||||||||
OTμν, OTμ, OTν = if (regularization == true) && (plan === nothing) | ||||||||
sinkhorn_loss(μ, ν, C, ε, alg; kwargs...), | ||||||||
sinkhorn_loss(μ, C, ε, algμ; kwargs...), | ||||||||
sinkhorn_loss(ν, C, ε, algν; kwargs...) | ||||||||
else | ||||||||
sinkhorn2(μ, ν, C, ε, alg; plan=plan, regularization=false, kwargs...), | ||||||||
sinkhorn2(μ, C, ε, algμ; plan=nothing, regularization=false, kwargs...), | ||||||||
sinkhorn2(ν, C, ε, algν; plan=nothing, regularization=false, kwargs...) | ||||||||
end | ||||||||
zsteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
return max.(0, OTμν .- (OTμ .+ OTν) / 2) | ||||||||
zsteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
end | ||||||||
""" | ||||||||
|
@@ -290,16 +302,18 @@ function sinkhorn_divergence( | |||||||
alg::Sinkhorn=SinkhornGibbs(), | ||||||||
algμ::Sinkhorn=SymmetricSinkhornGibbs(), | ||||||||
algν::Sinkhorn=SymmetricSinkhornGibbs(); | ||||||||
regularization=nothing, | ||||||||
regularization=true, | ||||||||
zsteve marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
plan=nothing, | ||||||||
kwargs..., | ||||||||
) | ||||||||
if regularization !== nothing | ||||||||
@warn "`sinkhorn_divergence` does not support the `regularization` keyword argument" | ||||||||
OTμν, OTμ, OTν = if (regularization == true) && (plan === nothing) | ||||||||
sinkhorn_loss(μ, ν, Cμν, ε, alg; kwargs...), | ||||||||
sinkhorn_loss(μ, Cμ, ε, algμ; kwargs...), | ||||||||
sinkhorn_loss(ν, Cν, ε, algν; kwargs...) | ||||||||
else | ||||||||
sinkhorn2(μ, ν, Cμν, ε, alg; plan=plan, regularization=false, kwargs...), | ||||||||
sinkhorn2(μ, Cμ, ε, algμ; plan=nothing, regularization=false, kwargs...), | ||||||||
sinkhorn2(ν, Cν, ε, algν; plan=nothing, regularization=false, kwargs...) | ||||||||
end | ||||||||
|
||||||||
OTμν = sinkhorn2(μ, ν, Cμν, ε, alg; plan=plan, regularization=false, kwargs...) | ||||||||
OTμ = sinkhorn2(μ, Cμ, ε, algμ; plan=nothing, regularization=false, kwargs...) | ||||||||
OTν = sinkhorn2(ν, Cν, ε, algν; plan=nothing, regularization=false, kwargs...) | ||||||||
return max.(0, OTμν - (OTμ + OTν) / 2) | ||||||||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we just integrate this in
sinkhorn2
? Or renamesinkhorn2
tosinkhorn_loss
?