comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Nearest neighbors
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Nearest neighbors [message #68224] Thu, 08 October 2009 18:55
Chris[6] is currently offline  Chris[6]
Messages: 84
Registered: July 2008
Member
On Oct 8, 2:08 pm, "N. Johnson" <evilish...@gmail.com> wrote:
> On Oct 7, 7:00 pm, Chris <beaum...@ifa.hawaii.edu> wrote:
>
>
>
>> On Oct 7, 2:01 pm, "N. Johnson" <evilish...@gmail.com> wrote:
>
>>> I have a set of latitude/longitude pairs and I need to find the n
>>> closest neighbors for all of them. I'm trying to use the
>>> nearest_neighbors() function found on this page:http://www.dfanning.com/code_tips/slowloops.html
>
>>> However, when I attempt to run the function, I get an error on the
>>> line:
>>> p=c[c[point]:c[point+1]-1] ;start with this point's DT neighbors
>
>>> because c[point] is equal to c[point+1]. Since I don't know exactly
>>> what the function is doing, I don't know how to fix it. If it matters,
>>> I have a lot of lat/lon pairs (~1e6) and there may be duplicates.
>
>>> Any suggestions?
>>> Nathan Johnson
>
>> I have an alternative nearest neighbors routine that doesn't use
>> triangulation - it  may be useful (it assumes a euclidian space, so it
>> won't work if your points are very spread out or near a pole)
>
>> Documentation:http://www.ifa.hawaii.edu/~beaumont/code/neare stn.html(lookat
>> nearestn, not nearestn_findneighbors)
>
>> Library:http://www.ifa.hawaii.edu/~beaumont/code/beaumont_li brary.tar
>
>> Chris
>
> Chris,
>
> Thanks that works well. Is there a way to get the nth nearest points
> by calling that function just once? Or do I have to call it n times?
>
> Thanks,
> Nathan

Yes, if you set the /all keyword, it will return a 2d array of the nth
nearest neighbors for each point. Note that it starts counting from
zero, so if you set n = 3, the resulting array will by (4, n_points)

chris
Re: Nearest neighbors [message #68225 is a reply to message #68224] Thu, 08 October 2009 17:08 Go to previous message
N. Johnson is currently offline  N. Johnson
Messages: 2
Registered: October 2009
Junior Member
On Oct 7, 7:00 pm, Chris <beaum...@ifa.hawaii.edu> wrote:
> On Oct 7, 2:01 pm, "N. Johnson" <evilish...@gmail.com> wrote:
>
>> I have a set of latitude/longitude pairs and I need to find the n
>> closest neighbors for all of them. I'm trying to use the
>> nearest_neighbors() function found on this page:http://www.dfanning.com/code_tips/slowloops.html
>
>> However, when I attempt to run the function, I get an error on the
>> line:
>> p=c[c[point]:c[point+1]-1] ;start with this point's DT neighbors
>
>> because c[point] is equal to c[point+1]. Since I don't know exactly
>> what the function is doing, I don't know how to fix it. If it matters,
>> I have a lot of lat/lon pairs (~1e6) and there may be duplicates.
>
>> Any suggestions?
>> Nathan Johnson
>
> I have an alternative nearest neighbors routine that doesn't use
> triangulation - it  may be useful (it assumes a euclidian space, so it
> won't work if your points are very spread out or near a pole)
>
> Documentation:http://www.ifa.hawaii.edu/~beaumont/code/neare stn.html(look at
> nearestn, not nearestn_findneighbors)
>
> Library:http://www.ifa.hawaii.edu/~beaumont/code/beaumont_li brary.tar
>
> Chris

Chris,

Thanks that works well. Is there a way to get the nth nearest points
by calling that function just once? Or do I have to call it n times?

Thanks,
Nathan
Re: Nearest neighbors [message #68250 is a reply to message #68225] Wed, 07 October 2009 19:31 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Oct 7, 9:01 pm, "N. Johnson" <evilish...@gmail.com> wrote:
> I have a set of latitude/longitude pairs and I need to find the n
> closest neighbors for all of them. I'm trying to use the
> nearest_neighbors() function found on this page:http://www.dfanning.com/code_tips/slowloops.html
>
> However, when I attempt to run the function, I get an error on the
> line:
> p=c[c[point]:c[point+1]-1] ;start with this point's DT neighbors
>
> because c[point] is equal to c[point+1]. Since I don't know exactly
> what the function is doing, I don't know how to fix it. If it matters,
> I have a lot of lat/lon pairs (~1e6) and there may be duplicates.
>
> Any suggestions?
> Nathan Johnson

I do not know if this is the problem, but if you need to remove
duplicates, you can use grid_input.
Re: Nearest neighbors [message #68251 is a reply to message #68250] Wed, 07 October 2009 19:00 Go to previous message
Chris[6] is currently offline  Chris[6]
Messages: 84
Registered: July 2008
Member
On Oct 7, 2:01 pm, "N. Johnson" <evilish...@gmail.com> wrote:
> I have a set of latitude/longitude pairs and I need to find the n
> closest neighbors for all of them. I'm trying to use the
> nearest_neighbors() function found on this page:http://www.dfanning.com/code_tips/slowloops.html
>
> However, when I attempt to run the function, I get an error on the
> line:
> p=c[c[point]:c[point+1]-1] ;start with this point's DT neighbors
>
> because c[point] is equal to c[point+1]. Since I don't know exactly
> what the function is doing, I don't know how to fix it. If it matters,
> I have a lot of lat/lon pairs (~1e6) and there may be duplicates.
>
> Any suggestions?
> Nathan Johnson

I have an alternative nearest neighbors routine that doesn't use
triangulation - it may be useful (it assumes a euclidian space, so it
won't work if your points are very spread out or near a pole)

Documentation:
http://www.ifa.hawaii.edu/~beaumont/code/nearestn.html (look at
nearestn, not nearestn_findneighbors)

Library:
http://www.ifa.hawaii.edu/~beaumont/code/beaumont_library.ta r

Chris
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Sky is falling, maybe?
Next Topic: interpolation of irregular satellite data

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:42:57 PDT 2025

Total time taken to generate the page: 0.00749 seconds