All Projects → u1234x1234 → pynanoflann

u1234x1234 / pynanoflann

Licence: BSD-2-Clause license
Unofficial python wrapper to the nanoflann k-d tree

Programming Languages

python
139335 projects - #7 most used programming language
C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to pynanoflann

knn-cpp
A header-only C++ library for k nearest neighbor search with Eigen3.
Stars: ✭ 25 (+4.17%)
Mutual labels:  kd-tree, nearest-neighbor-search
graphgrove
A framework for building (and incrementally growing) graph-based data structures used in hierarchical or DAG-structured clustering and nearest neighbor search
Stars: ✭ 29 (+20.83%)
Mutual labels:  nearest-neighbor-search, nearest-neighbors
kdtree
A k-d tree implementation in Go.
Stars: ✭ 98 (+308.33%)
Mutual labels:  nearest-neighbor-search, kdtree
adventures-with-ann
All the code for a series of Medium articles on Approximate Nearest Neighbors
Stars: ✭ 40 (+66.67%)
Mutual labels:  nearest-neighbor-search, nearest-neighbors
go-kd
Golang k-D tree implementation with duplicate coordinate support
Stars: ✭ 48 (+100%)
Mutual labels:  kdtree
pointu
✏️ Pointillisme tool based on Weighted Voronoi Stippling
Stars: ✭ 32 (+33.33%)
Mutual labels:  kd-tree
Mrpt
Fast and lightweight header-only C++ library (with Python bindings) for approximate nearest neighbor search
Stars: ✭ 210 (+775%)
Mutual labels:  nearest-neighbor-search
Tarsoslsh
A Java library implementing practical nearest neighbour search algorithm for multidimensional vectors that operates in sublinear time. It implements Locality-sensitive Hashing (LSH) and multi index hashing for hamming space.
Stars: ✭ 179 (+645.83%)
Mutual labels:  nearest-neighbor-search
awesome-cpp-python-binding-generator
😎 A curated list of awesome automatic Python binding generators for C++ projects
Stars: ✭ 16 (-33.33%)
Mutual labels:  pybind11
pybind11-stubgen
Generates stubs for python modules (targeted to C++ extensions compiled with pybind11)
Stars: ✭ 103 (+329.17%)
Mutual labels:  pybind11
quick-adc
Quick ADC
Stars: ✭ 20 (-16.67%)
Mutual labels:  nearest-neighbor-search
rrgeo
A fast, offline, reverse geocoder
Stars: ✭ 76 (+216.67%)
Mutual labels:  kd-tree
libkdtree
libkdtree++ is an STL-like C++ template container implementation of k-dimensional space sorting, using a kd-tree. It sports a theoretically unlimited number of dimensions, and can store any data structure. Fork of the project once available from http://libkdtree.alioth.debian.org/
Stars: ✭ 46 (+91.67%)
Mutual labels:  kd-tree
node-kdtree
A node.js add-on for performing efficient Nearest Neighbor searches using libkdtree.
Stars: ✭ 58 (+141.67%)
Mutual labels:  kd-tree
wordvector be
Web服务:使用腾讯 800 万词向量模型和 spotify annoy 引擎得到相似关键词
Stars: ✭ 92 (+283.33%)
Mutual labels:  nearest-neighbor-search
Scanns
A scalable nearest neighbor search library in Apache Spark
Stars: ✭ 190 (+691.67%)
Mutual labels:  nearest-neighbor-search
UE4-Kdtree
UE4 Plugin: k-d tree
Stars: ✭ 48 (+100%)
Mutual labels:  kd-tree
pqtable
Fast search algorithm for product-quantized codes via hash-tables
Stars: ✭ 48 (+100%)
Mutual labels:  nearest-neighbor-search
bitpit
Open source library for scientific HPC
Stars: ✭ 80 (+233.33%)
Mutual labels:  kd-tree
scikit-hubness
A Python package for hubness analysis and high-dimensional data mining
Stars: ✭ 41 (+70.83%)
Mutual labels:  nearest-neighbor-search

Build Status codecov

pynanoflann

Unofficial python wrapper to the nanoflann library [1] with sklearn interface and additional multithreaded capabilities.

nanoflann implementation of k-d tree provides one of the best performance for many k-nearest neighbour problems [2].

It is a good choice for exact k-NN, radius searches in low dimensional spaces.

Install

pip install git+https://github.com/u1234x1234/[email protected]

Basic Usage

import numpy as np
import pynanoflann

index = np.random.uniform(0, 100, (100, 4))
queries = np.random.uniform(0, 100, (10, 4))

nn = pynanoflann.KDTree(n_neighbors=5, metric='L1', radius=100)
nn.fit(index)

# Get k-nearest neighbors
distances, indices = nn.kneighbors(queries)

# Radius search
distances, indices = nn.radius_neighbors(queries)

Save, load

If you need to save the model, there are two options:

  1. Save only the built index. In this case, data points are NOT stored in file. Very efficient, but inconvenient in some cases.
kdtree.fit(X)
kdtree.save_index('index.bin')

prebuilt_kdtree = pynanoflann.KDTree()
# Must use the same data on which the index was built.
prebuilt_kdtree.fit(X, 'index.bin')

Please refer to the detailed example

  1. Pickle the whole model with data points. Less efficient, but convenient.
kdtree.fit(X)
with open('kdtree.pkl', 'wb') as out_file:
    pickle.dump(kdtree, out_file)
with open('kdtree.pkl', 'rb') as in_file:
    unpickled_kdtree = pickle.load(in_file)

Please refer to the detailed example

Multicore parallelization

Implemented on C++ side to reduce python's multiprocessing overhead.

Performance

Generally it much faster than brute force or cython implementation of k-d tree in sklearn

To run benchmark:

python benchmark.py

Links

  1. Blanco, Jose Luis and Rai, Pranjal Kumar, 2014, nanoflann: a C++ header-only fork of FLANN, a library for Nearest Neighbor ({NN}) with KD-trees.
  2. Vermeulen, J.L., Hillebrand, A. and Geraerts, R., 2017. A comparative study of k‐nearest neighbour techniques in crowd simulation.
  3. OpenFLANN Performance comparison between PCL, nanoflann, picoflann
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].