Commit 470de7ea by Matthieu Boileau

Minor change in optimal_transport

parent 71f17284
 %% 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: ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!