-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial barycenter refactor * format * added convergence warning * fix convergence check for barycenters * updated tests * update docs * avoid deprecated use of begin * update compat and replace SinkhornBarycenterGibbs with SinkhornGibbs * fix docs and format * check docs and format
- Loading branch information
Showing
7 changed files
with
202 additions
and
45 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# cache | ||
|
||
struct SinkhornBarycenterGibbsCache{U,V,KT,A} | ||
u::U | ||
v::V | ||
K::KT | ||
Kv::U | ||
a::A | ||
end | ||
|
||
# solver cache | ||
function build_cache( | ||
::Type{T}, ::SinkhornGibbs, size2::Tuple, μ::AbstractMatrix, C::AbstractMatrix, ε::Real | ||
) where {T} | ||
# compute Gibbs kernel (has to be mutable for ε-scaling algorithm) | ||
K = similar(C, T) | ||
@. K = exp(-C / ε) | ||
|
||
# create and initialize dual potentials | ||
u = similar(μ, T, size(μ, 1), size2...) | ||
v = similar(μ, T, size(μ, 1), size2...) | ||
a = similar(μ, T, size(μ, 1), 1) | ||
fill!(u, one(T)) | ||
fill!(v, one(T)) | ||
fill!(a, one(T)) | ||
|
||
# cache for next iterate of `u` | ||
Kv = similar(u) | ||
|
||
return SinkhornBarycenterGibbsCache(u, v, K, Kv, a) | ||
end | ||
|
||
prestep!(::SinkhornBarycenterSolver{SinkhornGibbs}, ::Int) = nothing | ||
|
||
function solution(solver::SinkhornBarycenterSolver{SinkhornGibbs}) | ||
cache = solver.cache | ||
return cache.u[:, 1] .* cache.Kv[:, 1] | ||
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