@@ -45,7 +45,7 @@ Some imports.
45
45
<pre data-code-language="python"
46
46
data-executable="true"
47
47
data-type="programlisting">
48
- # That's an impressive list of imports!
48
+ # That's an impressive list of imports.
49
49
import numpy as np
50
50
from numpy import linalg
51
51
from numpy.linalg import norm
@@ -63,18 +63,20 @@ from sklearn.manifold.t_sne import (_joint_probabilities,
63
63
_kl_divergence)
64
64
from sklearn.utils.extmath import _ravel
65
65
66
- # matplotlib for graphics
66
+ # matplotlib for graphics.
67
67
import matplotlib.pyplot as plt
68
68
import matplotlib.patheffects as PathEffects
69
69
import matplotlib
70
+ %matplotlib inline
71
+
72
+ # We import seaborn for improve aesthetics.
73
+ import seaborn as sns
74
+ sns.set_style('darkgrid')
75
+ sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 2.5})
70
76
71
- # We'll generate an animation with matplotlib and moviepy
77
+ # We'll generate an animation with matplotlib and moviepy.
72
78
from moviepy.video.io.bindings import mplfig_to_npimage
73
79
import moviepy.editor as mpy
74
-
75
- # Some matplotlib params.
76
- %matplotlib inline
77
- matplotlib.rcParams.update({'font.size': 22})
78
80
</pre >
79
81
80
82
Illustration on digit dataset.
@@ -290,37 +292,41 @@ animation.write_gif("anim2.gif", fps=20)
290
292
291
293
<img src =" anim2.gif " />
292
294
293
- <pre data-code-language="python"
294
- data-executable="true"
295
- data-type="programlisting">
296
- def simpleaxis(ax):
297
- ax.spines['top'].set_visible(False)
298
- ax.spines['left'].set_visible(False)
299
- ax.set_yticks([]);
300
- ax.get_xaxis().tick_bottom()
301
- ax.set_xticks([0., .5, 1.]);
302
- </pre >
303
-
304
295
<pre data-code-language="python"
305
296
data-executable="true"
306
297
data-type="programlisting">
307
298
npoints = 1000
308
- plt.figure(figsize=(14, 3 ))
299
+ plt.figure(figsize=(15, 4 ))
309
300
for i, D in enumerate((2, 5, 10)):
301
+ # Normally distributed points.
310
302
u = np.random.randn(npoints, D)
303
+ # Now on the sphere.
311
304
u /= norm(u, axis=1)[:, None]
305
+ # Uniform radius.
312
306
r = np.random.rand(npoints, 1)
307
+ # Uniformly within the ball.
313
308
points = u * r**(1./D)
309
+ # Plot.
314
310
ax = plt.subplot(1, 3, i+1)
315
311
ax.set_xlabel('Ball radius')
316
312
if i == 0:
317
- ax.set_ylabel('Distance from\norigin')
318
- simpleaxis(ax)
313
+ ax.set_ylabel('Distance from origin')
319
314
ax.hist(norm(points, axis=1),
320
315
bins=np.linspace(0., 1., 50))
321
316
ax.set_title('D=%d' % D, loc='left')
322
317
</pre >
323
318
319
+ <pre data-code-language="python"
320
+ data-executable="true"
321
+ data-type="programlisting">
322
+ z = np.linspace(0., 5., 1000)
323
+ gauss = np.exp(-z**2)
324
+ cauchy = 1/(1+z**2)
325
+ plt.plot(z, gauss, label='Gaussian distribution');
326
+ plt.plot(z, cauchy, label='Cauchy distribution');
327
+ plt.legend();
328
+ </pre >
329
+
324
330
Equations:
325
331
326
332
<span class =" math-tex " data-type =" tex " >\\ (p_ {j|i} = \frac{\exp(-\lVert\mathbf{x}_ i - \mathbf{x}_ j\rVert^2 / 2\sigma_i^2)}{\sum_ {k \neq i} \exp(-\lVert\mathbf{x}_ i - \mathbf{x}_ k\rVert^2 / 2\sigma_i^2)}\\ )</span >
0 commit comments