[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

came up with an algorithem to go over a list of 2d points an

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 7
Thread images: 1

File: 7UzjUF1M.jpg (19KB, 720x720px) Image search: [Google]
7UzjUF1M.jpg
19KB, 720x720px
came up with an algorithem to go over a list of 2d points and match each point to it's closest point with great efficiency.(nearest neighbor search for 2d)
need a way to genrealize this algorithem to higher dimensions.

basically the brute force way of O(n^2) is for each point go over all other points and find the closest point.

my method is to first sort the list by the point x value (each point is represented as (x,y)).

if for some point p1 I know of some minimum distance d to some other point p2, then if the difference between some point p3 x value and
p1 x value is greater than d, then the distance between p3 and p1 must be greater than he distance between p2 and p1.

using this I would only need to go over few points until I know what the minimum distance point is, instead of the whole list.

python code for you to inspect:
https://gist.github.com/anonymous/35746facfe07f4ed9078eebd39df162b

problem is, I need a way to generalize it to higher dimensions reliably
>>
>>56436480
>>>/homework/
>>
>>56436480
You should check if the distance is greater than d^2:

d(p1,p2) = \sqrt{ \sum_{i = 1}^{N} (x^{1}_{i} - x^{2}_{i})^{2} }

Now let p3 =\{ x^^{3}_{j} \}_{j=1}^{N}. If

x^{1}_{k} - x^{3}_{k} > d(p1,p2)^2

then

d(p1,p3)^{2} = \sum_{i = 1}^{N} (x^{1}_{i} - x^{3}_{i})^{2} = x^{1}_{k} - x^{3}_{k} + \sum_{i = 1 , j \neq k }^{N} (x^{1}_{i} - x^{3}_{i})^{2} > d(p1,p2)^{2} + \sum_{i = 1 , j \neq k }^{N} (x^{1}_{i} - x^{3}_{i})^{2} > d(p1,p2)^{2}

Therefore, d(p1,p3) > d(p1,p2).
>>
>>56436480
best way is to use a proper data structure like kdtree
>>
>>56436480
I bet this would be faster in python with numpy
def find_closest(unarranged_array, index):
unarranged -= unarranged[index]
distances = sum((unarranged*unarranged).transpose())
return distances.index(np.partition(distances,1)[1])

but maybe you are just interested in the theory.
>>
>>56436746
yeah, I am
>>
>>56436597
Nevermind, I'm an idiot. d is fine. If

x^{1}_{k} - x^{3}_{k} > d(p1,p2)

Then

(x^{1}_{k} - x^{3}_{k})^{2} > d(p1,p2)^{2}
Thread posts: 7
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.