Пример #1
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__)
Пример #2
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__}")
Пример #3
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__)