Course of Dario Trevisan
We solve the earth movers problem using the POT library.
First, some python initializations.
%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.05, value=1.1, continuous_update=False)
from earth_movers import EarthMovers1D, EarthMovers2D
Solve the earth movers problem for 50-position samples.
em1D = EarthMovers1D(50)
interact(em1D.plot_ot, p=FloatSlider(**sliderd), plot_points=fixed(True));
Solve the earth movers problem for 50-position samples.
em2D = EarthMovers2D(100)
interact(em2D.plot_ot, p=FloatSlider(**sliderd), plot_points=fixed(True));
Solve the earth movers problem for 1000-position samples. The darker the line, the longer the distance.
em2D_large = EarthMovers2D(1000)
interact(em2D_large.plot_ot, p=FloatSlider(**sliderd), plot_points=fixed(False));
Plot the histogram of distance for 2000-position samples on the 1D and 2D problems.
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));
PoT: https://pot.readthedocs.io/en/stable/auto_examples/plot_OT_2D_samples.html