In [68]:
import sys
sys.path.append('../scripts/')

In [285]:
import matplotlib.pyplot as plt
import numpy as np
import numpy.random as npr
%matplotlib inline
plt.rcParams['font.family']='Serif'

In [2]:
npr.seed(0)

In [3]:
X = np.vstack((npr.randn(1000,3),
               npr.randn(1000,3)+5))

In [ ]:
X = np.vstack(([]))

In [423]:
import itertools
dim=3
radius=1
corners = [(np.array(i)*radius+radius)/2 for i in itertools.product([-1,1],repeat=dim)]

In [424]:
def coord_str(array):
    str_a = [str(int(elem)) for elem in array]
    return "(" + ", ".join(str_a) + ")"

In [425]:
from scipy.spatial.distance import pdist,squareform
plt.imshow(squareform(pdist(corners)),interpolation='none',cmap='Blues')
plt.colorbar()
#plt.axis('off')
plt.yticks(np.arange(len(corners)),[coord_str(c) for c in corners])
plt.xticks(np.arange(len(corners)),[coord_str(c) for c in corners],rotation=30)


Out[425]:
([<matplotlib.axis.XTick at 0x139dd72b0>,
  <matplotlib.axis.XTick at 0x139dcf588>,
  <matplotlib.axis.XTick at 0x139dd5f60>,
  <matplotlib.axis.XTick at 0x139e0a208>,
  <matplotlib.axis.XTick at 0x139f047b8>,
  <matplotlib.axis.XTick at 0x139f08208>,
  <matplotlib.axis.XTick at 0x139f08c18>,
  <matplotlib.axis.XTick at 0x139f0b668>],
 <a list of 8 Text xticklabel objects>)

In [419]:
for d in range(1,12):
    corners = [np.array(i) for i in itertools.product([-1,1],repeat=d)]
    plt.imshow(squareform(pdist(corners)),interpolation='none')
    plt.colorbar()
    #plt.yticks(np.arange(len(corners)),[str(c) for c in corners])
    plt.title('{0}D hypercube'.format(d))
    plt.savefig('../figures/hypercube-d={0}.jpg'.format(d),dpi=300)
    plt.close()

In [400]:
for d in range(1,13):
    corners = [np.array(i) for i in itertools.product([-1,1],repeat=d)]
    plt.imshow(squareform(pdist(corners)),interpolation='none',cmap='Blues')
    plt.axis('off')
    #plt.colorbar()
    #plt.yticks(np.arange(len(corners)),[str(c) for c in corners])
    #plt.title('{0}D hypercube'.format(d))
    plt.savefig('../figures/blue-hypercube-nolabel-d={0}.jpg'.format(d),dpi=300)
    plt.close()

In [ ]:


In [182]:
corners = [np.array(i) for i in itertools.product([-1,1],repeat=13)]
plt.hist(pdist(corners),bins=10);



In [183]:
len(set(pdist(corners)))


Out[183]:
13

In [ ]:
print(corners[0])

In [279]:
n=100
X = np.vstack([npr.randn(n,dim) + c for c in corners])
Y = np.hstack([np.ones(n)*r for r in range(len(corners))])
X.shape,Y.shape


Out[279]:
((800, 3), (800,))

In [240]:
def generate_hypercube(dim=3,radius=4,n_tot=100):
    corners = [np.array(i)*radius for i in itertools.product([-1,1],repeat=dim)]
    n = int(n_tot / len(corners))
    X = np.vstack([npr.randn(n,dim) + c for c in corners])
    Y = np.hstack([np.ones(n)*r for r in range(len(corners))])
    return X,Y

In [318]:
X,Y = generate_hypercube(4,n_tot=1400)

In [319]:
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X[:,0],X[:,1],X[:,2],c=Y,linewidths=0,alpha=0.5)


Out[319]:
<mpl_toolkits.mplot3d.art3d.Path3DCollection at 0x11a87d198>

In [335]:
plt.scatter(X[:,0],X[:,1],c=Y,linewidths=0,alpha=0.5)


Out[335]:
<matplotlib.collections.PathCollection at 0x11cb9d7f0>

