Skip to content

Commit

Permalink
Added empircal_sinkhorn_divergence function (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: David Widmann <[email protected]>
  • Loading branch information
3 people committed Jun 3, 2021
1 parent af649a0 commit c7d0f05
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
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

2 comments on commit c7d0f05

@devmotion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/38079

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.4 -m "<description of version>" c7d0f05e417afd9414a52a4134eafcb7a8ee7303
git push origin v0.1.4

Please sign in to comment.