示例#1
0
def test_ltsa_eigendecomps():
    from sklearn import manifold
    from sklearn import datasets
    N = 10
    X, color = datasets.samples_generator.make_s_curve(N, random_state=0)
    n_components = 2
    Geometry = geom.Geometry(X, neighborhood_radius = 2, distance_method = 'brute')
    (mm_ltsa_ar, err) = ltsa.ltsa(Geometry, n_components, eigen_solver = 'arpack')
    (mm_ltsa_de, err2) = ltsa.ltsa(Geometry, n_components, eigen_solver = 'dense')
    (mm_ltsa_amg, err3) = ltsa.ltsa(Geometry, n_components, eigen_solver = 'amg')
    assert(_check_with_col_sign_flipping(mm_ltsa_ar, mm_ltsa_de, 0.05))
    assert(_check_with_col_sign_flipping(mm_ltsa_ar, mm_ltsa_amg, 0.05))
    assert(_check_with_col_sign_flipping(mm_ltsa_amg, mm_ltsa_de, 0.05))
示例#2
0
def test_ltsa_with_sklearn():
    from sklearn import manifold
    from sklearn import datasets
    from sklearn.neighbors import NearestNeighbors
    N = 10
    X, color = datasets.samples_generator.make_s_curve(N, random_state=0)
    n_components = 2
    n_neighbors = 3
    knn = NearestNeighbors(n_neighbors + 1).fit(X)
    Geometry = geom.Geometry(X)
    Geometry.assign_distance_matrix(knn.kneighbors_graph(X, mode = 'distance'))
    sk_Y_ltsa = manifold.LocallyLinearEmbedding(n_neighbors, n_components, 
                                                method = 'ltsa',
                                                eigen_solver = 'arpack').fit_transform(X)
    (mm_Y_ltsa, err) = ltsa.ltsa(Geometry, n_components, eigen_solver = 'arpack')
    assert(_check_with_col_sign_flipping(sk_Y_ltsa, mm_Y_ltsa, 0.05))
示例#3
0
n_components = 2
n_neighbors = 3

knn = NearestNeighbors(n_neighbors + 1).fit(X)

# Assign the geometry matrix to get the same answer since sklearn using k-neighbors instead of radius-neighbors
Geometry = geom.Geometry(X)
Geometry.assign_distance_matrix(knn.kneighbors_graph(X, mode = 'distance'))

from sklearn import manifold

# test LTSA with sklearn
sk_Y_ltsa = manifold.LocallyLinearEmbedding(n_neighbors, n_components, 
                                            method = 'ltsa', eigen_solver = 'arpack').fit_transform(X)
import Mmani.embedding.ltsa as ltsa
(mm_Y_ltsa, err) = ltsa.ltsa(Geometry, n_components, eigen_solver = 'arpack')
assert(_check_with_col_sign_flipping(sk_Y_ltsa, mm_Y_ltsa, 0.05))

# test LLE with sklearn
sk_Y_lle = manifold.LocallyLinearEmbedding(n_neighbors, n_components, method = 'standard').fit_transform(X)
import Mmani.embedding.locally_linear_ as lle
(mm_Y_lle, err) = lle.locally_linear_embedding(Geometry, n_components)
assert(_check_with_col_sign_flipping(sk_Y_ltsa, mm_Y_ltsa, 0.05))

# test Isomap with sklearn
sk_Y_iso = manifold.Isomap(n_neighbors, n_components, eigen_solver = 'arpack').fit_transform(X)
import Mmani.embedding.isomap_ as iso
mm_Y_iso = iso.isomap(Geometry, n_components)
assert(_check_with_col_sign_flipping(sk_Y_iso, mm_Y_iso, 0.05))

from scipy.spatial.distance import pdist, squareform