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

Home » Public Forums » archive » Re: the fastest way to find number of points in sphere(radius r)
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: the fastest way to find number of points in sphere(radius r) [message #46399] Tue, 22 November 2005 11:16 Go to next message
Xavier Llobet is currently offline  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 #46403 is a reply to message #46399] Tue, 22 November 2005 10:18 Go to previous messageGo to next message
MarioIncandenza is currently offline  MarioIncandenza
Messages: 231
Registered: February 2005
Senior Member
Those are some pretty big numbers for this problem. I'm not sure even
HISTOGRAM can get around that. 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/

Good luck,

Edward Hyer.
Re: the fastest way to find number of points in sphere(radius r) [message #46405 is a reply to message #46403] Tue, 22 November 2005 08:53 Go to previous messageGo to next message
Haje Korth is currently offline  Haje Korth
Messages: 651
Registered: May 1997
Senior Member
Here the short answer: There is no way to avoid looping over your centers.
Xavier's method is the best you can do.

Haje

PS: To the experts: Please don't tell me that HISTOGRAM is the solution.
This functions usually does everything I cannot comprehend. :-)

"PYJ" <snfinder@naver.com> wrote in message
news:1132665267.676156.221240@g49g2000cwa.googlegroups.com.. .
> 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.
>
> Anyway, I can't understand your way exactly.
> Can you explain it more ?
>
> So sph(2,*) is the array of distances.
> -> distances? Whose distances?
> ***I need a number of points. ***
> Do I use a where function about every centers again?
> I want to avoid loops if possible.
>
> Help, again. ^^
>
> ^_^
>
Re: the fastest way to find number of points in sphere(radius r) [message #46406 is a reply to message #46405] Tue, 22 November 2005 08:01 Go to previous messageGo to next message
Xavier Llobet is currently offline  Xavier Llobet
Messages: 7
Registered: April 2005
Junior Member
By the way, I have just timed my procedure (standard PC, Linux, 756MB)
IDL5.5, and it takes 0.74 s per center with 5E5 points, so for 3E6
centers it would take about a month (without histogramming).

--
_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 #46407 is a reply to message #46406] Tue, 22 November 2005 07:29 Go to previous messageGo to next message
Xavier Llobet is currently offline  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 Go to previous messageGo to next message
btt is currently offline  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 #46411 is a reply to message #46409] Tue, 22 November 2005 05:14 Go to previous messageGo to next message
snfinder@naver.com is currently offline  snfinder@naver.com
Messages: 35
Registered: August 2005
Member
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.

Anyway, I can't understand your way exactly.
Can you explain it more ?

So sph(2,*) is the array of distances.
-> distances? Whose distances?
***I need a number of points. ***
Do I use a where function about every centers again?
I want to avoid loops if possible.

Help, again. ^^

^_^
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 Go to previous messageGo to next message
Xavier Llobet is currently offline  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 Go to previous messageGo to next message
Xavier Llobet is currently offline  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?
Re: the fastest way to find number of points in sphere(radius r) [message #46415 is a reply to message #46414] Tue, 22 November 2005 03:33 Go to previous messageGo to next message
snfinder@naver.com is currently offline  snfinder@naver.com
Messages: 35
Registered: August 2005
Member
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~~!!!
Re: the fastest way to find number of points in sphere(radius r) [message #46419 is a reply to message #46415] Tue, 22 November 2005 01:13 Go to previous messageGo to next message
Peter Clinch is currently offline  Peter Clinch
Messages: 98
Registered: April 1996
Member
PYJ wrote:
> Sorry, I can't understand you.
> It's not voxels.

Like I suspected, I haven't had a coffee yet...

sorry!

Pete.
--
Peter Clinch Medical Physics IT Officer
Tel 44 1382 660111 ext. 33637 Univ. of Dundee, Ninewells Hospital
Fax 44 1382 640177 Dundee DD1 9SY Scotland UK
net p.j.clinch@dundee.ac.uk http://www.dundee.ac.uk/~pjclinch/
Re: the fastest way to find number of points in sphere(radius r) [message #46420 is a reply to message #46419] Tue, 22 November 2005 01:06 Go to previous messageGo to next message
snfinder@naver.com is currently offline  snfinder@naver.com
Messages: 35
Registered: August 2005
Member
Sorry, I can't understand you.
It's not voxels.
X,Y,Z are 3D position of galaxies.(It's not just meaningless points.)

Actually, I want to know the # of points inside spheres by increasing
the radius.

:-)
Re: the fastest way to find number of points in sphere(radius r) [message #46421 is a reply to message #46420] Tue, 22 November 2005 00:31 Go to previous messageGo to next message
Peter Clinch is currently offline  Peter Clinch
Messages: 98
Registered: April 1996
Member
PYJ wrote:
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)

If you have the radius R in terms of voxels then the number of voxels in
the sphere will be 4/3 Pi R^3, surely? Seems so simple I suspect that
my not having had a coffee yet has caused me to miss something obvious...

Pete.
--
Peter Clinch Medical Physics IT Officer
Tel 44 1382 660111 ext. 33637 Univ. of Dundee, Ninewells Hospital
Fax 44 1382 640177 Dundee DD1 9SY Scotland UK
net p.j.clinch@dundee.ac.uk http://www.dundee.ac.uk/~pjclinch/
Re: the fastest way to find number of points in sphere(radius r) [message #46485 is a reply to message #46399] Tue, 22 November 2005 22:23 Go to previous message
snfinder@naver.com is currently offline  snfinder@naver.com
Messages: 35
Registered: August 2005
Member
Thanks a million. Everyone~


Thank you for your time and consideration.

Park
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: image display with different pixel size in x & y
Next Topic: Re: 3d space set up and plotting data on maps

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

Current Time: Wed Oct 08 19:23:33 PDT 2025

Total time taken to generate the page: 0.00891 seconds