Ejemplo n.º 1
0
def test_knn_isomap():
    """
    Test of the isomap algorithm on knn graphs
    """
    X = randn(10,3)
    M = knn_Isomap(X, rdim=1)
    u = M.train(k=2)
    x = X[:2,:]
    a = M.test(x)
    eps = 1.e12
    test = np.sum(a-u[:2,:])**2<eps
    print np.sum(a-u[:2,:])**2
    assert test
Ejemplo n.º 2
0
def test_knn_isomap():
    """
    Test of the isomap algorithm on knn graphs
    this one fails if the graph as more than one connected component
    to avoid this we use a non-random example
    """
    prng = np.random.RandomState(seed=2)
    X = prng.randn(10,3)
    M = knn_Isomap(X, rdim=1)
    u = M.train(k=2)
    x = X[:2,:]
    a = M.test(x)
    eps = 1.e-12
    test = np.sum(a-u[:2,:])**2<eps
    assert test
Ejemplo n.º 3
0
Bertrand Thirion, 2008-2010
"""
print __doc__

import numpy as np
from nipy.neurospin.eda.dimension_reduction import swiss_roll, isomap, CCA,\
     mds, MDS, knn_Isomap , PCA
import nipy.neurospin.graph.graph as fg
import matplotlib.pylab as mp

# Generate a swiss roll datasets
# y are the 3D coordinates
# x are  he  2D latent coordinates
nbsamp = 1000
y, x = swiss_roll(nbsamp)

M = knn_Isomap(y, rdim=3)
u = M.train(k=7)

# cheack that u and x span the same space,
# i.e. their two canonical coorelations are close to 1
sv = CCA(x-x.mean(0),u[:,:2])
print 'the canonical correlations between true and estimated parameters are %f, %f' %(sv[0],sv[1])

ax = M.G.show(u[:,:2])
ax.set_title('embedding of the data graph')
ax.axis('off')
mp.show()