In [321]:
from sklearn.decomposition import PCA
pca = PCA()
pca.fit(X)


Out[321]:
PCA(copy=True, n_components=None, whiten=False)

In [322]:
pca.explained_variance_ratio_


Out[322]:
array([ 0.25703139,  0.24887468,  0.24822486,  0.24586907])

In [323]:
X_ = pca.transform(X)[:,:2]

In [359]:
plt.scatter(X_[:,0],X_[:,1],c=Y,linewidths=0,alpha=0.5)
plt.tick_params(labelleft='off',
    labelbottom='off') # labels along the bottom edge are off



In [445]:
ds = list(range(3,7))
#algs = []
results = dict()
num_algs = 3
for i,d in enumerate(ds):
    X,Y = generate_hypercube(d,n_tot=1400)
    pca = PCA()
    pca.fit(X)
    X_ = pca.transform(X)[:,:2]
    plt.subplot(len(ds),num_algs,(num_algs*i)+1)
    #plt.title('PCA: {0}D hypercube'.format(d))
    if i == 0:
        plt.title('PCA')
    plt.scatter(X_[:,0],X_[:,1],c=Y,linewidths=0,alpha=0.5,s=3)
    plt.tick_params(labelleft='off',labelbottom='off')
    #plt.xlabel('PC1')
    #plt.ylabel('PC2')
    plt.ylabel('{0}D'.format(d))
    
    #X_tpe = X_tsne = X_
    
    tpe = TPE('complete')
    X_tpe = tpe.fit_transform(X)
    plt.subplot(len(ds),num_algs,(num_algs*i)+2)
    if i == 0:
        plt.title('TPE')
    #plt.title('TPE: {0}D hypercube'.format(d))
    plt.scatter(X_tpe[:,0],X_tpe[:,1],c=Y,linewidths=0,alpha=0.5,s=3)
    plt.tick_params(labelleft='off',labelbottom='off')
    
    tsne = TSNE()
    X_tsne = tsne.fit_transform(X)
    plt.subplot(len(ds),num_algs,(num_algs*i)+3)
    if i == 0:
        plt.title('t-SNE')
    plt.scatter(X_tsne[:,0],X_tsne[:,1],c=Y,linewidths=0,alpha=0.5,s=3)
    plt.tick_params(labelleft='off',labelbottom='off')
    
    results[d] = (X_,X_tpe,X_tsne)
    
plt.tight_layout()
plt.savefig('blah-complete.pdf')



In [446]:
for d in results:
    for a in results[d]:
        _,Y = generate_hypercube(d,n_tot=1400)
        print(one_nn_class_baseline(a,Y))
    print()


0.954285714286
0.999285714286
1.0

0.665948275862
0.999281609195
1.0

0.524709302326
0.99636627907
0.998546511628

0.33556547619
0.997023809524
1.0


In [482]:
d = 6
X_pca,X_tpe,X_tsne = results[d]
X,Y = generate_hypercube(d,n_tot=1400)
cluster_centers = np.array([np.mean(X[Y==y],0) for y in set(Y)])
cluster_centers_pca = np.array([np.mean(X_pca[Y==y],0) for y in set(Y)])
cluster_centers_tpe = np.array([np.mean(X_tpe[Y==y],0) for y in set(Y)])
cluster_centers_tsne = np.array([np.mean(X_tsne[Y==y],0) for y in set(Y)])

In [499]:
plt.scatter(pdist(cluster_centers_pca),pdist(cluster_centers),alpha=0.5,linewidths=0)
plt.xlabel("Inter-cluster distances in PCA embedding")
plt.ylabel("Ground-truth inter-cluster distances")
plt.title('PCA')
plt.figure()

plt.scatter(pdist(cluster_centers_tpe),pdist(cluster_centers),alpha=0.5,linewidths=0)
plt.xlabel("Inter-cluster distances in Approx. TPE embedding")
plt.ylabel("Ground-truth inter-cluster distances")
plt.title('Approx. TPE')

plt.figure()

