Approximate Nearest Neighbor library wrapper for Numpy
Project description
The ANN module provides a numpy-compatible python wrapper around the
Approximate Nearest Neighbor library (http://www.cs.umd.edu/~mount/ANN/).
* Installation *
Download and build the Approximate Nearest Neighbor library. Modify the ANN section of
site.cfg so that ANN_ROOT is the path to the root of the Approximate Nearest Neighbor
library include/lib tree.
If /usr/local/include contains the ANN/ include directory and /usr/local/lib contains
libANN.a, then
ANN_ROOT = /usr/local
Run ::
python setup.py build_ext --inplace build test
sudo python setup.py install
from within the source directory.
* Usage *
scikits.ann exposes a single class, kdtree that wraps the Approximate Nearest Neighbor
library's kd-tree implementation. kdtree has a single (non-constructor) method, knn that
finds the indecies (of the points used to construct the kdtree) of the k-nearest neighbors
and the squared distances to those points. A little example will probably be much
more enlightening::
>>> import scikits.ann as ann
>>> import numpy as np
>>> k=ann.kdtree(np.array([[0.,0],[1,0],[1.5,2]]))
>>> k.knn([0,.2],1)
(array([[0]]), array([[ 0.04]]))
>>> k.knn([0,.2],2)
(array([[0, 1]]), array([[ 0.04, 1.04]]))
>>> k.knn([[0,.2],[.1,2],[3,1],[0,0]],2)
(array([[0, 1],
[2, 0],
[2, 1],
[1, 2]]), array([[ 0.04, 1.04],
[ 1.96, 4.01],
[ 3.25, 5. ],
[ 1. , 6.25]]))
>>> k.knn([[0,.2],[.1,2],[3,1],[0,0]],3)
(array([[ 0, 1, 2],
[ 2, 0, 1],
[ 2, 1, 0],
[ 1, 2, -1]]), array([[ 4.00000000e-002, 1.04000000e+000, 5.49000000e+000],
[ 1.96000000e+000, 4.01000000e+000, 4.81000000e+000],
[ 3.25000000e+000, 5.00000000e+000, 1.00000000e+001],
[ 1.00000000e+000, 6.25000000e+000, 1.79769313e+308]]))
Approximate Nearest Neighbor library (http://www.cs.umd.edu/~mount/ANN/).
* Installation *
Download and build the Approximate Nearest Neighbor library. Modify the ANN section of
site.cfg so that ANN_ROOT is the path to the root of the Approximate Nearest Neighbor
library include/lib tree.
If /usr/local/include contains the ANN/ include directory and /usr/local/lib contains
libANN.a, then
ANN_ROOT = /usr/local
Run ::
python setup.py build_ext --inplace build test
sudo python setup.py install
from within the source directory.
* Usage *
scikits.ann exposes a single class, kdtree that wraps the Approximate Nearest Neighbor
library's kd-tree implementation. kdtree has a single (non-constructor) method, knn that
finds the indecies (of the points used to construct the kdtree) of the k-nearest neighbors
and the squared distances to those points. A little example will probably be much
more enlightening::
>>> import scikits.ann as ann
>>> import numpy as np
>>> k=ann.kdtree(np.array([[0.,0],[1,0],[1.5,2]]))
>>> k.knn([0,.2],1)
(array([[0]]), array([[ 0.04]]))
>>> k.knn([0,.2],2)
(array([[0, 1]]), array([[ 0.04, 1.04]]))
>>> k.knn([[0,.2],[.1,2],[3,1],[0,0]],2)
(array([[0, 1],
[2, 0],
[2, 1],
[1, 2]]), array([[ 0.04, 1.04],
[ 1.96, 4.01],
[ 3.25, 5. ],
[ 1. , 6.25]]))
>>> k.knn([[0,.2],[.1,2],[3,1],[0,0]],3)
(array([[ 0, 1, 2],
[ 2, 0, 1],
[ 2, 1, 0],
[ 1, 2, -1]]), array([[ 4.00000000e-002, 1.04000000e+000, 5.49000000e+000],
[ 1.96000000e+000, 4.01000000e+000, 4.81000000e+000],
[ 3.25000000e+000, 5.00000000e+000, 1.00000000e+001],
[ 1.00000000e+000, 6.25000000e+000, 1.79769313e+308]]))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
scikits.ann-0.2.dev-r803.tar.gz
(20.4 kB
view details)
Built Distribution
File details
Details for the file scikits.ann-0.2.dev-r803.tar.gz
.
File metadata
- Download URL: scikits.ann-0.2.dev-r803.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9330333e7b6cf0653d9396437ee7f8f676eda863568e168623071a19c76d8aaf |
|
MD5 | a0380cdc31fd705c15eb50f483bbe5fb |
|
BLAKE2b-256 | fd7ed23d4c862ca8a9fe3ba770b57b6d91e192608ddcc6760e0428f288e48023 |
File details
Details for the file scikits.ann-0.2.dev_r803-py2.5-macosx-10.5-i386.egg
.
File metadata
- Download URL: scikits.ann-0.2.dev_r803-py2.5-macosx-10.5-i386.egg
- Upload date:
- Size: 84.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ccdd7d02b1b201c98ca2aa01cb04b82fa39be7f462b96d2959e564d26abd177 |
|
MD5 | ac2b350f03584d2c0c6f6130cd72bda3 |
|
BLAKE2b-256 | 644aaa8fc0fc50776768b74559eddfe93f24790a69c42a7a7a56529b32899483 |