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

Avoid computing n distances per node in tree #43

Closed
andreasnoack opened this issue Dec 15, 2020 · 2 comments
Closed

Avoid computing n distances per node in tree #43

andreasnoack opened this issue Dec 15, 2020 · 2 comments

Comments

@andreasnoack
Copy link
Member

It seems that one of the main reasons for constructing the KDTree is to have a more efficient way of computing distances but right no all n distances are computed for each node, see

Loess.jl/src/Loess.jl

Lines 81 to 84 in 9127229

# distance to each point
for i in 1:n
ds[i] = euclidean(vec(vert), vec(xs[i,:]))
end
. I believe it should be possible to use the tree to make of these calculations O(log(n)) instead of O(n).

@dcjones
Copy link
Contributor

dcjones commented Jan 19, 2021

I think the neighborhood size q = ceil(Int, (span * n)) is typically such that this brute force approach is fine.

The brute force approach is O(kn) where k is the number of vertices. We could probably use the kd-tree to lookup for each point which vertices' neighborhoods it resides in. But I think points will be in an average of span*k neighborhoods (where span=0.75 by default). This will end up being something like O(n*(log(k) + span*k)) = O(kn), so it's not an asymptotic improvement as long as neighborhoods are defined proportionally like this. If span is small, it might be practically more efficient though.

@andreasnoack
Copy link
Member Author

This is actually mentioned briefly in the original paper. The purpose of KD-tree is not to help with the nearest neighbor calculation. Maybe it's possible to improve here but I don't think my original thinking here is correct so I'll close.

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