plt.scatter(pdist(cluster_centers_tsne),pdist(cluster_centers),alpha=0.5,linewidths=0)
plt.xlabel("Inter-cluster distances in t-SNE embedding")
plt.ylabel("Ground-truth inter-cluster distances")
plt.title('t-SNE')
plt.figure()


Out[499]:
<matplotlib.figure.Figure at 0x13a3c3be0>
<matplotlib.figure.Figure at 0x13a3c3be0>

In [501]:
from sklearn.metrics import r2_score
r2_score(pdist(cluster_centers),pdist(cluster_centers_pca))


Out[501]:
-5.4105023128029384

In [502]:
r2_score(pdist(cluster_centers),pdist(cluster_centers_tpe))


Out[502]:
-14.074424698056925

In [503]:
r2_score(pdist(cluster_centers),pdist(cluster_centers_tsne))


Out[503]:
-44.05004443285263

In [487]:
plt.imshow(squareform(pdist(cluster_centers)),interpolation='none',cmap='Blues')
plt.title('Ground-truth inter-cluster distances')
plt.figure()
plt.imshow(squareform(pdist(cluster_centers_pca)),interpolation='none',cmap='Blues')
plt.title('PCA inter-cluster distances')
plt.figure()
plt.imshow(squareform(pdist(cluster_centers_tpe)),interpolation='none',cmap='Blues')
plt.title('TPE inter-cluster distances')
plt.figure()
plt.imshow(squareform(pdist(cluster_centers_tsne)),interpolation='none',cmap='Blues')
plt.title('t-SNE inter-cluster distances')


Out[487]:
<matplotlib.text.Text at 0x136be02b0>

In [508]:
from sklearn.manifold import MDS
mds = MDS(dissimilarity='precomputed')
mds_centers = mds.fit_transform(squareform(pdist(cluster_centers)))

In [509]:
r2_score(pdist(cluster_centers),pdist(mds_centers))


Out[509]:
-1.9765479419190863

In [510]:
plt.imshow(squareform(pdist(mds_centers)),interpolation='none',cmap='Blues')
plt.title('Directly optimized inter-cluster distances')


Out[510]:
<matplotlib.text.Text at 0x13a0bb240>

In [513]:
plt.scatter(pdist(mds_centers),pdist(cluster_centers),alpha=0.5,linewidths=0)
plt.xlabel("Directly optimized inter-cluster distances (2D)")
plt.ylabel("Ground-truth inter-cluster distances (6D)")
plt.figure()


Out[513]:
<matplotlib.figure.Figure at 0x13a38f0f0>
<matplotlib.figure.Figure at 0x13a38f0f0>

In [340]:
for i,d in enumerate(ds):
    print(i,d)


0 3
1 4
2 5
3 6

In [331]:
len(set(Y))


Out[331]:
16

In [332]:
2**6


Out[332]:
64

In [329]:
2**7


Out[329]:
128

In [297]:
X_.shape,Y.shape


Out[297]:
((800, 2), (800,))

In [298]:
from sklearn.decomposition import FastICA
ica = FastICA(n_components=2)
X_ica = ica.fit_transform(X)
plt.scatter(X_ica[:,0],X_ica[:,1],c=Y,linewidths=0,alpha=0.5)


Out[298]:
<matplotlib.collections.PathCollection at 0x112060b70>

In [299]:
from sklearn import neighbors
def one_nn_baseline(X,Y):
    one_nn_X = neighbors.kneighbors_graph(X,2)
    one_nn_Y = neighbors.kneighbors_graph(Y,2)
    sames = 0
    for i in range(len(X)):
        neighbor_X = one_nn_X[i].indices[one_nn_X[i].indices!=i][0]
        neighbor_Y = one_nn_Y[i].indices[one_nn_Y[i].indices!=i][0]
        if neighbor_X == neighbor_Y:
            sames+=1
    return 1.0*sames / len(X)

def one_nn_class_baseline(X,Y):
    one_nn = neighbors.kneighbors_graph(X,2)
    inds = np.zeros(len(X),dtype=int)
    for i in range(len(X)):
        inds[i] = [ind for ind in one_nn[i].indices if ind != i][0]
    preds = Y[inds]
    return 1.0*sum(preds==Y) / len(Y)

