Skip to content

Commit 8dbc084

Browse files
Merge pull request #16 from dillondaudert/v0.3.0-dev
V0.3.0
2 parents 141d63b + 5bb0466 commit 8dbc084

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1972
-1145
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
environment:
22
matrix:
3-
- julia_version: 1
3+
- julia_version: 1.3
44
- julia_version: nightly
55

66
platform:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ deps/deps.jl
55
Manifest.toml
66

77
.ipynb_checkpoints
8+
*.swp
9+
docs/build/

.travis.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
language: julia
2-
os:
2+
notifications:
3+
email: false
4+
os:
35
- linux
46
- osx
5-
7+
- windows
8+
before_script:
9+
- git config --global user.name Tester
10+
- git config --global user.email te@st.er
611
julia:
7-
- 1.0
8-
- 1.2
12+
- 1.3
913
- nightly
10-
11-
script:
12-
- julia -e 'import Pkg; Pkg.build(); Pkg.test(; coverage=true)'
13-
14+
script: travis_wait julia --project -e 'using Pkg; Pkg.test(; coverage=true)'
15+
matrix:
16+
fast_finish: true
17+
allow_failures:
18+
- julia: nightly
1419
codecov: true
1520
coveralls: true
16-
1721
after_success:
1822
- julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
1923
- julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'
24+
25+
jobs:
26+
include:
27+
- stage: "Documentation"
28+
julia: 1.3
29+
os: linux
30+
script:
31+
- julia --project=docs/ docs/make.jl
32+
after_success: skip

Project.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
name = "NearestNeighborDescent"
22
uuid = "dd2c4c9e-a32f-5b2f-b342-08c2f244fce8"
33
authors = ["Dillon Daudert <dillongdaudert@gmail.com>"]
4-
version = "0.2.1"
4+
version = "0.3.0"
55

66
[deps]
77
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
88
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
9+
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
910
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
11+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
12+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1013

1114
[compat]
12-
13-
Distances = "0.8"
1415
DataStructures = "0.15, 0.17"
15-
julia = "1.0"
16+
Distances = "0.8"
17+
LightGraphs = "1.3"
18+
Reexport = "0.2"
19+
julia = "1.3"
1620

1721
[extras]
22+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1823
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1924

2025
[targets]
21-
test = ["Test"]
26+
test = ["Test", "Statistics"]

README.md

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# NearestNeighborDescent.jl
22

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] |
56

67
A Julia implementation of Nearest Neighbor Descent.
78

@@ -20,67 +21,54 @@ NNDescent is based on the heuristic argument that *a neighbor of a neighbor is a
2021
given a list of approximate nearest neighbors to a point, we can improve that list by exploring the neighbors of each
2122
point in the list. The algorithm is in essence the repeated application of this principle.
2223

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
2827
```
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
5428

55-
# nn descent search
56-
graph = DescentGraph(data, n_neighbors)
29+
## Basic Usage
30+
31+
Approximate kNN graph construction on a dataset:
5732

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)
6140
```
6241

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)
6748
```
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)
8656
```
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

Comments
 (0)