1
1
# NearestNeighborDescent.jl
2
2
3
- [ ![ Build Status] ( https://travis-ci.com/dillondaudert/NearestNeighborDescent.jl.svg?branch=master )] ( https://travis-ci.com/dillondaudert/NearestNeighborDescent.jl ) [ ![ Build status] ( https://ci.appveyor.com/api/projects/status/lr49p9vxkr8a3uv0?svg=true )] ( https://ci.appveyor.com/project/dillondaudert/nearestneighbordescent-jl )
4
- [ ![ codecov] ( https://codecov.io/gh/dillondaudert/NearestNeighborDescent.jl/branch/master/graph/badge.svg )] ( https://codecov.io/gh/dillondaudert/NearestNeighborDescent.jl ) [ ![ Coverage Status] ( https://coveralls.io/repos/github/dillondaudert/NearestNeighborDescent.jl/badge.svg?branch=master )] ( https://coveralls.io/github/dillondaudert/NearestNeighborDescent.jl?branch=master )
3
+ | ** Documentation** | ** Build Status** |
4
+ | :-----------------:| :----------------:|
5
+ | [ ![ ] [ docs-stable-img ]] [ docs-stable-url ] [ ![ ] [ docs-dev-img ]] [ docs-dev-url ] | [ ![ ] [ travis-img ]] [ travis-url ] [ ![ ] [ appveyor-img ]] [ appveyor-url ] [ ![ ] [ codecov-img ]] [ codecov-url ] [ ![ ] [ coveralls-img ]] [ coveralls-url ] |
5
6
6
7
A Julia implementation of Nearest Neighbor Descent.
7
8
@@ -20,67 +21,54 @@ NNDescent is based on the heuristic argument that *a neighbor of a neighbor is a
20
21
given a list of approximate nearest neighbors to a point, we can improve that list by exploring the neighbors of each
21
22
point in the list. The algorithm is in essence the repeated application of this principle.
22
23
23
-
24
- ## Usage
25
- The ` DescentGraph ` constructor builds the approximate kNN graph:
26
- ``` jl
27
- DescentGraph (data, n_neighbors, metric; max_iters, sample_rate, precision)
24
+ ## Installation
25
+ ``` julia
26
+ ]add NearestNeighborDescent
28
27
```
29
- - ` data ` : The set of points to build the tree from. This must be of type
30
- ` Vector{V} ` , where ` V <: AbstractVector ` ** or** ` AbstractMatrix ` .
31
- - ` n_neighbors ` : An integer specifies the number of neighbors to find
32
- - ` metric ` : Any metric ` M ` where ` M <: SemiMetric ` from the Distances.jl package. Default is ` Euclidean() ` .
33
-
34
- The performance of NN Descent can be tuned with several keyword arguments.
35
- - ` max_iters ` : This controls the maximum number of iterations to search for
36
- neighbors. Default is ` 10 ` .
37
- - ` sample_rate ` : The algorithm performs a local join around the candidate
38
- neighbors of each point during execution. The sample rate is the likelihood
39
- that each candidate be included in the local join for an iteration. Default is
40
- ` 1. ` .
41
- - ` precision ` : This argument roughly corresponds to the fraction of true
42
- nearest neighbors that will be missed by the algorithm. Default ` .001 ` .
43
-
44
- The k-nearest neighbors can be accessed through the ` indices ` and ` distances `
45
- attributes. These are both ` KxN ` matrices containing ids and distances to each
46
- point's neighbors, respectively, where ` K = n_neighbors ` and ` N = length(data) ` .
47
-
48
- Example:
49
- ``` jl
50
- using NearestNeighborDescent
51
- data = [rand (10 ) for _ in 1 : 1000 ]
52
- # OR data = rand(10, 1000)
53
- n_neighbors = 5
54
28
55
- # nn descent search
56
- graph = DescentGraph (data, n_neighbors)
29
+ ## Basic Usage
30
+
31
+ Approximate kNN graph construction on a dataset:
57
32
58
- # access point i's jth nearest neighbor:
59
- graph. indices[j, i]
60
- graph. distances[j, i]
33
+ ``` julia
34
+ using NearestNeighborDescent
35
+ using Distances
36
+ data = [rand (20 ) for _ in 1 : 1000 ]
37
+ n_neighbors = 10
38
+ metric = Euclidean ()
39
+ graph = nndescent (data, n_neighbors, metric)
61
40
```
62
41
63
- Once constructed, the ` DescentGraph ` can be used to find the nearest
64
- neighbors to new points. This is done via the ` search ` method:
65
- ``` jl
66
- search (graph, queries, n_neighbors, queue_size) -> indices, distances
42
+ The approximate KNNs of the original dataset can be retrieved from the resulting graph with
43
+ ``` julia
44
+ # return the approximate knns as KxN matrices of indexes and distances, where
45
+ # indices[j, i] and distances[j, i] are the index of and distance to node i's jth
46
+ # nearest neighbor, respectively.
47
+ indices, distances = knn_matrices (graph)
67
48
```
68
- - ` graph ` : An instance of ` DescentGraph `
69
- - ` queries ` : A vector of new data points of type ` Vector{V} ` or ` AbstractMatrix ` .
70
- Note that the dimensionality of the queries should match that of the data used to
71
- originally construct the graph.
72
- - ` n_neighbors ` : The number of neighbors to find for each query. This does
73
- * not* have to be the same as the number used to construct ` graph ` .
74
- - ` queue_size ` : Each query maintains a heap of candidate neighbors.
75
- ` queue_size ` controls the maximum number of candidates as a multiple of
76
- ` n_neighbors ` . Default is ` 1. ` .
77
-
78
- Similar to ` DescentGraph ` , this returns two matrices for the indices and
79
- distances to the nearest neighbors of each query.
80
-
81
- Example:
82
- ``` jl
83
- queries = [rand (10 ) for _ in 1 : 100 ]
84
- # OR queries = rand(10, 100)
85
- idxs, dists = search (knngraph, queries, 4 )
49
+
50
+ To find the approximate neighbors for new points with respect to an already constructed graph:
51
+
52
+ ``` julia
53
+ queries = [rand (20 ) for _ in 1 : 20 ]
54
+ n_neighbors = 5
55
+ indices, distances = search (graph, queries, n_neighbors)
86
56
```
57
+
58
+ [ docs-stable-img ] : https://img.shields.io/badge/docs-stable-blue.svg
59
+ [ docs-stable-url ] : https://dillondaudert.github.io/NearestNeighborDescent.jl/stable
60
+
61
+ [ docs-dev-img ] : https://img.shields.io/badge/docs-dev-blue.svg
62
+ [ docs-dev-url ] : https://dillondaudert.github.io/NearestNeighborDescent.jl/dev
63
+
64
+ [ travis-img ] : https://travis-ci.com/dillondaudert/NearestNeighborDescent.jl.svg?branch=master
65
+ [ travis-url ] : https://travis-ci.com/dillondaudert/NearestNeighborDescent.jl
66
+
67
+ [ appveyor-img ] : https://ci.appveyor.com/api/projects/status/lr49p9vxkr8a3uv0?svg=true
68
+ [ appveyor-url ] : https://ci.appveyor.com/project/dillondaudert/nearestneighbordescent-jl
69
+
70
+ [ codecov-img ] : https://codecov.io/gh/dillondaudert/NearestNeighborDescent.jl/branch/master/graph/badge.svg
71
+ [ codecov-url ] : https://codecov.io/gh/dillondaudert/NearestNeighborDescent.jl
72
+
73
+ [ coveralls-img ] : https://coveralls.io/repos/github/dillondaudert/NearestNeighborDescent.jl/badge.svg?branch=master
74
+ [ coveralls-url ] : https://coveralls.io/github/dillondaudert/NearestNeighborDescent.jl?branch=master
0 commit comments