Boost logo

Boost Users :

Subject: Re: [Boost-users] Interprenting nearest's neighbor's output
From: Adam Wulkiewicz (adam.wulkiewicz_at_[hidden])
Date: 2014-04-15 06:38:21

Georgios Samaras wrote:
> I changed the code to use points, but order the items are returned is
> not understandable by me.
> I request the 5 NNs of the query point (0, 0), in a dataset of points
> (0, 0), (1, 1), .., (9, 9).
> The output I receive is this:
> knn query result:
> POINT(4 4)
> POINT(3 3)
> POINT(2 2)
> POINT(0 0)
> POINT(1 1)
> If you need the code, let me know. I remember that I read that the
> order is not specified, but does that mean that there is no logic in
> the results? I mean, clearly the 1st NN is (0, 0).

If the kNN query using query() function is performed, the order of
returned Values isn't specified. The function returns 5 NNs, not sorted
5NNs. This way we save a call of sort() or sort_heap().
AFAIK the most typical use case would be to perform a kNN query and then
to process all of those neighbours so it's not needed to sort them

On the other hand in the case of query iterators (
you should get closer Values first.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at