Skip to content

Commit

Permalink
Correcting the 1D example (#150)
Browse files Browse the repository at this point in the history
* 📚 Correcting 1D example

* 📚 Correcting 1D example
  • Loading branch information
davibarreira authored Oct 28, 2021
1 parent 06bcd71 commit 40a1808
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions examples/1D/script.jl → examples/OneDimension/script.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# # 1D Cases
# # One-Dimensional Cases
#
# The 1D case in Optimal Transport is a special case where one can
# easily obtain closed form solutions efficiently
Expand All @@ -18,36 +18,36 @@ using StatsPlots
using LinearAlgebra
using Random

Random.seed!(1234)
Random.seed!(1234);

# ## Continuous Distribution
#
# In the 1D case, when the source measure $\mu$ is continuous and the cost function
# has the form ``c(x, y) = h(|x - y|)`` where ``h`` is a convex function,
# the optimal transport plan is the Monge map
# ```math
# T = F_\\nu^{-1} \\circ F_\\mu
# T = F_\nu^{-1} \circ F_\mu
# ```
# where ``F_\\mu`` is the cumulative distribution function of `μ` and ``F_\\nu^{-1}`` is the
# where ``F_\mu`` is the cumulative distribution function of `μ` and ``F_\nu^{-1}`` is the
# quantile function of `ν`.
# In this setting, the optimal transport cost can be computed as
# ```math
# \\int_0^1 c(F_\\mu^{-1}(x), F_\\nu^{-1}(x)) \\mathrm{d}x
# \int_0^1 c(F_\mu^{-1}(x), F_\nu^{-1}(x)) \mathrm{d}x
# ```
# where ``F_\\mu^{-1}`` and ``F_\\nu^{-1}`` are the quantile functions of `μ` and `ν`,
# where ``F_\mu^{-1}`` and ``F_\nu^{-1}`` are the quantile functions of `μ` and `ν`,
# respectively.
#
# We start by defining the distributions.

μ = Normal(0, 1)

N = 10
ν = Poisson(N)
ν = Poisson(N);

# Nest, we define a cost function.
c(x, y) = (abs(x - y))^2 # could have used `sqeuclidean` from `Distances.jl`

T = ot_plan(c, μ, ν)
T = ot_plan(c, μ, ν);

# `T` is the Monge Map. Let's visualize it.
p1 = plot(μ; label='μ')
Expand Down

0 comments on commit 40a1808

Please sign in to comment.