Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The knnsearch result seems to be random in C++ version #509

Open
Philip035 opened this issue Jul 29, 2023 · 1 comment
Open

The knnsearch result seems to be random in C++ version #509

Philip035 opened this issue Jul 29, 2023 · 1 comment

Comments

@Philip035
Copy link

When I use flann to perform KNN search on the same data, the result seems to be random in every test. Here is my code:

vector<vector<int>> Poi_kNN_Idx(Poi_In_Ipl_Num, vector<int>(Ngh_K));
vector<vector<double>> Dis_kNN(Poi_In_Ipl_Num, vector<double>(Ngh_K));
flann::Matrix<double> dataMatrix(Poi_In_Ref_Tmp, Poi_In_Ref_Num, 3);
flann::Index<flann::L2<double>> index(dataMatrix, flann::KDTreeIndexParams(4));
index.buildIndex();
flann::Matrix<double> queryMatrix(Poi_In_Ipl_Tmp, Poi_In_Ipl_Num, 3);
index.knnSearch(queryMatrix, Poi_kNN_Idx, Dis_kNN, Ngh_K, flann::SearchParams(128));

where Poi_In_Ref_Tmp and Poi_In_Ipl_Tmp are defined as double*, and xyz coordinates of each point are stored in turn.
However, the result of Poi_kNN_Idx seems to be unfixed.

@stephematician
Copy link

The default method is randomised kd-trees therefore the results are random, too. The algorithms are described here: https://www.cs.ubc.ca/~lowe/papers/09muja.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants