def visualize_spe(features, labels): from modshogun import StochasticProximityEmbedding, SPE_GLOBAL converter = StochasticProximityEmbedding() converter.set_strategy(SPE_GLOBAL) converter.set_k(10) converter.set_target_dim(2) converter.set_nupdates(40) embedding = converter.embed(features) plot_data(embedding.get_feature_matrix(), labels.get_labels()) pyplot.show()
def converter_stochasticproximityembedding_modular (data_fname, k): try: from modshogun import RealFeatures,StochasticProximityEmbedding, SPE_GLOBAL, SPE_LOCAL, CSVFile features = RealFeatures(CSVFile(data_fname)) 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 except ImportError: print('No Eigen3 available')
# Plot helix fig = pylab.figure() fig.add_subplot(2, 2, 1, projection='3d') pylab.plot(X[0, y1], X[1, y1], X[2, y1], 'ro') pylab.plot(X[0, y2], X[1, y2], X[2, y2], 'go') pylab.title('Original 3D Helix') # Create features instance features = RealFeatures(X) # Create Stochastic Proximity Embedding converter instance converter = StochasticProximityEmbedding() # Set target dimensionality converter.set_target_dim(2) # Set strategy converter.set_strategy(SPE_GLOBAL) # Compute SPE embedding embedding = converter.embed(features) X = embedding.get_feature_matrix() fig.add_subplot(2, 2, 2) pylab.plot(X[0, y1], X[1, y1], 'ro') pylab.plot(X[0, y2], X[1, y2], 'go')