示例#1
0
 def run(self, n_samples=1000):
     x, y = self.load_data(n_samples=n_samples)
     print("-" * 80)
     start = time.time()
     SKLTSNE(
         early_exaggeration=12, learning_rate=self.learning_rate, angle=0.5,
         perplexity=self.perplexity, init="random", verbose=True,
     ).fit_transform(x)
     print("scikit-learn t-SNE:", time.time() - start)
示例#2
0
    def run(self, n_samples=1000, random_state=None):
        x, y = self.load_data(n_samples=n_samples)

        print("-" * 80)
        print("Random state", random_state)
        print("-" * 80, flush=True)

        init = openTSNE.initialization.random(
            x, n_components=2, random_state=random_state
        )

        start = time.time()
        SKLTSNE(
            early_exaggeration=12,
            learning_rate=self.learning_rate,
            angle=0.5,
            perplexity=self.perplexity,
            init=init,
            verbose=True,
            random_state=random_state
        ).fit_transform(x)
        print("scikit-learn t-SNE:", time.time() - start, flush=True)
示例#3
0
def run(perplexity=30, learning_rate=100, n_jobs=4):
    x, y = get_mouse_60k()
    # x, y = get_fashion_mnist()

    angle = 0.5
    ee = 12
    metric = 'euclidean'

    print(x.shape)

    start = time.time()
    tsne = TSNE(
        perplexity=perplexity,
        learning_rate=learning_rate,
        early_exaggeration=ee,
        n_jobs=n_jobs,
        theta=angle,
        initialization='random',
        metric=metric,
        n_components=2,
        n_iter=750,
        early_exaggeration_iter=250,
        neighbors='approx',
        negative_gradient_method='fft',
        min_num_intervals=10,
        ints_in_interval=1,
        late_exaggeration_iter=0,
        late_exaggeration=2.,
        callbacks=ErrorLogger(),
    )
    # x = PCA(n_components=50).fit_transform(x)
    embedding = tsne.fit(x)
    print('-' * 80)
    print('tsne', time.time() - start)
    plt.title('tsne')
    plot(embedding, y)
    return

    x = np.ascontiguousarray(x.astype(np.float64))
    from fitsne import FItSNE
    start = time.time()
    embedding = FItSNE(
        x,
        2,
        perplexity=perplexity,
        stop_lying_iter=250,
        ann_not_vptree=True,
        early_exag_coeff=ee,
        nthreads=n_jobs,
        theta=angle,
    )
    print('-' * 80)
    print('fft interp %.4f' % (time.time() - start))
    plt.title('fft interp')
    plot(embedding, y)
    plt.show()
    return

    init = PCA(n_components=2).fit_transform(x)
    start = time.time()
    embedding = MulticoreTSNE(early_exaggeration=ee,
                              learning_rate=learning_rate,
                              perplexity=perplexity,
                              n_jobs=n_jobs,
                              cheat_metric=False,
                              angle=angle,
                              init=init,
                              metric=metric,
                              verbose=True).fit_transform(x)
    print('-' * 80)
    print('mctsne', time.time() - start)
    plt.title('mctsne')
    plot(embedding, y)
    plt.show()

    start = time.time()
    embedding = SKLTSNE(
        early_exaggeration=ee,
        learning_rate=learning_rate,
        angle=angle,
        perplexity=perplexity,
        init='pca',
        metric=metric,
    ).fit_transform(x)
    print('-' * 80)
    print('sklearn', time.time() - start)
    plt.title('sklearn')
    plot(embedding, y)
    plt.show()