In [300]:
one_nn_baseline(X_,X),one_nn_class_baseline(X_,Y)


Out[300]:
(0.2125, 0.85875000000000001)

In [301]:
one_nn_class_baseline(X_ica,Y)


Out[301]:
0.85875000000000001

In [302]:
# example, if we have clusters centered on corners of a cube, then there's no linear projection that preserves all the clusters

In [303]:
from tpe import TPE

In [304]:
tpe = TPE()

In [305]:
X_tpe = tpe.fit_transform(X)

In [306]:
plt.scatter(X_tpe[:,0],X_tpe[:,1],c=Y,linewidths=0,alpha=0.5)


Out[306]:
<matplotlib.collections.PathCollection at 0x11094b278>

In [307]:
one_nn_class_baseline(X_tpe,Y)


Out[307]:
0.99875000000000003

In [308]:
from sklearn.manifold import Isomap
iso = Isomap()
X_iso = iso.fit_transform(X)
plt.scatter(X_iso[:,0],X_iso[:,1],c=Y,linewidths=0,alpha=0.5)


Out[308]:
<matplotlib.collections.PathCollection at 0x12442d6a0>

In [309]:
one_nn_class_baseline(X_iso,Y)


Out[309]:
0.43375000000000002

In [310]:
from sklearn.manifold import LocallyLinearEmbedding
lle = LocallyLinearEmbedding()
X_lle = lle.fit_transform(X)
plt.scatter(X_lle[:,0],X_lle[:,1],c=Y,linewidths=0,alpha=0.5)


Out[310]:
<matplotlib.collections.PathCollection at 0x1167746d8>

In [311]:
from sklearn.manifold import TSNE
tsne = TSNE()
X_tsne = tsne.fit_transform(X)
plt.scatter(X_tsne[:,0],X_tsne[:,1],c=Y,linewidths=0,alpha=0.5)


Out[311]:
<matplotlib.collections.PathCollection at 0x114f75a90>

In [ ]:


In [312]:
one_nn_class_baseline(X_tsne,Y)


Out[312]:
0.99875000000000003

In [313]:
from sklearn.decomposition import KernelPCA

In [314]:
kpca = KernelPCA(n_components=2,kernel='rbf',gamma=0.05)
X_kpca = kpca.fit_transform(X)

In [315]:
plt.scatter(X_kpca[:,0],X_kpca[:,1],c=Y,linewidths=0,alpha=0.5)


Out[315]:
<matplotlib.collections.PathCollection at 0x11bf60550>

In [316]:
one_nn_class_baseline(X_kpca,Y)


Out[316]:
0.995

In [317]:
X_l,Y_l = generate_hypercube(8,n_tot=2000)
kpca = KernelPCA(n_components=2,kernel='rbf',gamma=0.06)
X_kpca = kpca.fit_transform(X_l)
plt.scatter(X_kpca[:,0],X_kpca[:,1],c=Y_l,linewidths=0,alpha=0.5)


Out[317]:
<matplotlib.collections.PathCollection at 0x11a49f080>

In [ ]:
# what if the clusters are not isotropic

In [427]:
from scipy.cluster import hierarchy

In [438]:
dim=6
radius=1
corners = [(np.array(i)*radius+radius)/2 for i in itertools.product([-1,1],repeat=dim)]

In [453]:
hierarchy.dendrogram(hierarchy.to_tree(corners));


