Exemplo n.º 1
0
    def test_affinity(self):
        init = initialization.random(self.x, random_state=0)

        for aff in [
                affinity.PerplexityBasedNN(self.x, perplexity=30),
                affinity.Uniform(self.x, k_neighbors=30),
                affinity.FixedSigmaNN(self.x, sigma=1, k=30),
                affinity.Multiscale(self.x, perplexities=[10, 30]),
                affinity.MultiscaleMixture(self.x, perplexities=[10, 30]),
        ]:
            # 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(10, learning_rate=0.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(10, learning_rate=0.1, inplace=True)
            self.eval_embedding(new_embedding, self.y,
                                f"transform::{aff.__class__.__name__}")
Exemplo n.º 2
0
    def test_affinity_with_precomputed_neighbors(self):
        nn = NearestNeighbors(n_neighbors=30)
        nn.fit(self.x)
        distances, neighbors = nn.kneighbors(n_neighbors=30)

        knn_index = nearest_neighbors.PrecomputedNeighbors(
            neighbors, distances)
        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__)

            # With initilization
            embedding = TSNE().fit(affinities=aff, initialization=init)
            self.eval_embedding(embedding, self.y, aff.__class__.__name__)
Exemplo n.º 3
0
 def test_2(self):
     init = initialization.pca(self.x)
     aff = affinity.MultiscaleMixture(self.x, perplexities=[5, 30])
     embedding = openTSNE.TSNEEmbedding(init, aff)
     embedding.optimize(25, exaggeration=12, momentum=0.5, inplace=True)
     embedding.optimize(50, exaggeration=1, momentum=0.8, inplace=True)
     self.eval_embedding(embedding, self.y)
     new_embedding = embedding.transform(self.x)
     self.eval_embedding(new_embedding, self.y, "transform")
Exemplo n.º 4
0
    def test_affinity_with_precomputed_distances(self):
        d = squareform(pdist(self.x))
        knn_index = nearest_neighbors.PrecomputedDistanceMatrix(d, 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, aff.__class__.__name__)

            # With initilization
            embedding = TSNE().fit(affinities=aff, initialization=init)
            self.eval_embedding(embedding, aff.__class__.__name__)