Created
March 8, 2019 16:55
-
-
Save keuv-grvl/0c0689b783dd0591841c7b56c27e9f8b to your computer and use it in GitHub Desktop.
FItSNE wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FItSNE_wrapper: | |
""" | |
Wrapper class for FItSNE `fast_tsne.fast_tsne` v1.1.0. | |
It is currently designed to work in a Conda environment with Python 3.7 and FFTW 3. | |
Install and compile as follow: | |
$ conda create -n YOUR-ENV python=3.7 fftw=3 | |
$ source activate YOUR-ENV | |
$ cd $CONDA_PREFIX/lib/python3.7/ | |
$ git clone https://github.com/KlugerLab/FIt-SNE.git FIt-SNE | |
$ cd FIt-SNE | |
$ git checkout tags/v1.1.0 | |
$ g++ -std=c++11 -O3 -pthread -I${CONDA_PREFIX}/include -o nbodyfft.o -c src/nbodyfft.cpp | |
$ g++ -std=c++11 -O3 -pthread -I${CONDA_PREFIX}/include -o sptree.o -c src/sptree.cpp | |
$ g++ -std=c++11 -O3 -pthread -I${CONDA_PREFIX}/include -o tsne.o -c src/tsne.cpp | |
$ g++ -o bin/fast_tsne nbodyfft.o sptree.o tsne.o -L${CONDA_PREFIX}/lib -Wl,-rpath ${CONDA_PREFIX}/lib -lm -lfftw3 -lpthread | |
$ file bin/fast_tsne # should be an ELF 64-bit LSB executable | |
References: | |
- https://github.com/KlugerLab/FIt-SNE | |
- https://arxiv.org/abs/1712.09005 | |
""" | |
def __init__(self, **kwargs): | |
self.__dict__ = { # default values | |
"theta": 0.5, | |
"perplexity": 30, | |
"map_dims": 2, | |
"max_iter": 1000, | |
"stop_early_exag_iter": 250, | |
"K": -1, | |
"sigma": -1, | |
"nbody_algo": "FFT", | |
"knn_algo": "annoy", | |
"mom_switch_iter": 250, | |
"momentum": 0.5, | |
"final_momentum": 0.8, | |
"learning_rate": 200, | |
"early_exag_coeff": 12, | |
"no_momentum_during_exag": False, | |
"n_trees": 50, | |
"search_k": None, | |
"start_late_exag_iter": -1, | |
"late_exag_coeff": -1, | |
"nterms": 3, | |
"intervals_per_integer": 1, | |
"min_num_intervals": 50, | |
"seed": -1, | |
"initialization": None, | |
"load_affinities": None, | |
"perplexity_list": None, | |
"df": 1, | |
"return_loss": False, | |
"nthreads": None, | |
} | |
self.__dict__ = {**self.__dict__, **kwargs} # user inputs overwrite default params | |
def fit_transform(self, X, fitsne_path=None): | |
""" | |
""" | |
import os, sys | |
if fitsne_path is None: | |
fitsne_path = os.getenv("CONDA_PREFIX") + "/lib/python3.7/FIt-SNE" | |
if fitsne_path not in sys.path: | |
sys.path.append(fitsne_path) | |
from fast_tsne import fast_tsne as _fast_tsne | |
return _fast_tsne(X, **self.__dict__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment