1
1
"""
2
2
emd(μ, ν, C; kwargs...)
3
3
4
- Compute the optimal transport map for the Monge-Kantorovich problem with source and target
4
+ Compute the optimal transport plan for the Monge-Kantorovich problem with source and target
5
5
marginals `μ` and `ν` and cost matrix `C` of size `(length(μ), length(ν))`.
6
6
7
- The optimal transport map `γ` is of the same size as `C` and solves
7
+ The optimal transport plan `γ` is of the same size as `C` and solves
8
8
```math
9
9
\\ inf_{\\ gamma \\ in \\ Pi(\\ mu, \\ nu)} \\ langle \\ gamma, C \\ rangle.
10
10
```
@@ -20,9 +20,7 @@ julia> μ = [0.5, 0.2, 0.3];
20
20
21
21
julia> ν = [0.0, 1.0];
22
22
23
- julia> C = [0.0 1.0;
24
- 2.0 0.0;
25
- 0.5 1.5];
23
+ julia> C = [0.0 1.0; 2.0 0.0; 0.5 1.5];
26
24
27
25
julia> emd(μ, ν, C)
28
26
3×2 Matrix{Float64}:
@@ -59,9 +57,7 @@ julia> μ = [0.5, 0.2, 0.3];
59
57
60
58
julia> ν = [0.0, 1.0];
61
59
62
- julia> C = [0.0 1.0;
63
- 2.0 0.0;
64
- 0.5 1.5];
60
+ julia> C = [0.0 1.0; 2.0 0.0; 0.5 1.5];
65
61
66
62
julia> emd2(μ, ν, C)
67
63
0.95
76
72
"""
77
73
sinkhorn(μ, ν, C, ε; kwargs...)
78
74
79
- Compute the optimal transport map for the entropic regularization optimal transport problem
75
+ Compute the optimal transport plan for the entropic regularization optimal transport problem
80
76
with source and target marginals `μ` and `ν`, cost matrix `C` of size
81
77
`(length(μ), length(ν))`, and entropic regularization parameter `ε`.
82
78
83
- The optimal transport map `γ` is of the same size as `C` and solves
79
+ The optimal transport plan `γ` is of the same size as `C` and solves
84
80
```math
85
81
\\ inf_{\\ gamma \\ in \\ Pi(\\ mu, \\ nu)} \\ langle \\ gamma, C \\ rangle
86
82
+ \\ varepsilon \\ Omega(\\ gamma),
@@ -94,14 +90,12 @@ Transport package. Keyword arguments are listed in the documentation of the Pyth
94
90
95
91
# Examples
96
92
97
- ```jldoctest
93
+ ```jldoctest sinkhorn
98
94
julia> μ = [0.5, 0.2, 0.3];
99
95
100
96
julia> ν = [0.0, 1.0];
101
97
102
- julia> C = [0.0 1.0;
103
- 2.0 0.0;
104
- 0.5 1.5];
98
+ julia> C = [0.0 1.0; 2.0 0.0; 0.5 1.5];
105
99
106
100
julia> sinkhorn(μ, ν, C, 0.01)
107
101
3×2 Matrix{Float64}:
@@ -110,6 +104,18 @@ julia> sinkhorn(μ, ν, C, 0.01)
110
104
0.0 0.3
111
105
```
112
106
107
+ It is possible to provide multiple target marginals as columns of a matrix. In this case the
108
+ optimal transport costs are returned:
109
+
110
+ ```jldoctest sinkhorn
111
+ julia> ν = [0.0 0.5; 1.0 0.5];
112
+
113
+ julia> round.(sinkhorn(μ, ν, C, 0.01); sigdigits=6)
114
+ 2-element Vector{Float64}:
115
+ 0.95
116
+ 0.45
117
+ ```
118
+
113
119
See also: [`sinkhorn2`](@ref)
114
120
"""
115
121
function sinkhorn (μ, ν, C, ε; kwargs... )
@@ -137,20 +143,29 @@ Transport package. Keyword arguments are listed in the documentation of the Pyth
137
143
138
144
# Examples
139
145
140
- ```jldoctest
146
+ ```jldoctest sinkhorn2
141
147
julia> μ = [0.5, 0.2, 0.3];
142
148
143
149
julia> ν = [0.0, 1.0];
144
150
145
- julia> C = [0.0 1.0;
146
- 2.0 0.0;
147
- 0.5 1.5];
151
+ julia> C = [0.0 1.0; 2.0 0.0; 0.5 1.5];
148
152
149
153
julia> round.(sinkhorn2(μ, ν, C, 0.01); sigdigits=6)
150
154
1-element Vector{Float64}:
151
155
0.95
152
156
```
153
157
158
+ It is possible to provide multiple target marginals as columns of a matrix.
159
+
160
+ ```jldoctest sinkhorn2
161
+ julia> ν = [0.0 0.5; 1.0 0.5];
162
+
163
+ julia> round.(sinkhorn2(μ, ν, C, 0.01); sigdigits=6)
164
+ 2-element Vector{Float64}:
165
+ 0.95
166
+ 0.45
167
+ ```
168
+
154
169
See also: [`sinkhorn`](@ref)
155
170
"""
156
171
function sinkhorn2 (μ, ν, C, ε; kwargs... )
@@ -160,12 +175,12 @@ end
160
175
"""
161
176
sinkhorn_unbalanced(μ, ν, C, ε, λ; kwargs...)
162
177
163
- Compute the optimal transport map for the unbalanced entropic regularization optimal
178
+ Compute the optimal transport plan for the unbalanced entropic regularization optimal
164
179
transport problem with source and target marginals `μ` and `ν`, cost matrix `C` of size
165
180
`(length(μ), length(ν))`, entropic regularization parameter `ε`, and marginal relaxation
166
181
term `λ`.
167
182
168
- The optimal transport map `γ` is of the same size as `C` and solves
183
+ The optimal transport plan `γ` is of the same size as `C` and solves
169
184
```math
170
185
\\ inf_{\\ gamma} \\ langle \\ gamma, C \\ rangle
171
186
+ \\ varepsilon \\ Omega(\\ gamma)
@@ -182,14 +197,12 @@ Python function.
182
197
183
198
# Examples
184
199
185
- ```jldoctest
200
+ ```jldoctest sinkhorn_unbalanced
186
201
julia> μ = [0.5, 0.2, 0.3];
187
202
188
203
julia> ν = [0.0, 1.0];
189
204
190
- julia> C = [0.0 1.0;
191
- 2.0 0.0;
192
- 0.5 1.5];
205
+ julia> C = [0.0 1.0; 2.0 0.0; 0.5 1.5];
193
206
194
207
julia> sinkhorn_unbalanced(μ, ν, C, 0.01, 1_000)
195
208
3×2 Matrix{Float64}:
@@ -198,6 +211,18 @@ julia> sinkhorn_unbalanced(μ, ν, C, 0.01, 1_000)
198
211
0.0 0.29983
199
212
```
200
213
214
+ It is possible to provide multiple target marginals as columns of a matrix. In this case the
215
+ optimal transport costs are returned:
216
+
217
+ ```jldoctest sinkhorn_unbalanced
218
+ julia> ν = [0.0 0.5; 1.0 0.5];
219
+
220
+ julia> round.(sinkhorn_unbalanced(μ, ν, C, 0.01, 1_000); sigdigits=6)
221
+ 2-element Vector{Float64}:
222
+ 0.949709
223
+ 0.449411
224
+ ```
225
+
201
226
See also: [`sinkhorn_unbalanced2`](@ref)
202
227
"""
203
228
function sinkhorn_unbalanced (μ, ν, C, ε, λ; kwargs... )
@@ -231,20 +256,29 @@ Python function.
231
256
232
257
# Examples
233
258
234
- ```jldoctest
259
+ ```jldoctest sinkhorn_unbalanced2
235
260
julia> μ = [0.5, 0.2, 0.3];
236
261
237
262
julia> ν = [0.0, 1.0];
238
263
239
- julia> C = [0.0 1.0;
240
- 2.0 0.0;
241
- 0.5 1.5];
264
+ julia> C = [0.0 1.0; 2.0 0.0; 0.5 1.5];
242
265
243
266
julia> round.(sinkhorn_unbalanced2(μ, ν, C, 0.01, 1_000); sigdigits=6)
244
267
1-element Vector{Float64}:
245
268
0.949709
246
269
```
247
270
271
+ It is possible to provide multiple target marginals as columns of a matrix:
272
+
273
+ ```jldoctest sinkhorn_unbalanced2
274
+ julia> ν = [0.0 0.5; 1.0 0.5];
275
+
276
+ julia> round.(sinkhorn_unbalanced2(μ, ν, C, 0.01, 1_000); sigdigits=6)
277
+ 2-element Vector{Float64}:
278
+ 0.949709
279
+ 0.449411
280
+ ```
281
+
248
282
See also: [`sinkhorn_unbalanced`](@ref)
249
283
"""
250
284
function sinkhorn_unbalanced2 (μ, ν, C, ε, λ; kwargs... )
@@ -263,7 +297,7 @@ The Wasserstein barycenter is a histogram and solves
263
297
```math
264
298
\\ inf_{a} \\ sum_{i} W_{\\ varepsilon,C}(a, a_i),
265
299
```
266
- where the histograms ``a_i`` are columns of matrix `A` and ``W_{\\ varepsilon,C}(a, a_i)} ``
300
+ where the histograms ``a_i`` are columns of matrix `A` and ``W_{\\ varepsilon,C}(a, a_i)``
267
301
is the optimal transport cost for the entropically regularized optimal transport problem
268
302
with marginals ``a`` and ``a_i``, cost matrix ``C``, and entropic regularization parameter
269
303
``\\ varepsilon``. Optionally, weights of the histograms ``a_i`` can be provided with the
@@ -287,11 +321,4 @@ julia> isapprox(sum(barycenter(A, C, 0.01; method="sinkhorn_stabilized")), 1; at
287
321
true
288
322
```
289
323
"""
290
- function barycenter (A, C, ε; kwargs... )
291
- return pot. barycenter (
292
- PyCall. PyReverseDims (permutedims (A)),
293
- PyCall. PyReverseDims (permutedims (C)),
294
- ε;
295
- kwargs... ,
296
- )
297
- end
324
+ barycenter (A, C, ε; kwargs... ) = pot. barycenter (A, C, ε; kwargs... )
0 commit comments