Out[453]:
{'icoord': [[5.0, 5.0, 15.0, 15.0],
  [25.0, 25.0, 35.0, 35.0],
  [10.0, 10.0, 30.0, 30.0],
  [45.0, 45.0, 55.0, 55.0],
  [65.0, 65.0, 75.0, 75.0],
  [50.0, 50.0, 70.0, 70.0],
  [20.0, 20.0, 60.0, 60.0],
  [85.0, 85.0, 95.0, 95.0],
  [105.0, 105.0, 115.0, 115.0],
  [90.0, 90.0, 110.0, 110.0],
  [125.0, 125.0, 135.0, 135.0],
  [145.0, 145.0, 155.0, 155.0],
  [130.0, 130.0, 150.0, 150.0],
  [100.0, 100.0, 140.0, 140.0],
  [40.0, 40.0, 120.0, 120.0],
  [165.0, 165.0, 175.0, 175.0],
  [185.0, 185.0, 195.0, 195.0],
  [170.0, 170.0, 190.0, 190.0],
  [205.0, 205.0, 215.0, 215.0],
  [225.0, 225.0, 235.0, 235.0],
  [210.0, 210.0, 230.0, 230.0],
  [180.0, 180.0, 220.0, 220.0],
  [245.0, 245.0, 255.0, 255.0],
  [265.0, 265.0, 275.0, 275.0],
  [250.0, 250.0, 270.0, 270.0],
  [285.0, 285.0, 295.0, 295.0],
  [305.0, 305.0, 315.0, 315.0],
  [290.0, 290.0, 310.0, 310.0],
  [260.0, 260.0, 300.0, 300.0],
  [200.0, 200.0, 280.0, 280.0],
  [80.0, 80.0, 240.0, 240.0],
  [325.0, 325.0, 335.0, 335.0],
  [345.0, 345.0, 355.0, 355.0],
  [330.0, 330.0, 350.0, 350.0],
  [365.0, 365.0, 375.0, 375.0],
  [385.0, 385.0, 395.0, 395.0],
  [370.0, 370.0, 390.0, 390.0],
  [340.0, 340.0, 380.0, 380.0],
  [405.0, 405.0, 415.0, 415.0],
  [425.0, 425.0, 435.0, 435.0],
  [410.0, 410.0, 430.0, 430.0],
  [445.0, 445.0, 455.0, 455.0],
  [465.0, 465.0, 475.0, 475.0],
  [450.0, 450.0, 470.0, 470.0],
  [420.0, 420.0, 460.0, 460.0],
  [360.0, 360.0, 440.0, 440.0],
  [485.0, 485.0, 495.0, 495.0],
  [505.0, 505.0, 515.0, 515.0],
  [490.0, 490.0, 510.0, 510.0],
  [525.0, 525.0, 535.0, 535.0],
  [545.0, 545.0, 555.0, 555.0],
  [530.0, 530.0, 550.0, 550.0],
  [500.0, 500.0, 540.0, 540.0],
  [565.0, 565.0, 575.0, 575.0],
  [585.0, 585.0, 595.0, 595.0],
  [570.0, 570.0, 590.0, 590.0],
  [605.0, 605.0, 615.0, 615.0],
  [625.0, 625.0, 635.0, 635.0],
  [610.0, 610.0, 630.0, 630.0],
  [580.0, 580.0, 620.0, 620.0],
  [520.0, 520.0, 600.0, 600.0],
  [400.0, 400.0, 560.0, 560.0],
  [160.0, 160.0, 480.0, 480.0]],
 'dcoord': [[0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [1.4142135623730951,
   1.7320508075688772,
   1.7320508075688772,
   1.4142135623730951],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [1.4142135623730951,
   1.7320508075688772,
   1.7320508075688772,
   1.4142135623730951],
  [1.7320508075688772, 2.0, 2.0, 1.7320508075688772],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [1.4142135623730951,
   1.7320508075688772,
   1.7320508075688772,
   1.4142135623730951],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [1.4142135623730951,
   1.7320508075688772,
   1.7320508075688772,
   1.4142135623730951],
  [1.7320508075688772, 2.0, 2.0, 1.7320508075688772],
  [2.0, 2.2360679774997898, 2.2360679774997898, 2.0],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [1.4142135623730951,
   1.7320508075688772,
   1.7320508075688772,
   1.4142135623730951],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [1.4142135623730951,
   1.7320508075688772,
   1.7320508075688772,
   1.4142135623730951],
  [1.7320508075688772, 2.0, 2.0, 1.7320508075688772],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [1.4142135623730951,
   1.7320508075688772,
   1.7320508075688772,
   1.4142135623730951],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [0.0, 1.0, 1.0, 0.0],
  [0.0, 1.0, 1.0, 0.0],
  [1.0, 1.4142135623730951, 1.4142135623730951, 1.0],
  [1.4142135623730951,
   1.7320508075688772,
   1.7320508075688772,
   1.4142135623730951],
  [1.7320508075688772, 2.0, 2.0, 1.7320508075688772],
  [2.0, 2.2360679774997898, 2.2360679774997898, 2.0],
  [2.2360679774997898,
   2.4494897427831779,
   2.4494897427831779,
   2.2360679774997898]],
 'leaves': [0,
  1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
  10,
  11,
  12,
  13,
  14,
  15,
  16,
  17,
  18,
  19,
  20,
  21,
  22,
  23,
  24,
  25,
  26,
  27,
  28,
  29,
  30,
  31,
  32,
  33,
  34,
  35,
  36,
  37,
  38,
  39,
  40,
  41,
  42,
  43,
  44,
  45,
  46,
  47,
  48,
  49,
  50,
  51,
  52,
  53,
  54,
  55,
  56,
  57,
  58,
  59,
  60,
  61,
  62,
  63],
 'color_list': ['g',
  'g',
  'g',
  'r',
  'r',
  'r',
  'b',
  'c',
  'c',
  'c',
  'm',
  'm',
  'm',
  'b',
  'b',
  'y',
  'y',
  'y',
  'k',
  'k',
  'k',
  'b',
  'g',
  'g',
  'g',
  'r',
  'r',
  'r',
  'b',
  'b',
  'b',
  'c',
  'c',
  'c',
  'm',
  'm',
  'm',
  'b',
  'y',
  'y',
  'y',
  'k',
  'k',
  'k',
  'b',
  'b',
  'g',
  'g',
  'g',
  'r',
  'r',
  'r',
  'b',
  'c',
  'c',
  'c',
  'm',
  'm',
  'm',
  'b',
  'b',
  'b',
  'b'],
 'ivl': ['0',
  '1',
  '2',
  '3',
  '4',
  '5',
  '6',
  '7',
  '8',
  '9',
  '10',
  '11',
  '12',
  '13',
  '14',
  '15',
  '16',
  '17',
  '18',
  '19',
  '20',
  '21',
  '22',
  '23',
  '24',
  '25',
  '26',
  '27',
  '28',
  '29',
  '30',
  '31',
  '32',
  '33',
  '34',
  '35',
  '36',
  '37',
  '38',
  '39',
  '40',
  '41',
  '42',
  '43',
  '44',
  '45',
  '46',
  '47',
  '48',
  '49',
  '50',
  '51',
  '52',
  '53',
  '54',
  '55',
  '56',
  '57',
  '58',
  '59',
  '60',
  '61',
  '62',
  '63']}

In [454]:
Z = hierarchy.complete(corners)

In [456]:
l = hierarchy.to_tree(Z)

In [515]:
from sklearn.datasets import make_swiss_roll

In [514]:
tpe = TPE()

In [516]:
X,Y = make_swiss_roll(1000)

In [517]:
X_ = tpe.fit_transform(X)

In [518]:
plt.scatter(X_[:,0],X_[:,1],c=Y,linewidths=0,alpha=0.5)


Out[518]:
<matplotlib.collections.PathCollection at 0x136c04198>

In [519]:
tpe = TPE('ward')
X_ = tpe.fit_transform(X)
plt.scatter(X_[:,0],X_[:,1],c=Y,linewidths=0,alpha=0.5)


Out[519]:
<matplotlib.collections.PathCollection at 0x13702e8d0>

In [520]:
tsne = TSNE()
X_ = tsne.fit_transform(X)
plt.scatter(X_[:,0],X_[:,1],c=Y,linewidths=0,alpha=0.5)


Out[520]:
<matplotlib.collections.PathCollection at 0x11b51a358>

In [521]:
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X[:,0],X[:,1],X[:,2],c=Y,linewidths=0,alpha=0.5)


Out[521]:
<mpl_toolkits.mplot3d.art3d.Path3DCollection at 0x1381b25f8>

In [ ]: