Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
proba-mc2020
proba-mc2020
Commits
470de7ea
Commit
470de7ea
authored
Feb 03, 2020
by
Matthieu Boileau
Browse files
Minor change in optimal_transport
parent
71f17284
Changes
1
Hide whitespace changes
Inline
Side-by-side
optimal_transport.ipynb
View file @
470de7ea
...
...
@@ -43,7 +43,7 @@
"from ipywidgets import interact, fixed, FloatSlider, RadioButtons\n",
"rcParams['figure.figsize'] = (8., 6.) # Enlarge figure\n",
"# A slider for p\n",
"sliderd = dict(min=-1., max=2., step=0.
1
, value=1.1, continuous_update=False)\n",
"sliderd = dict(min=-1., max=2., step=0.
05
, value=1.1, continuous_update=False)\n",
"\n",
"from earth_movers import EarthMovers1D, EarthMovers2D"
]
...
...
@@ -105,7 +105,8 @@
}
},
"source": [
"Solve the earth movers problem for 1000-position samples."
"Solve the earth movers problem for 1000-position samples.\n",
"The darker the line, the longer the distance."
]
},
{
...
...
%% Cell type:markdown id: tags:
# Course of Dario Trevisan: Optimal transport
%% Cell type:markdown id: tags:
We solve the earth movers problem using the
[
POT
](
https://pot.readthedocs.io/en/stable/index.html
)
library.
First, some python initializations.
%% Cell type:code id: tags:
```
python
%
matplotlib
inline
from
matplotlib
import
rcParams
from
ipywidgets
import
interact
,
fixed
,
FloatSlider
,
RadioButtons
rcParams
[
'figure.figsize'
]
=
(
8.
,
6.
)
# Enlarge figure
# A slider for p
sliderd
=
dict
(
min
=-
1.
,
max
=
2.
,
step
=
0.
1
,
value
=
1.1
,
continuous_update
=
False
)
sliderd
=
dict
(
min
=-
1.
,
max
=
2.
,
step
=
0.
05
,
value
=
1.1
,
continuous_update
=
False
)
from
earth_movers
import
EarthMovers1D
,
EarthMovers2D
```
%% Cell type:markdown id: tags:
## 1D case
Solve the earth movers problem for 50-position samples.
%% Cell type:code id: tags:
```
python
em1D
=
EarthMovers1D
(
50
)
interact
(
em1D
.
plot_ot
,
p
=
FloatSlider
(
**
sliderd
),
plot_points
=
fixed
(
True
));
```
%% Cell type:markdown id: tags:
## 2D case
Solve the earth movers problem for 50-position samples.
%% Cell type:code id: tags:
```
python
em2D
=
EarthMovers2D
(
100
)
interact
(
em2D
.
plot_ot
,
p
=
FloatSlider
(
**
sliderd
),
plot_points
=
fixed
(
True
));
```
%% Cell type:markdown id: tags:
Solve the earth movers problem for 1000-position samples.
The darker the line, the longer the distance.
%% Cell type:code id: tags:
```
python
em2D_large
=
EarthMovers2D
(
1000
)
interact
(
em2D_large
.
plot_ot
,
p
=
FloatSlider
(
**
sliderd
),
plot_points
=
fixed
(
False
));
```
%% Cell type:markdown id: tags:
## Histogram of distance
%% Cell type:markdown id: tags:
Plot the histogram of distance for 2000-position samples on the 1D and 2D problems.
%% Cell type:code id: tags:
```
python
def
plot_histogram
(
dimension
=
2
,
p
=
1.1
):
nsim
=
2000
em
=
EarthMovers1D
(
nsim
)
if
dimension
==
1
else
EarthMovers2D
(
nsim
)
return
em
.
plot_distance_histogram
(
p
,
bins
=
20
)
interact
(
plot_histogram
,
dimension
=
RadioButtons
(
options
=
[
1
,
2
],
value
=
2
),
p
=
FloatSlider
(
**
sliderd
));
```
%% Cell type:markdown id: tags:
## Todo
-
Uniform random blue and red points on a square #
-
Its optimal mathching, with p=1, n=500 #
-
Histogram of matching length in d=1,2,3 #
-
one dimensional matching for p=1.1 and p=0.9, comparison
-
The scaling algorithm for local optimal matching
PoT:
<https://pot.readthedocs.io/en/stable/auto_examples/plot_OT_2D_samples.html>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment