https://github.com/shamazmazum/vp-trees
Vantage point trees for Common Lisp
https://github.com/shamazmazum/vp-trees
common-lisp lisp vp-tree
Last synced: about 2 months ago
JSON representation
Vantage point trees for Common Lisp
- Host: GitHub
- URL: https://github.com/shamazmazum/vp-trees
- Owner: shamazmazum
- License: bsd-2-clause
- Created: 2020-03-23T19:22:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-27T07:50:20.000Z (over 2 years ago)
- Last Synced: 2025-02-09T10:11:18.608Z (3 months ago)
- Topics: common-lisp, lisp, vp-tree
- Language: Common Lisp
- Size: 20.5 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
vp-trees
========
[](https://cirrus-ci.com/github/shamazmazum/vp-trees)
**vp-trees** is an implementation of vantage point tree data structure
in Common Lisp. It allows to perform fast (O(log N) in the best case)
fixed-radius near neighbors searches in some set of a metric space.Look at the following example. Let's choose the space ℝ²[0, 1] and
generate some points belonging to this space:``` lisp
(defun gen-point ()
(vector (random 1.0)
(random 1.0)))(defun gen-points (n)
(loop repeat n collect (gen-point)))
```Then introduce a metric on this space (usual Euclidean metric):
``` lisp
(defun dist (a b)
(sqrt
(reduce #'+
(map 'vector (lambda (x y) (expt (- x y) 2))
a b))))
```Build a tree consisting of 1000000 items in ℝ²[0, 1]:
``` lisp
(defparameter *tree*
(vp-trees:make-vp-tree (gen-points 1000000) #'dist))
```Now return points which are closer than `0.1` to the origin:
``` lisp
(vp-trees:items-in-ball *tree* #(0.0 0.0) 0.1 #'dist)
```The advantage of VP trees is that you don't have to stick to Euclidean
metric: you may choose whatever metric you want as long as four
metric axioms hold. For example, VP trees can be used for
multidimensional spaces.## API list
~~~~
make-vp-tree
flatten
items-in-ball
nearest-neighbor
~~~~