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

Selection sort implementation #16

Open
ahrnjic3 opened this issue Dec 13, 2022 · 3 comments
Open

Selection sort implementation #16

ahrnjic3 opened this issue Dec 13, 2022 · 3 comments

Comments

@ahrnjic3
Copy link

ahrnjic3 commented Dec 13, 2022

Hello,

My college group and I, tried to modify this algorithm by using selection sort which takes first k elements. However the precision we get for indices is less than 99.9% and the test function fails. This has lead us to believe that using selection sort for a parallel knn algorithm isn't possible. So, our question is if you think that it is possible and if it is how would you implement it? We can send you code for our selection sort method if you need it.

Kind regards,
Amer

@ghost
Copy link

ghost commented Dec 24, 2022

Hello Amer and sorry for the late answer.
I don't see why selection sort would not be possible.
The problem is that the distances computed using the CPU or using CUDA are slightly different.
My guess is that random points are too close to each other.
You can try to increase the distance between points or use a regular grid to make sure the distance is greater than the computation error.
I hope this will help.
Best,
Vincent

@ahrnjic3
Copy link
Author

Hello Vincent,

It's me again. We we're able to implement the selection sort into the algorithm, but it proved to be much slower than your implementation with insertion sort. We tried some other ideas but they failed and now we are out of them. Since our college project requires us to achieve any kind of speedup over previous work, we were wondering if you have any ideas that we could try to implement to speed the algorithm up? (even if it's a small speedup)

All the best,
Amer

@ghost
Copy link

ghost commented Dec 26, 2022

You need to think about what you are trying to achieve. You don't want to sort the n distances and only keep the k smallest ones, you want to reject quickly the n-k points that are not the smallest distances and sort the other k distances. That's why a regular sorting algorithm won't be as fast as my naive implementation I believe. I'm pretty sure that if you keep the same logic but replace the insertion sort with a fancier sort (e.g. merge sort), you'll get a speedup.

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

1 participant