Commit fa883a39 authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

ot: update histogram

parent f17f7ae1
......@@ -9,6 +9,8 @@ import ot
class EarthMovers2D:
dimension = '2D'
def __init__(self, n: int):
self.n = n # number of samples
self.p = None
......@@ -93,11 +95,14 @@ class EarthMovers2D:
plt.hist(distances, bins=bins)
ax.set_xlabel("Distance")
ax.set_ylabel("Number of matchings")
ax.set_title(f"Histogram of distance ($p = {self.p}$)")
fig.suptitle("Histogram of distance", fontsize=14)
ax.set_title(f"{self.dimension} - $p = {self.p}$")
class EarthMovers1D(EarthMovers2D):
dimension = '1D'
def _set_positions(self):
# source and target positions
self.xs = np.empty((self.n, 2))
......
......@@ -37,7 +37,7 @@
"%matplotlib inline\n",
"from matplotlib import rcParams\n",
"from matplotlib import pyplot as plt\n",
"from ipywidgets import interact, fixed, FloatSlider, IntSlider\n",
"from ipywidgets import interact, fixed, FloatSlider, RadioButtons\n",
"rcParams['figure.figsize'] = (8., 6.) # Enlarge figure\n",
"rcParams['animation.html'] = 'html5' # to render animation in notebook\n",
"# A slider for p\n",
......@@ -108,7 +108,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the histogram of distance for 2000-position samples on the 2D problem."
"## Histogram of distance"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the histogram of distance for 2000-position samples on the 1D and 2D problems."
]
},
{
......@@ -119,7 +126,12 @@
},
"outputs": [],
"source": [
"interact(em2D_2000.plot_distance_histogram, p=slider, bins=fixed(30));"
"def plot_histogram(dimension=2, p=1.1):\n",
" nsim = 2000\n",
" em = EarthMovers1D(nsim) if dimension == 1 else EarthMovers2D(nsim)\n",
" return em.plot_distance_histogram(p, bins=20)\n",
"\n",
"interact(plot_histogram, dimension=RadioButtons(options=[1, 2], value=2), p=slider);"
]
},
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment