Skip to content

Added empircal_sinkhorn_divergence function #13

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

Merged
merged 20 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PythonOT"
uuid = "3c485715-4278-42b2-9b5f-8f00e43c12ef"
authors = ["David Widmann"]
version = "0.1.3"
version = "0.1.4"

[deps]
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Expand Down
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ emd2_1d
```@docs
sinkhorn
sinkhorn2
empirical_sinkhorn_divergence
barycenter
```

Expand Down
3 changes: 2 additions & 1 deletion src/PythonOT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export emd,
barycenter,
barycenter_unbalanced,
sinkhorn_unbalanced,
sinkhorn_unbalanced2
sinkhorn_unbalanced2,
empirical_sinkhorn_divergence

const pot = PyCall.PyNULL()

Expand Down
37 changes: 37 additions & 0 deletions src/lib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,43 @@ function sinkhorn2(μ, ν, C, ε; kwargs...)
return pot.sinkhorn2(μ, ν, PyCall.PyReverseDims(permutedims(C)), ε; kwargs...)
end

"""
empirical_sinkhorn_divergence(xsource, xtarget, ε; kwargs...)

Compute the Sinkhorn divergence from empirical data, where `xsource` and `xtarget` are
arrays representing samples in the source domain and target domain, respectively, and `ε`
is the regularization term.

This function is a wrapper of the function
[`ot.bregman.empirical_sinkhorn_divergence`](https://pythonot.github.io/gen_modules/ot.bregman.html#ot.bregman.empirical_sinkhorn_divergence)
in the Python Optimal Transport package. Keyword arguments are listed in the documentation of the Python function.

# Examples

```jldoctest
julia> xsource = [1];

julia> xtarget = [2, 3];

julia> ε = 0.01;

julia> empirical_sinkhorn_divergence(xsource, xtarget, ε) ≈
sinkhorn2([1], [0.5, 0.5], [1 4], ε) -
(
sinkhorn2([1], [1], zeros(1, 1), ε) +
sinkhorn2([0.5, 0.5], [0.5, 0.5], [0 1; 1 0], ε)
) / 2
true
```

See also: [`sinkhorn2`](@ref)
"""
function empirical_sinkhorn_divergence(xsource, xtarget, ε; kwargs...)
return pot.bregman.empirical_sinkhorn_divergence(
reshape(xsource, Val(2)), reshape(xtarget, Val(2)), ε; kwargs...
)
end

"""
sinkhorn_unbalanced(μ, ν, C, ε, λ; kwargs...)

Expand Down