def converter_multidimensionalscaling_modular(data): try: from shogun.Features import RealFeatures from shogun.Converter import MultidimensionalScaling from shogun.Distance import EuclideanDistance features = RealFeatures(data) distance_before = EuclideanDistance() distance_before.init(features, features) converter = MultidimensionalScaling() converter.set_target_dim(2) converter.set_landmark(False) embedding = converter.apply(features) distance_after = EuclideanDistance() distance_after.init(embedding, embedding) distance_matrix_after = distance_after.get_distance_matrix() distance_matrix_before = distance_before.get_distance_matrix() return numpy.linalg.norm(distance_matrix_after - distance_matrix_before ) / numpy.linalg.norm(distance_matrix_before) except ImportError: print('No Eigen3 available')
def converter_multidimensionalscaling_modular (data): try: from shogun.Features import RealFeatures from shogun.Converter import MultidimensionalScaling from shogun.Distance import EuclideanDistance features = RealFeatures(data) distance_before = EuclideanDistance() distance_before.init(features,features) converter = MultidimensionalScaling() converter.set_target_dim(2) converter.set_landmark(False) embedding = converter.apply(features) distance_after = EuclideanDistance() distance_after.init(embedding,embedding) distance_matrix_after = distance_after.get_distance_matrix() distance_matrix_before = distance_before.get_distance_matrix() return numpy.linalg.norm(distance_matrix_after-distance_matrix_before)/numpy.linalg.norm(distance_matrix_before) < 1e-6 except ImportError: print('No Eigen3 available')
import numpy numpy.random.seed(40) tt = numpy.genfromtxt('../../data/toy/swissroll_color.dat', unpack=True).T X = numpy.genfromtxt('../../data/toy/swissroll.dat', unpack=True).T N = X.shape[1] converters = [] from shogun.Converter import LocallyLinearEmbedding lle = LocallyLinearEmbedding() lle.set_k(9) converters.append((lle, "LLE with k=%d" % lle.get_k())) from shogun.Converter import MultidimensionalScaling mds = MultidimensionalScaling() converters.append((mds, "Classic MDS")) lmds = MultidimensionalScaling() lmds.set_landmark(True) lmds.set_landmark_number(20) converters.append( (lmds, "Landmark MDS with %d landmarks" % lmds.get_landmark_number())) from shogun.Converter import Isomap cisomap = Isomap() cisomap.set_k(9) converters.append((cisomap, "Isomap with k=%d" % cisomap.get_k())) from shogun.Converter import DiffusionMaps from shogun.Kernel import GaussianKernel dm = DiffusionMaps() dm.set_t(2)
numpy.random.seed(40) tt = numpy.genfromtxt('../../../../data/toy/swissroll_color.dat',unpack=True).T X = numpy.genfromtxt('../../../../data/toy/swissroll.dat',unpack=True).T N = X.shape[1] converters = [] from shogun.Converter import LocallyLinearEmbedding lle = LocallyLinearEmbedding() lle.set_k(9) converters.append((lle, "LLE with k=%d" % lle.get_k())) from shogun.Converter import MultidimensionalScaling mds = MultidimensionalScaling() converters.append((mds, "Classic MDS")) lmds = MultidimensionalScaling() lmds.set_landmark(True) lmds.set_landmark_number(20) converters.append((lmds,"Landmark MDS with %d landmarks" % lmds.get_landmark_number())) from shogun.Converter import Isomap cisomap = Isomap() cisomap.set_k(9) converters.append((cisomap,"Isomap with k=%d" % cisomap.get_k())) from shogun.Converter import DiffusionMaps from shogun.Kernel import GaussianKernel dm = DiffusionMaps() dm.set_t(20) kernel = GaussianKernel(100,1.0) dm.set_kernel(kernel)