• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    C++
  • Created over 8 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python module for Barnes-Hut implementation of t-SNE (Cython)

travis-ci

Python BHTSNE

Python module for Barnes-Hut implementation of t-SNE (Cython).

This module is based on the excellent work of Laurens van der Maaten.

Features

  • Better results than the Scikit-Learn BH t-SNE implementation: bhtsne VS Scikit-Learn
  • Fast (C++/Cython)
  • Ability to set random seed
  • Ability to set pre-defined plot coordinates (allow for smooth transitions between plots)

Installation

From pip:

pip install bhtsne

Examples

Iris Data Set

Reduce the four dimensional iris data set to two dimensions:

from bhtsne import tsne
from sklearn.datasets import load_iris
iris = load_iris()
Y = tsne(iris.data)
plt.scatter(Y[:, 0], Y[:, 1], c=iris.target)
plt.show()

This should result in:

Iris Plot

Transition between two t-SNE results

When adding new data the t-SNE plot can change dramatically (even when setting a random seed). This makes it hard to animate between different plots when data is in motion.

This problem can be partially solved by setting the start coordinates of the first N vectors. In this example we'll create two t-SNE plots, the first one will have part of the iris data set. The second will include the remaining 10 of the iris set:

from bhtsne import tsne
from sklearn.datasets import load_iris
iris = load_iris()
X_a = load_iris().data[:-10]
X_b = load_iris().data
# Generate random positions for last 10 items
remainder_positions = np.array([
    [(random.uniform(0, 1) * 0.0001), (random.uniform(0, 1) * 0.0001)]
        for x in range(X_b.shape[0] - Y_a.shape[0])
    ])
# Append them to previous TSNE output and use as seed_positions in next plot
seed_positions = np.vstack((Y_a, remainder_positions))
Y_b = tsne(X_b, seed_positions=seed_positions)
plt.scatter(Y_a[:, 0], Y_a[:, 1], c='b')
plt.scatter(Y_b[:-10, 0], Y_b[:-10, 1], c='r')
plt.scatter(Y_b[-10:, 0], Y_b[-10:, 1], c='g')
plt.show()

The resulting plot shows our first iteration in blue. Then the second iteration is shown in red and the new nodes that were added are green:

Iris Plot

Development

Build:

pip install cython
make

To run unit tests:

make test

Also creates visual plots in the test/plots folder.

Todo

  • Allow more sophisticated control of updates to the t-SNE (streaming/online t-SNE)
  • Allow more control on the number of iterations and error rate thresholds

More Repositories

1

word2vec-explorer

Tool for exploring Word Vector models
JavaScript
176
star
2

node-facebook

Simple Facebook Integration for NodeJS (and Express)
JavaScript
124
star
3

deep-base

Deep learning base image for Docker (Tensorflow, Caffe, MXNet, Torch, Openface, etc.)
Makefile
79
star
4

kakuteru

Semantic-web enabled Lifestreamer built on RubyOnRails
Ruby
63
star
5

eth-indexer

High performance Ethereum smart contract event indexing for fast local retrieval
JavaScript
58
star
6

transferflow

Transfer Learning for Tensorflow
Python
34
star
7

app-skeleton

Simple JS App Skeleton (React, SemanticUI, Babel, Standard, ES6, Webpack, React-router)
JavaScript
32
star
8

node-api-skeleton

Node.js API Skeleton using frameworks du jour: ES6/Await, Express, Jest, Mongoose, Docker, JWT, etc.
JavaScript
28
star
9

ruby-v8

Run the V8 Javascript Engine from Ruby.
C++
22
star
10

xml-to-json-proxy

Tools that allow client-side XML calls in the browser. Using Flash crossdomain calls, the XML is converted to JSONML and delivered in JavaScript
13
star
11

iknow_developers

Example code on how to use the iKnow! API
PHP
11
star
12

shoal

A modern upstart replacement. Manage processes using centralized JSON configurations
JavaScript
10
star
13

relex-json-serve

Small server that allows you to access the Relex NLP toolkit using JSON RPC calls.
Ruby
7
star
14

moonfish-app

Open source platform for doing Token Sales and Initial Coin Offerings (ICOs)
JavaScript
6
star
15

crypto-toad

Crypto market intelligence via Telegram
Python
5
star
16

Pulsi

Virtual stock market simulator for pre-IPO companies.
JavaScript
4
star
17

content_focus

This is a little gem that allows you to input raw HTML and extract the most relevant piece of content.
Ruby
4
star
18

nnpack

Packaging and Data Portability for Neural Networks
Python
3
star
19

activity_mapper

A framework for aggregating (public) social activity into a single polymorphic persistent structure.
Ruby
3
star
20

python-api-skeleton

Simple Python-based JSON API skeleton for SPA SaaS apps.
Python
2
star
21

phpfbex

Simple JS/PHP Facebook integration Example
PHP
2
star
22

dominiek.github.com

Storing of static stuff
JavaScript
2
star
23

wqet-grader

Python
2
star
24

etherist

Real-time Ethereum currency data brokerage + Telegram Bot
Python
1
star
25

moonfish-api

Open source platform for doing Token Sales and Initial Coin Offerings (ICOs)
JavaScript
1
star