Re: [R] Finding the neighbors of the point

From: Leaf Sun <leaflovesun_at_yahoo.ca>
Date: Wed 26 Oct 2005 - 09:05:13 EST


Hi Roger and the list,

The package is working very well. What surprised me most is the speed. As I mentioned in my previous emails, I have to find the neighbors for around 200,000 individuals. It took no more than 10 minutes for the function to finish the searching and returned enough information (ldnn, lnn). As of the third dimension -Z, I applied the code you sent to me, also worked very well. I only modified some condition that meets the requirement. This package is just great for such neighbor searching.

Thank you very much and all the best!

Leaf

>On Mon, 24 Oct 2005, Leaf Sun wrote:
>
>> Running R 2.2.0 on winXP. Computer P4 CPU 3.2G and 1G of RAM.
>
>Please try the attached Windows binary package. Look at the help page for
>ann.dist(). It returns a list of three elements, the first, lnn, gives the
>index numbers of the neighbours closer than maxdist. From there say you
>have a vector z where you want the neighbour relation to apply only when
>z[i] < z[j], so
>
>res <- ann.dist(pts, maxdist=md)
>glist <- vector(mode="list", length=length(res$lnn))
>for (i in seq(along=res$lnn)) {
> if (length(res$lnn[[i]]) > 0) {
> glist[[i]] <- ifelse(z[i] < z[res$lnn[[i]]], 1, 0)
> }
>}
>
>so glist tells you which to drop. Alternatively, you can drop them
>straight away:
>
>res <- ann.dist(pts, maxdist=md)
>glist <- vector(mode="list", length=length(res$lnn))
>for (i in seq(along=res$lnn)) {
> if (length(res$lnn[[i]]) > 0) {
> glist[[i]] <- res$lnn[[i]]][z[i] < z[res$lnn[[i]]]]
> }
>}
>
>(neither of these are tried, so the brackets may not match).
>
>Please let me know how you get on.
>
>Roger
>
>>
>> ======= At 2005-10-24, 09:46:28 you wrote: =======
>>
>> >On Mon, 24 Oct 2005, Leaf Sun wrote:
>> >
>> >> No, I mean I have to find the neighbors of 200,000 points.
>> >
>> >Your R version and OS - output of version on your machine?
>> >
>> >Roger
>> >
>> >
>> >>
>> >> ======= At 2005-10-24, 03:30:41 you wrote: =======
>> >>
>> >> >On Fri, 21 Oct 2005, Leaf Sun wrote:
>> >> >
>> >> >> Roger,
>> >> >>
>> >> >> The data frame is of 200,000 by 15 elements.
>> >> >
>> >> >Do you mean that you need to find distances in 15 dimensions?
>> >> >
>> >> >Roger
>> >> >
>> >> >>
>> >> >> I've learned some C, long time ago. But I guess I would understand the C codes. Thanks!
>> >> >>
>> >> >> Leaf
>> >> >>
>> >> >> ======= At 2005-10-21, 14:11:38 you wrote: =======
>> >> >>
>> >> >> >On Fri, 21 Oct 2005, Leaf Sun wrote:
>> >> >> >
>> >> >> >> Dear all,
>> >> >> >>
>> >> >> >> I got point data of trees. I was wondering if anybody has experience in searching the neighbors within a specified distance efficiently.
>> >> >> >>
>> >> >> >> X Y Z
>> >> >> >> 99 34 65
>> >> >> >> 98 35 29
>> >> >> >> 98 34 28
>> >> >> >> 99 33 33
>> >> >> >> 98 32 23
>> >> >> >> 99 33 21
>> >> >> >> 99 33 22
>> >> >> >> 99 32 24
>> >> >> >> 99 30 23
>> >> >> >> ...
>> >> >> >>
>> >> >> >
>> >> >> >> What I want to do is : searching for the neighbors with a distance R
>> >> >> >> for each tree & the neighbor must have a bigger Z.
>> >> >> >>
>> >> >> >>
>> >> >> >> The data set is huge so the R-codes is working slowly when I search it
>> >> >> >> without subset it.
>> >> >> >>
>> >> >> >
>> >> >> >And huge is how big? For very large problems, you'll need a kd-tree or
>> >> >> >r-tree approach to divide up the point locations before making the spatial
>> >> >> >query (I think the retention of neighbours with a larger z is the final
>> >> >> >step). There do not seem to be such functions in R or contributed packages
>> >> >> >at present. If you are willing to collaborate, I can pass on a draft
>> >> >> >package corrected by Christian Sangiorgio for approximate nearest
>> >> >> >neighbours (an interface to ANN by David Mount and collaborators), but it
>> >> >> >isn't working yet. So an investment in time and some knowledge of C++ will
>> >> >> >be useful.
>> >> >> >
>> >> >> >> Any suggestion would be much appreciated!
>> >> >> >>
>> >> >> >> Leaf
>> >> >> >>
>> >> >> >>
>> >> >> >
>> >> >> >--
>> >> >> >Roger Bivand
>> >> >> >Economic Geography Section, Department of Economics, Norwegian School of
>> >> >> >Economics and Business Administration, Helleveien 30, N-5045 Bergen,
>> >> >> >Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
>> >> >> >e-mail: Roger.Bivand@nhh.no
>> >> >> >
>> >> >> >
>> >> >>
>> >> >> = = = = = = = = = = = = = = = = = = = =
>> >> >>
>> >> >>
>> >> >>
>> >> >> __________________________________________________
>> >> >> Do You Yahoo!?

>> >> >> http://mail.yahoo.com
>> >> >>
>> >> >
>> >> >--
>> >> >Roger Bivand
>> >> >Economic Geography Section, Department of Economics, Norwegian School of
>> >> >Economics and Business Administration, Helleveien 30, N-5045 Bergen,
>> >> >Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
>> >> >e-mail: Roger.Bivand@nhh.no
>> >> >
>> >> >.
>> >>
>> >> = = = = = = = = = = = = = = = = = = = =
>> >>
>> >> Leaf Sun
>> >> leaflovesun@yahoo.ca
>> >> 2005-10-24
>> >>
>> >>
>> >>
>> >> __________________________________________________
>> >> Do You Yahoo!?

>> >> http://mail.yahoo.com
>> >>
>> >
>> >--
>> >Roger Bivand
>> >Economic Geography Section, Department of Economics, Norwegian School of
>> >Economics and Business Administration, Helleveien 30, N-5045 Bergen,
>> >Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
>> >e-mail: Roger.Bivand@nhh.no
>> >
>>
>> = = = = = = = = = = = = = = = = = = = =
>>
>>
>>
>> __________________________________________________
>> Do You Yahoo!?

>> http://mail.yahoo.com
>>
>
>--
>Roger Bivand
>Economic Geography Section, Department of Economics, Norwegian School of
>Economics and Business Administration, Helleveien 30, N-5045 Bergen,
>Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
>e-mail: Roger.Bivand@nhh.no
>
>


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Oct 26 09:15:13 2005

This archive was generated by hypermail 2.1.8 : Wed 26 Oct 2005 - 12:13:43 EST