Important: Please read the installation page for details about how to install the toolboxes. $\newcommand{\dotp}[2]{\langle #1, #2 \rangle}$ $\newcommand{\enscond}[2]{\lbrace #1, #2 \rbrace}$ $\newcommand{\pd}[2]{ \frac{ \partial #1}{\partial #2} }$ $\newcommand{\umin}[1]{\underset{#1}{\min}\;}$ $\newcommand{\umax}[1]{\underset{#1}{\max}\;}$ $\newcommand{\umin}[1]{\underset{#1}{\min}\;}$ $\newcommand{\uargmin}[1]{\underset{#1}{argmin}\;}$ $\newcommand{\norm}[1]{\|#1\|}$ $\newcommand{\abs}[1]{\left|#1\right|}$ $\newcommand{\choice}[1]{ \left\{ \begin{array}{l} #1 \end{array} \right. }$ $\newcommand{\pa}[1]{\left(#1\right)}$ $\newcommand{\diag}[1]{{diag}\left( #1 \right)}$ $\newcommand{\qandq}{\quad\text{and}\quad}$ $\newcommand{\qwhereq}{\quad\text{where}\quad}$ $\newcommand{\qifq}{ \quad \text{if} \quad }$ $\newcommand{\qarrq}{ \quad \Longrightarrow \quad }$ $\newcommand{\ZZ}{\mathbb{Z}}$ $\newcommand{\CC}{\mathbb{C}}$ $\newcommand{\RR}{\mathbb{R}}$ $\newcommand{\EE}{\mathbb{E}}$ $\newcommand{\Zz}{\mathcal{Z}}$ $\newcommand{\Ww}{\mathcal{W}}$ $\newcommand{\Vv}{\mathcal{V}}$ $\newcommand{\Nn}{\mathcal{N}}$ $\newcommand{\NN}{\mathcal{N}}$ $\newcommand{\Hh}{\mathcal{H}}$ $\newcommand{\Bb}{\mathcal{B}}$ $\newcommand{\Ee}{\mathcal{E}}$ $\newcommand{\Cc}{\mathcal{C}}$ $\newcommand{\Gg}{\mathcal{G}}$ $\newcommand{\Ss}{\mathcal{S}}$ $\newcommand{\Pp}{\mathcal{P}}$ $\newcommand{\Ff}{\mathcal{F}}$ $\newcommand{\Xx}{\mathcal{X}}$ $\newcommand{\Mm}{\mathcal{M}}$ $\newcommand{\Ii}{\mathcal{I}}$ $\newcommand{\Dd}{\mathcal{D}}$ $\newcommand{\Ll}{\mathcal{L}}$ $\newcommand{\Tt}{\mathcal{T}}$ $\newcommand{\si}{\sigma}$ $\newcommand{\al}{\alpha}$ $\newcommand{\la}{\lambda}$ $\newcommand{\ga}{\gamma}$ $\newcommand{\Ga}{\Gamma}$ $\newcommand{\La}{\Lambda}$ $\newcommand{\si}{\sigma}$ $\newcommand{\Si}{\Sigma}$ $\newcommand{\be}{\beta}$ $\newcommand{\de}{\delta}$ $\newcommand{\De}{\Delta}$ $\newcommand{\phi}{\varphi}$ $\newcommand{\th}{\theta}$ $\newcommand{\om}{\omega}$ $\newcommand{\Om}{\Omega}$
This tour explores the Isomap algorithm for manifold learning.
The <http://waldron.stanford.edu/~isomap/ Isomap> algorithm is introduced in
A Global Geometric Framework for Nonlinear Dimensionality Reduction, J. B. Tenenbaum, V. de Silva and J. C. Langford, Science 290 (5500): 2319-2323, 22 December 2000.
using PyPlot
using NtToolBox
Manifold learning consist in approximating the parameterization of a manifold represented as a point cloud.
First we load a simple 3D point cloud, the famous Swiss Roll.
Number of points.
n = 500; #1000 points leads to very slow computation
Random position on the parameteric domain.
x = rand(2,n);
Mapping on the manifold.
v = 3*pi/2*(.1 + 2*x[1,:])
X = zeros(3,n)
X[2,:] = 20*x[2,:]
X[1,:] = - cos(v).*v
X[3,:] = sin(v).*v;
Parameter for display.
ms = 200
elev = 20; azim = -110;
Display the point cloud.
fig = figure(figsize=(15,11))
ax = gca(projection="3d")
#swiss roll
scatter3D(X[1,:], X[2,:], X[3,:], c=get_cmap("jet")((X[1,:].^2+X[3,:].^2)/100), s=ms, lw=0, alpha=1)
#params
xlim(minimum(X[1,:]),maximum(X[1,:]))
ylim(minimum(X[2,:]),maximum(X[2,:]))
zlim(minimum(X[3,:]),maximum(X[3,:]))
axis("off")
ax[:view_init](elev, azim)
Compute the pairwise Euclidean distance matrix.
D1 = repeat(sum(X.^2, 1), outer=(n,1))
D1 = D1 + D1' - 2*X'*X
D1[D1.<0] = NaN
D1=sqrt(D1);
Number of NN for the graph.
k = 6;
Compute the k-NN connectivity.
DNN, NN = zeros(size(D1)), zeros(size(D1))
for i in 1:size(D1,2)
DNN[i,:], NN[i,:] = sort(D1[i,:]), sortperm(D1[i,:])
end
NN = Int.(NN[:,2:k+1])
DNN = DNN[:,2:k+1];
Adjacency matrix, and weighted adjacency.
B = repeat((1:n)', outer=(k,1))
A = sparse(vec(B), vec(NN'), ones(k*n));
Weighted adjacency (the metric on the graph).
W = sparse(vec(B),vec(NN'), vec(DNN'));
Display the graph.
fig = figure(figsize=(15,11))
ax = gca(projection="3d")
#swiss roll
scatter3D(X[1,:], X[2,:], X[3,:], c=get_cmap("jet")((X[1,:].^2+X[3,:].^2)/100), s=ms, lw=0, alpha=1)
#graph
(I,J) = findn(A)
#(I,J) = (vec(B), vec(NN))
xx = hcat(X[1,I],X[1,J])
yy = hcat(X[2,I],X[2,J])
zz = hcat(X[3,I],X[3,J])
for i in 1:length(I)
plot3D(xx[i,:], yy[i,:], zz[i,:], color="black")
end
#params
xlim(minimum(X[1,:]),maximum(X[1,:]))
ylim(minimum(X[2,:]),maximum(X[2,:]))
zlim(minimum(X[3,:]),maximum(X[3,:]))
axis("off")
ax[:view_init](elev, azim)