6
|
1 |
pyANN
|
|
2 |
=====
|
|
3 |
|
|
4 |
pyANN provides Python bindings for David Mount and Sunil Arya's ANN_ library for
|
|
5 |
approximate nearest neighbor searching.
|
|
6 |
|
|
7 |
.. _ANN: http://www.cs.umd.edu/~mount/ANN/
|
|
8 |
|
|
9 |
|
|
10 |
Example
|
|
11 |
-------
|
|
12 |
|
|
13 |
.. parsed-literal::
|
|
14 |
|
|
15 |
>>> import pyANN
|
|
16 |
>>> kdtree = pyANN.KDTree([[1,1,1], [1,2,3], [4,5,6]])
|
|
17 |
>>> kdtree.kSearch([0,0,0], 2, 0)
|
|
18 |
([0, 1], [3.0, 14.0])
|
|
19 |
|
|
20 |
|
|
21 |
Download
|
|
22 |
--------
|
|
23 |
|
|
24 |
The easiest way to obtain pyANN is to check it out from my Mercurial_
|
|
25 |
repository:
|
|
26 |
|
|
27 |
.. parsed-literal::
|
|
28 |
|
|
29 |
hg clone http://hg.mrzv.org/pyANN
|
|
30 |
|
|
31 |
Alternatively, one can download the tarball_.
|
|
32 |
|
|
33 |
.. _Mercurial: http://www.selenic.com/mercurial/wiki/
|
|
34 |
.. _tarball: http://hg.mrzv.org/pyANN/archive/tip.tar.gz
|
|
35 |
|
|
36 |
|
|
37 |
Building and Installing
|
|
38 |
-----------------------
|
|
39 |
|
|
40 |
First of all, one needs to patch ANN_ to make it compile with more recent
|
|
41 |
versions of GCC_ and to make it build shared libraries under Linux. If you are
|
|
42 |
not under Linux and have an older version of GCC_ (below 4.3), you can safely
|
|
43 |
skip these steps.
|
|
44 |
|
|
45 |
.. _GCC: http://gcc.gnu.org/
|
|
46 |
|
|
47 |
Download the gcc43.patch_ and shared-libs.patch_. Within the directory where
|
|
48 |
you've extracted ANN_, run::
|
|
49 |
|
|
50 |
patch -p1 < .../gcc43.patch
|
|
51 |
patch -p1 < .../shared-libs.patch
|
|
52 |
make linux-g++-sl
|
|
53 |
|
|
54 |
(assuming you are on Linux).
|
|
55 |
|
|
56 |
.. _gcc43.patch: http://aur.archlinux.org/packages/ann/ann/gcc43.patch
|
|
57 |
.. _shared-libs.patch: http://aur.archlinux.org/packages/ann/ann/shared-libs.patch
|
|
58 |
|
|
59 |
Besides ANN_, pyANN **depends** on Boost.Python_. To compile and install the
|
|
60 |
bindings, if you have waf_ installed, run::
|
|
61 |
|
|
62 |
waf configure
|
|
63 |
waf build
|
|
64 |
waf install
|
|
65 |
|
|
66 |
Otherwise, there is the original simple ``Makefile``, which you can tweak (e.g.,
|
|
67 |
adjust paths), and then ``make`` will compile the bindings. You will have to
|
|
68 |
manually put them somewhere on your ``PYTHONPATH``.
|
|
69 |
|
|
70 |
.. _Boost.Python: http://www.boost.org/doc/libs/1_39_0/libs/python/doc/index.html
|
|
71 |
.. _waf: http://code.google.com/p/waf/
|
|
72 |
|
|
73 |
|
|
74 |
KDTree class
|
|
75 |
------------
|
|
76 |
|
|
77 |
The main content of pyANN is the class `KDTree`. The class is initialized with a
|
|
78 |
list of points, and provides three key methods:
|
|
79 |
|
|
80 |
:kSearch:
|
|
81 |
:kPriSearch:
|
|
82 |
:kFRSearch:
|
|
83 |
|
|
84 |
Additional auxiliary methods mimick ANN's functionality:
|
|
85 |
|
|
86 |
|