Re: the fastest way to find number of points in sphere(radius r) [message #46399] |
Tue, 22 November 2005 11:16  |
Xavier Llobet
Messages: 7 Registered: April 2005
|
Junior Member |
|
|
In article <1132683502.085584.295570@g14g2000cwa.googlegroups.com>,
"Ed Hyer" <ejhyer@gmail.com> wrote:
> Those are some pretty big numbers for this problem. I'm not sure even
> HISTOGRAM can get around that.
HISTOGRAM should be able to handle 3E5 elements: called once per sphere
center.
> If this is homework, forget about it,
> but if it's your dissertation, I think you'll likely end up calling
> these C routines: http://www.cs.umd.edu/~mount/ANN/
If it's dissertation-grade work, a month of CPU is not much. The work
can be divided in as many pieces as desired (results for each center are
completely independent), and if you can use 6 PC's, from 17:00 to 09:00
plus week-end you are done in less than a week. And this is a
calculation that you need to do only once, as there are no parameters to
vary.
_x.
--
Only one "o" in my address.
|
|
|
|
|
|
Re: the fastest way to find number of points in sphere(radius r) [message #46407 is a reply to message #46406] |
Tue, 22 November 2005 07:29   |
Xavier Llobet
Messages: 7 Registered: April 2005
|
Junior Member |
|
|
In article <1132665267.676156.221240@g49g2000cwa.googlegroups.com>,
"PYJ" <snfinder@naver.com> wrote:
> Thank you, Xavier Llobet~^^
>
> Actually, I expect a vectorizing method. (finding number of points
> about all centers at a time.)
>
> By the way,
> The points that I have are about 5*10^5.
> The number of centers is about 3*10^6.
> These are quite large.
In that case, use ix = lindgen(n_elements(X))
> Anyway, I can't understand your way exactly.
> Can you explain it more ?
>
> So sph(2,*) is the array of distances.
> -> distances? Whose distances?
The only obscure point is
>> ; Shift points' coordinates to the j-th sphere's center
>> blas_axpy, t1, -1, [XC(j), YC(j), ZC(j)], 1, [0,0], 2, ix
It is a fast way of doing X1 = X-XC(j), Y1 = Y-YC(j), Z1 = Z-ZC(j)
> ***I need a number of points. ***
> Do I use a where function about every centers again?
Quoting myself:
>> ; Histogram it, or treat as you please.
> I want to avoid loops if possible.
Well, given that you have 5E5 points and 3E6 centers, you have 1.5E12
distances to consider. It might be difficult to do it without loops...
--
_xavier
--
Only one "o" in my e-mail address
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
|
|
|
Re: the fastest way to find number of points in sphere(radius r) [message #46409 is a reply to message #46407] |
Tue, 22 November 2005 06:00   |
btt
Messages: 345 Registered: December 2000
|
Senior Member |
|
|
PYJ wrote:
> Data-------------------------------------------------------- ---------------
> lots of points: X, Y, Z
> lots of spheres: XC, YC, ZC (positions of center), R(radius)
> ------------------------------------------------------------ ------------------
>
> I want to know the number of galaxies inside each sphere without a
> loop.(If it is possible)
> The faster, the better!
>
> Help me, experts~~!!!
>
Hi,
I'm not sure if this is a similar problem, but it might be worth looking
at this thread...
http://tinyurl.com/92g73
Cheers,
Ben
|
|
|
|
Re: the fastest way to find number of points in sphere(radius r) [message #46413 is a reply to message #46411] |
Tue, 22 November 2005 04:16   |
Xavier Llobet
Messages: 7 Registered: April 2005
|
Junior Member |
|
|
In article <1132659183.873193.230050@g44g2000cwa.googlegroups.com>,
"PYJ" <snfinder@naver.com> wrote:
> Data-------------------------------------------------------- ---------------
> lots of points: X, Y, Z
> lots of spheres: XC, YC, ZC (positions of center), R(radius)
> ------------------------------------------------------------ ------------------
>
> I want to know the number of galaxies inside each sphere without a
> loop.(If it is possible)
> The faster, the better!
>
> Help me, experts~~!!!
I have the nagging feeling of doing someone's homework...
A way to do what you want:
ix=indgen(n_elements(X)) ; index array to be used in BLAS_AXPY
t=transpose([[X], [Y], [Z]]) ; array(3,n) of cartesian coordinates
;Loop over spheres' centers:
t1=t ; temporary array
; Shift points' coordinates to the j-th sphere's center
blas_axpy, t1, -1, [XC(j), YC(j), ZC(j)], 1, [0,0], 2, ix
; Convert to spherical coordinates (long, lat, radius)
sph = cv_coord(from_rect=t1, /TO_SPHERE)
; So sph(2,*) is the array of distances.
; Histogram it, or treat as you please.
;end_loop
It could be faster than your method...
--
_xavier
--
Only one "o" in my e-mail address
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
|
|
|
Re: the fastest way to find number of points in sphere(radius r) [message #46414 is a reply to message #46413] |
Tue, 22 November 2005 04:02   |
Xavier Llobet
Messages: 7 Registered: April 2005
|
Junior Member |
|
|
In article <1132647395.741577.324420@z14g2000cwz.googlegroups.com>,
"PYJ" <snfinder@naver.com> wrote:
> Dear all,
>
> First of all, my data is three-dimensional set.
> I have to use a loop because I have a lot of positions of centers of
> spheres that I should examine.
> I want to find the # of points inside each sphere.
> Now, I use a where function in order to find points inside the cube,
> then I compute distances of all. Next, I use where function again to
> examine # of distances less than radius of sphere.
> I think it is fairly slow when large data is considered.
>
> Is there any faster way?
> The fastest way to find the number of points in sphere(radius r)
>
> ------------------------------------
> data:
> positions of points: X, Y, Z
> centers of spheres: XC, YC, ZC
> radius of spheres: r
> ------------------------------------
>
> Help me~
A way:
ix=indgen(n_elements(X)) ; index array to be used in BLAS_AXPY
t=transpose([[X], [Y], [Z]]) ; array(3,n) of cartesian coordinates
;Loop over spheres' centers:
t1=t ; temporary array
; Shift points' coordinates to the j-th sphere's center
blas_axpy, t1, -1, [XC(j), YC(j), ZC(j)], [0,0], 2, ix
; Convert to spherical coordinates (long, lat, radius)
sph = cv_coord(from_rect=t1, /TO_SPHERE)
; So sph(2,*) is the array of distances.
; Histogram it, or treat as you please.
;end_loop
It could be faster...
--
_xavier
--
Only one "o" in my e-mail address
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
|
|
|
|
|
|
|
|