In [2]:
from numpy.linalg import inv
from scipy.linalg import eig
import numpy as np
from sklearn.datasets import make_swiss_roll
from sklearn.metrics import pairwise_distances
from diffmaps_util import *
In [3]:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
In [4]:
%matplotlib nbagg
In [5]:
X, y = make_swiss_roll(n_samples=1000, noise=.5, random_state=0)
X[:5]
Out[5]:
In [14]:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X[:,0], X[:,1], X[:,2], c=y)
Out[14]:
In [6]:
L = k(X, 8.)
print 'L shape %s %s' % L.shape
D = diag(L)
print 'D shape %s %s' % D.shape
M = inv(D).dot(L)
print 'M shape %s %s' % M.shape
w, v = eig(M)
w = np.abs(w.real)
v = v.real
print 'eigenvalue shape %s' % w.shape
print 'eigenvector shape %s %s' % v.shape
In [7]:
w, v = sort_eigens(w, v)
print 'eigenvalue shape %s' % w.shape
print 'eigenvector shape %s %s' % v.shape
In [8]:
psi = v / v[:,0]
psi.shape
Out[8]:
In [9]:
diffmap = (w.reshape(-1,1) * psi.T).T[:,1:]
diffmap.shape
Out[9]:
In [11]:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
diffmap = (w.reshape(-1,1) ** 5000 * psi.T).T[:,1:]
diffmap.shape
ax.scatter(diffmap[:,0], diffmap[:,1], diffmap[:,2], c=y )
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
Out[11]: