Skip to content

Commit

Permalink
Fallback for python tapkee examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jan 18, 2013
1 parent 3d866b1 commit d3939f7
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
parameter_list = [[data,10],[data,20]]

def converter_diffusionmaps_modular (data,t):
from shogun.Features import RealFeatures
from shogun.Converter import DiffusionMaps
from shogun.Kernel import GaussianKernel

features = RealFeatures(data)
try:
from shogun.Features import RealFeatures
from shogun.Converter import DiffusionMaps
from shogun.Kernel import GaussianKernel

converter = DiffusionMaps()
converter.set_target_dim(1)
converter.set_kernel(GaussianKernel(10,10.0))
converter.set_t(t)
converter.apply(features)

return features
features = RealFeatures(data)
converter = DiffusionMaps()
converter.set_target_dim(1)
converter.set_kernel(GaussianKernel(10,10.0))
converter.set_t(t)
converter.apply(features)

return features
except ImportError:
print('No Eigen3 available')

if __name__=='__main__':
print('DiffusionMaps')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
parameter_list = [[data,20],[data,30]]

def converter_hessianlocallylinearembedding_modular (data,k):
from shogun.Features import RealFeatures
from shogun.Converter import HessianLocallyLinearEmbedding

features = RealFeatures(data)
try:
from shogun.Features import RealFeatures
from shogun.Converter import HessianLocallyLinearEmbedding

converter = HessianLocallyLinearEmbedding()
converter.set_target_dim(1)
converter.set_k(k)
converter.apply(features)

return features
features = RealFeatures(data)
converter = HessianLocallyLinearEmbedding()
converter.set_target_dim(1)
converter.set_k(k)
converter.apply(features)

return features
except ImportError:
print('No Eigen3 available')

if __name__=='__main__':
print('HessianLocallyLinearEmbedding')
Expand Down
22 changes: 12 additions & 10 deletions examples/undocumented/python_modular/converter_isomap_modular.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
parameter_list = [[data]]

def converter_isomap_modular (data):
from shogun.Features import RealFeatures
from shogun.Converter import Isomap

features = RealFeatures(data)
try:
from shogun.Features import RealFeatures
from shogun.Converter import Isomap

converter = Isomap()
converter.set_k(20)
converter.set_target_dim(1)
converter.apply(features)

return features
features = RealFeatures(data)
converter = Isomap()
converter.set_k(20)
converter.set_target_dim(1)
converter.apply(features)

return features
except ImportError:
print('No Eigen3 available')

if __name__=='__main__':
print('Isomap')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
parameter_list = [[data,20],[data,30]]

def converter_kernellocallylinearembedding_modular (data,k):
from shogun.Features import RealFeatures
from shogun.Converter import KernelLocallyLinearEmbedding
from shogun.Kernel import LinearKernel

features = RealFeatures(data)
try:
from shogun.Features import RealFeatures
from shogun.Converter import KernelLocallyLinearEmbedding
from shogun.Kernel import LinearKernel

kernel = LinearKernel()

converter = KernelLocallyLinearEmbedding(kernel)
converter.set_target_dim(1)
converter.set_k(k)
converter.apply(features)

return features

features = RealFeatures(data)

kernel = LinearKernel()

converter = KernelLocallyLinearEmbedding(kernel)
converter.set_target_dim(1)
converter.set_k(k)
converter.apply(features)

return features
except ImportError:
print('No Eigen3 available')

if __name__=='__main__':
print('KernelLocallyLinearEmbedding')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
parameter_list = [[data,20],[data,30]]

def converter_laplacianeigenmaps_modular (data,k):
from shogun.Features import RealFeatures
from shogun.Converter import LaplacianEigenmaps

features = RealFeatures(data)
try:
from shogun.Features import RealFeatures
from shogun.Converter import LaplacianEigenmaps

converter = LaplacianEigenmaps()
converter.set_target_dim(1)
converter.set_k(k)
converter.set_tau(2.0)
converter.apply(features)

return features
features = RealFeatures(data)
converter = LaplacianEigenmaps()
converter.set_target_dim(1)
converter.set_k(k)
converter.set_tau(2.0)
converter.apply(features)

return features
except ImportError:
print('No Eigen3 available')

if __name__=='__main__':
print('LaplacianEigenmaps')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
parameter_list = [[data,20],[data,30]]

def converter_linearlocaltangentspacealignment_modular (data,k):
from shogun.Features import RealFeatures
from shogun.Converter import LinearLocalTangentSpaceAlignment

features = RealFeatures(data)
try:
from shogun.Features import RealFeatures
from shogun.Converter import LinearLocalTangentSpaceAlignment

converter = LinearLocalTangentSpaceAlignment()
converter.set_target_dim(1)
converter.set_k(k)
converter.apply(features)

return features
features = RealFeatures(data)
converter = LinearLocalTangentSpaceAlignment()
converter.set_target_dim(1)
converter.set_k(k)
converter.apply(features)

return features
except ImportError:
print('No Eigen3 available')

if __name__=='__main__':
print('LinearLocalTangentSpaceAlignment')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
parameter_list = [[data,20],[data,30]]

def converter_localitypreservingprojections_modular (data,k):
from shogun.Features import RealFeatures
from shogun.Converter import LocalityPreservingProjections

features = RealFeatures(data)
converter = LocalityPreservingProjections()
converter.set_target_dim(1)
converter.set_k(k)
converter.set_tau(2.0)
converter.apply(features)

return features
try:
from shogun.Features import RealFeatures
from shogun.Converter import LocalityPreservingProjections

features = RealFeatures(data)
converter = LocalityPreservingProjections()
converter.set_target_dim(1)
converter.set_k(k)
converter.set_tau(2.0)
converter.apply(features)

return features
except ImportError:
print('No Eigen3 available')

if __name__=='__main__':
print('LocalityPreservingProjections')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
parameter_list = [[data,20],[data,30]]

def converter_locallylinearembedding_modular (data,k):
from shogun.Features import RealFeatures
from shogun.Converter import LocallyLinearEmbedding

features = RealFeatures(data)
try:
from shogun.Features import RealFeatures
from shogun.Converter import LocallyLinearEmbedding

converter = LocallyLinearEmbedding()
converter.set_target_dim(1)
converter.set_k(k)
converter.apply(features)

return features
features = RealFeatures(data)
converter = LocallyLinearEmbedding()
converter.set_target_dim(1)
converter.set_k(k)
converter.apply(features)

return features
except ImportError:
print('No Eigen3 available')

if __name__=='__main__':
print('LocallyLinearEmbedding')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
parameter_list = [[data,20],[data,30]]

def converter_localtangentspacealignment_modular (data,k):
from shogun.Features import RealFeatures
from shogun.Converter import LocalTangentSpaceAlignment

features = RealFeatures(data)
try:
from shogun.Features import RealFeatures
from shogun.Converter import LocalTangentSpaceAlignment

converter = LocalTangentSpaceAlignment()
converter.set_target_dim(1)
converter.set_k(k)
converter.apply(features)
features = RealFeatures(data)

converter = LocalTangentSpaceAlignment()
converter.set_target_dim(1)
converter.set_k(k)
converter.apply(features)

return features
return features
except ImportError:
print('No Eigen3 available')


if __name__=='__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@
parameter_list = [[data]]

def converter_multidimensionalscaling_modular (data):
from shogun.Features import RealFeatures
from shogun.Converter import MultidimensionalScaling
from shogun.Distance import EuclideanDistance

features = RealFeatures(data)
try:
from shogun.Features import RealFeatures
from shogun.Converter import MultidimensionalScaling
from shogun.Distance import EuclideanDistance

distance_before = EuclideanDistance()
distance_before.init(features,features)
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)
converter = MultidimensionalScaling()
converter.set_target_dim(2)
converter.set_landmark(False)
embedding =converter.apply(features)

distance_after = EuclideanDistance()
distance_after.init(embedding,embedding)
distance_after = EuclideanDistance()
distance_after.init(embedding,embedding)

distance_matrix_after = distance_after.get_distance_matrix()
distance_matrix_before = distance_before.get_distance_matrix()
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)
return numpy.linalg.norm(distance_matrix_after-distance_matrix_before)/numpy.linalg.norm(distance_matrix_before)
except ImportError:
print('No Eigen3 available')

if __name__=='__main__':
print('MultidimensionalScaling')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@
parameter_list = [[data, 20]]

def converter_stochasticproximityembedding_modular (data, k):
from shogun.Features import RealFeatures
from shogun.Converter import StochasticProximityEmbedding, SPE_GLOBAL, SPE_LOCAL

features = RealFeatures(data)
try:
from shogun.Features import RealFeatures
from shogun.Converter import StochasticProximityEmbedding, SPE_GLOBAL, SPE_LOCAL

converter = StochasticProximityEmbedding()
converter.set_target_dim(1)
converter.set_nupdates(40)
# Embed with local strategy
converter.set_k(k)
converter.set_strategy(SPE_LOCAL)
converter.embed(features)
# Embed with global strategy
converter.set_strategy(SPE_GLOBAL)
converter.embed(features)
features = RealFeatures(data)

converter = StochasticProximityEmbedding()
converter.set_target_dim(1)
converter.set_nupdates(40)
# Embed with local strategy
converter.set_k(k)
converter.set_strategy(SPE_LOCAL)
converter.embed(features)
# Embed with global strategy
converter.set_strategy(SPE_GLOBAL)
converter.embed(features)

return features
return features
except ImportError:
print('No Eigen3 available')

if __name__=='__main__':
print('StochasticProximityEmbedding')
Expand Down

0 comments on commit d3939f7

Please sign in to comment.