def test_affinity_with_queryable_knn_index(self): knn_index = nearest_neighbors.Sklearn(self.x, k=30) init = initialization.random(self.x, random_state=0) for aff in [ affinity.PerplexityBasedNN(knn_index=knn_index, perplexity=30), affinity.Uniform(knn_index=knn_index, k_neighbors=30), affinity.FixedSigmaNN(knn_index=knn_index, sigma=1), affinity.Multiscale(knn_index=knn_index, perplexities=[10, 20]), affinity.MultiscaleMixture(knn_index=knn_index, perplexities=[10, 20]), ]: # Without initilization embedding = TSNE().fit(affinities=aff) self.eval_embedding(embedding, self.y, aff.__class__.__name__) new_embedding = embedding.prepare_partial(self.x) new_embedding.optimize(50, learning_rate=1, inplace=True) self.eval_embedding(new_embedding, self.y, f"transform::{aff.__class__.__name__}") # With initilization embedding = TSNE().fit(affinities=aff, initialization=init) self.eval_embedding(embedding, self.y, aff.__class__.__name__) new_embedding = embedding.prepare_partial(self.x) new_embedding.optimize(50, learning_rate=1, inplace=True) self.eval_embedding(new_embedding, self.y, f"transform::{aff.__class__.__name__}")
def test_accepts_knn_index(self): knn_index = nearest_neighbors.Sklearn(self.iris, k=30) for method_name, cls in AFFINITY_CLASSES: aff = cls(knn_index=knn_index) self.assertIs(aff.knn_index, knn_index, msg=method_name) self.assertEqual(aff.n_samples, self.iris.shape[0])
def test_to_new(self): knn_index = nearest_neighbors.Sklearn(self.iris, k=30) for method_name, cls in AFFINITY_CLASSES: aff = cls(knn_index=knn_index) aff.to_new(self.iris)
def test_fails_if_both_data_and_index_specified(self): knn_index = nearest_neighbors.Sklearn(self.iris, k=30) for method_name, cls in AFFINITY_CLASSES: with self.assertRaises(ValueError, msg=method_name): cls(data=self.iris, knn_index=knn_index)