algorithm - making use of neighbour finding and symmetry for runtime performance? -


suppose have set of 3d points {x[i], i=1,...,n}, ,

i have array a, each entry a[i] of array corresponds measurement of point x[i]. if 2 points x[i] , x[j] within fixed distance d each other, add constant f(x[i],x[j]), computed function f, both of entries a[i] , a[j] in array.

a direct way compute entries of array a (in pseudocode)

for = 1,...,n     a[i] = 0  = 1,...,n     j = i,...,n         if dist(x[i],x[j]) < d             tmp = f(x[i],x[j])             a[i]+= tmp             a[j]+= tmp 

if have function find_nb(x[i]), takes point x[i] argument , returns set of points within fixed distance d point x[i], including point x[i] itself, , number of them, wonder how function can improve run time performance (such time and/or space) of above algorithm?

following way thought of:

for = 1,...,n     a[i] = 0  = 1,...,n     (nbs, num) = find_nb(x[i])     j = 1,...,num         a[i]+=f(x[i],x[nbs[j]]) 

but doesn't make use of symmetry between every 2 points, i.e. have calculate f(x[i],x[nbs[j]]) twice, fora[i] , a[nbs[j]]. waste. can improved?

thanks!

first, there's bug in code: when = j, add tmp twice, both [i] , [j] same array element.

quite function doesn't return set of points, set of indices of points, improvement quite simple:

for = 1,...,n     (nbs, num) = find_nb(x[i])     k = 1,...,num         j = nbs [k]         if (j >= i)             tmp = f (x [i], x [j])             a[i]+=tmp             if (j != i)                 [j] += tmp 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -