Learn R Programming

⚠️There's a newer version (1.0.7) of this package.Take me there.

nmslibR (Non Metric Space Library in R)

The nmslibR package is a wrapper of the Non-Metric Space Library (NMSLIB) python package. More details on the functionality of the nmslibR package can be found in the package Documentation and Vignette.

Reference:

https://github.com/searchivarius/nmslib

https://github.com/searchivarius/nmslib/blob/master/manual/manual.pdf

System Requirements

  • Python (>= 2.7)

All modules should be installed in the default python configuration (the configuration that the R-session displays as default), otherwise errors will occur during the nmslibR package installation (reticulate::py_discover_config() might be useful here).

The installation notes for Linux, Macintosh, Windows are based on Python 2.7.

Debian/Ubuntu

Installation of the system requirements,


sudo pip install --upgrade pip setuptools

sudo pip install -U numpy

sudo pip install --upgrade scipy

sudo apt-get install libboost-all-dev libgsl0-dev libeigen3-dev

sudo apt-get install cmake

sudo pip install nmslib

Fedora

Installation of the system requirements,


sudo pip install --upgrade pip setuptools

sudo pip install -U numpy

sudo pip install --upgrade scipy

yum install python2-devel

yum install boost-devel

yum install gsl-devel

yum install eigen3-devel

Macintosh OSX

First do a fresh install of python using brew [ normally the brew-python will appear as python2, because python comes by default in Macintosh OS ]

brew install python

brew link --overwrite python

Then update the .bash_profile file in home directory with the following paths

export PATH=/usr/local/bin:/usr/bin:$PATH

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Installation of the system requirements,


sudo pip2 install --upgrade pip setuptools

sudo pip2 install -U numpy

sudo pip2 install --upgrade scipy

brew install boost

brew install eigen

brew install gsl

brew install cmake

brew link --overwrite cmake

sudo pip2 install nmslib

After a successful installation of the system requirements the user should open an R session and give the following reticulate command to change to the relevant (brew-python) directory (otherwise the nmslibR package won't work properly),


reticulate::use_python('/usr/local/bin/python2')

and then,


reticulate::py_discover_config()

to validate that a user is in the python version where nmslibR is installed.

Windows OS

First download of get-pip.py for windows

Update the Environment variables ( Control Panel >> System and Security >> System >> Advanced system settings >> Environment variables >> System variables >> Path >> Edit ) by adding ( for instance in case of python 2.7 ),


C:\Python27;C:\Python27\Scripts

Install the Visual C++ 2015 Build Tools

Open the Command prompt (console) and install / upgrade the system requirements,


pip install --upgrade pip setuptools

pip install -U numpy

pip install --upgrade scipy

Installation of cmake

First download cmake for Windows, win64-x64 Installer. Once the file is downloaded run the .exe file and during installation make sure to add CMake to the system PATH for all users.

Then install the nmslib library,


pip install nmslib

Installation of the nmslibR package

To install the package from CRAN use,


install.packages('nmslibR')

and to download the latest version from Github use the install_github function of the devtools package,


devtools::install_github(repo = 'mlampros/nmslibR')

https://github.com/mlampros/nmslibR/issues

Copy Link

Version

Install

install.packages('nmslibR')

Monthly Downloads

192

Version

1.0.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Lampros Mouselimis

Last Published

April 14th, 2018

Functions in nmslibR (1.0.1)

KernelKnnCV_nmslib

Approximate Kernel k nearest neighbors (cross-validated) using the nmslib library
func_tbl

this function returns a table of probabilities for each label
regr_folds

create folds (in regression) [ detailed information about class_folds in the FeatureSelection package ]
switch.ops

Arithmetic operations on lists
dgCMatrix_2scipy_sparse

conversion of an R dgCMatrix to a scipy sparse matrix
func_categorical_preds

OPTION to convert categorical features TO either numeric [ if levels more than 32] OR to dummy variables [ if levels less than 32 ]
func_tbl_dist

this function returns the probabilities in case of classification
inner_kernel_function

inner function to compute kernels, extract weights and return predictions
FUNCTION_weights

this function is used as a kernel-function-identifier [ takes the distances and a weights-kernel (in form of a function) and returns weights ]
FUN_kernels

performs kernel smoothing using a bandwidth. Besides using a kernel there is also the option to combine kernels
NMSlib

Non metric space library
class_folds

stratified folds (in classification) [ detailed information about class_folds in the FeatureSelection package ]
KernelKnn_nmslib

Approximate Kernel k nearest neighbors using the nmslib library
mat_2scipy_sparse

conversion of an R matrix to a scipy sparse matrix
normalized

this function normalizes the data
func_shuffle

shuffle data