findNN: find index of nearest neighbor.

Description Usage Arguments Value Author(s) See Also Examples

Description

Given a vector of sorted double values vec of size n and a vector of m query objects q.

findNN determines for each element q[i] in q the nearest neighbor index o so that the following remains true:

there is no element k with 1 k n and k is not o so that

abs(vec[k] - q[i]) < abs(vec[o] - q[i]).

The internal algorithm of findNN is implemented as binary search. findNN has O(m * log(n)) time complexity.

Usage

1
findNN(q, vec)

Arguments

q

a double vector which can be considered as query objects.

vec

a sorted double vector which can be considered as a data base.

Value

an integer vector

Author(s)

Lucas Schmidt, Christian Panse

See Also

protViz::findNN's cpluplus implementation.

Examples

1
2
3
4
5
(NNidx <- findNN(q<-c(1, 1.0001, 1.24, 1.26), DB<-seq(1,5,by=0.25)))
(NNidx == c(1,1,2,2))

# should be 0
unique(DB[findNN(DB,DB)] - DB)

deisotoper documentation built on May 1, 2019, 8:41 p.m.