# Manifold Learning with Isomap¶


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.

In [2]:
addpath('toolbox_signal')


## Graph Approximation of Manifolds¶

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.

In [3]:
n = 1000;


Random position on the parameteric domain.

In [4]:
x = rand(2,n);


Mapping on the manifold.

In [5]:
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.

In [6]:
ms = 50;
lw = 1.5;
v1 = -15; v2 = 20;


Display the point cloud.

In [7]:
clf;
scatter3(X(1,:),X(2,:),X(3,:),ms,v, 'filled');
colormap jet(256);
view(v1,v2); axis('equal'); axis('off');


Compute the pairwise Euclidean distance matrix.

In [8]:
D1 = repmat(sum(X.^2,1),n,1);
D1 = sqrt(D1 + D1' - 2*X'*X);


Number of NN for the graph.

In [9]:
k = 6;


Compute the k-NN connectivity.

In [10]:
[DNN,NN] = sort(D1);
NN = NN(2:k+1,:);
DNN = DNN(2:k+1,:);


In [11]:
B = repmat(1:n, [k 1]);
A = sparse(B(:), NN(:), ones(k*n,1));


Weighted adjacency (the metric on the graph).

In [12]:
W = sparse(B(:), NN(:), DNN(:));


Display the graph.

In [13]:
options.lw = lw;
options.ps = 0.01;
clf; hold on;
scatter3(X(1,:),X(2,:),X(3,:),ms,v, 'filled');
plot_graph(A, X, options);
colormap jet(256);
view(v1,v2); axis('equal'); axis('off');
zoom(.8);


## Floyd Algorithm to Compute Pairwise Geodesic Distances¶

A simple algorithm to compute the geodesic distances between all pairs of points on a graph is Floyd iterative algorithm. Its complexity is |O(n^3)| where |n| is the number of points. It is thus quite slow for sparse graph, where Dijkstra runs in |O(log(n)*n^2)|.

Floyd algorithm iterates the following update rule, for |k=1,...,n|

|D(i,j) <- min(D(i,j), D(i,k)+D(k,j)|,

with the initialization |D(i,j)=W(i,j)| if |W(i,j)>0|, and |D(i,j)=Inf| if |W(i,j)=0|.

Make the graph symmetric.

In [14]:
D = full(W);
D = (D+D')/2;


Initialize the matrix.

In [15]:
D(D==0) = Inf;


Add connexion between a point and itself.

In [16]:
D = D - diag(diag(D));


Exercise 1

Implement the Floyd algorithm to compute the full distance matrix |D|, where |D(i,j)| is the geodesic distance between

In [17]:
exo1()

In [18]:
%% Insert your code here.


Find index of vertices that are not connected to the main manifold.

In [19]:
Iremove = find(D(:,1)==Inf);


Remove Inf remaining values (disconnected comonents).

In [20]:
D(D==Inf) = 0;


## Isomap with Classical Multidimensional Scaling¶

Isomap perform the dimensionality reduction by applying multidimensional scaling.

Please refers to the tours on Bending Invariant for detail on Classical MDS (strain minimization).

Exercise 2

Perform classical MDS to compute the 2D flattening. entered kernel iagonalization lot graph

In [21]:
exo2()

In [22]:
%% Insert your code here.


Redess the points using the two leading eigenvectors of the covariance matrix (PCA correction).

In [23]:
[U,L] = eig(Xstrain*Xstrain' / n);
Xstrain1 = U'*Xstrain;


Remove problematic points.

In [24]:
Xstrain1(:,Iremove) = Inf;


Display the final result of the dimensionality reduction.

In [25]:
clf; hold on;
scatter(Xstrain1(1,:),Xstrain1(2,:),ms,v, 'filled');
plot_graph(A, Xstrain1, options);
colormap jet(256);
axis('equal'); axis('off');


For comparison, the ideal locations on the parameter domain.

In [26]:
Y = cat(1, v, X(2,:));
Y(1,:) = rescale(Y(1,:), min(Xstrain(1,:)), max(Xstrain(1,:)));
Y(2,:) = rescale(Y(2,:), min(Xstrain(2,:)), max(Xstrain(2,:)));


Display the ideal graph on the reduced parameter domain.

In [27]:
clf; hold on;
scatter(Y(1,:),Y(2,:),ms,v, 'filled');
plot_graph(A,  Y, options);
colormap jet(256);
axis('equal'); axis('off');
camroll(90);