-
Notifications
You must be signed in to change notification settings - Fork 95
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
add k-d tree #447
add k-d tree #447
Conversation
Depends on: 4336440 from PR mratsim#444.
`nonzero` is now a well behaved proc, which returns a Tensor instead of a nested seq. :)
We don't want to export `<` for tensors that does a element wise comparison until something is smaller or larger in either argument. As I couldn't make the compiler happy with a `bind `<`` in the code, let's work around it by creating a `distinct` type that we only use in the heap queue! 🥳
Only have to turn a few scipy comparisons into a proper test now. Seems to work fine now. An example of a 2D tree based on 1000 random points as a non balanced tree. The color corresponds to the node ID in which the data is. The shape corresponds to the result of a ball query around the red point with a radius of 0.1. All found points in the search correspond are drawn as points. The rest as crosses. And the same input data to create a balanced tree (cutting at the median instead of the middle): Both are using the default leaf size of 16. edit: The plots and stuffAs is evident from these plots up there, I wrote some code to plot such trees. Of course the plotting part is only really possible in the 2D case. But the hyperrectangle + extracting the bounds of each node could come in handy for the k-d case too. I wasn't sure whether to put it into this module directly. While looking around I saw that lonely |
Ok, aside from the question about whether I should add the plotting / hyperrectangle stuff, this is done from my side. Since this is a bit bigger, I'd appreciate if someone could take a look. :) |
Ugh, I forgot about the annoying |
Let's hope it works now. |
This is almost a straight up port from scipy's KD tree (the Python implementation, not
cKDTree
, which is a C implementation).In principle the implementation works and gives the same results as the scipy tree.
Things left to do:
seq[tuple]
to something more reasonable, maybe tuple ofTensor[T], Tensor[int]
.<
comparison of nodesmaybe unify the metricsused here with a general concept of metrics in arraymancer (given that e.g. dbscan allows for different metrics, maybe kmeans does too, haven't checked). NOTE: this will be done after the DBSCAN PR is merged (I'll try to get that done over the weekend). Then we can have a generalmetrics
inspatial
that can be used in clustering and here and by itself.