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

Home » Public Forums » archive » Re: Assign data point to n-Dimensional grid
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: Assign data point to n-Dimensional grid [message #80592] Fri, 22 June 2012 11:28
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <60a53808-3670-43e1-85da-ee00537487f9@googlegroups.com>,
Craig Markwardt <craig.markwardt@gmail.com> wrote:

> On Friday, June 22, 2012 12:06:15 PM UTC-4, (unknown) wrote:
>> Now I find that it is not exactly what I'm looking for
>>
>> Suppose my grid is [5,1,12] and I want to find to which of these values a
>> data point of 4 is closest to.
>>
>> So I write
>>
>> grid = [5,1,12]
>> print, VALUE_LOCATE(grid,4)
>> 1
>>
>> But indeed it should be 0 since the 5 in the grid is closer to my data
>> point...
>> So in fact I need the nearest neighbor... :(
>
> By the way, your grid has to be strictly ascending. If you pass a randomly
> ordered grid, expect random results.
>
> VALUE_LOCATE() always finds the next lowest grid point, not the nearest
> gridpoint.
>
> On the other hand, it's easy enough to check for this.
>
> x = your data points
> grid = [1, 5, 12]
> ii = value_locate(grid, x) ;; You already know this much
>
> ;; See if the ii+1 grid point is closer
> ;; _no overflow_ ___ ii+1 sep ___ __ ii sep __
> wh = where(ii LT 2 AND (grid[ii+1] - x) LT (x-grid[ii]), ct)
>
> ;; If we found some, then use those instead
> if ct GT 0 then ii[wh] = ii[wh]+1
>
> Craig

What he said!

Ken
Re: Assign data point to n-Dimensional grid [message #80593 is a reply to message #80592] Fri, 22 June 2012 10:49 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Friday, June 22, 2012 12:06:15 PM UTC-4, (unknown) wrote:
> Now I find that it is not exactly what I'm looking for
>
> Suppose my grid is [5,1,12] and I want to find to which of these values a data point of 4 is closest to.
>
> So I write
>
> grid = [5,1,12]
> print, VALUE_LOCATE(grid,4)
> 1
>
> But indeed it should be 0 since the 5 in the grid is closer to my data point...
> So in fact I need the nearest neighbor... :(

By the way, your grid has to be strictly ascending. If you pass a randomly ordered grid, expect random results.

VALUE_LOCATE() always finds the next lowest grid point, not the nearest gridpoint.

On the other hand, it's easy enough to check for this.

x = your data points
grid = [1, 5, 12]
ii = value_locate(grid, x) ;; You already know this much

;; See if the ii+1 grid point is closer
;; _no overflow_ ___ ii+1 sep ___ __ ii sep __
wh = where(ii LT 2 AND (grid[ii+1] - x) LT (x-grid[ii]), ct)

;; If we found some, then use those instead
if ct GT 0 then ii[wh] = ii[wh]+1

Craig
Re: Assign data point to n-Dimensional grid [message #80594 is a reply to message #80593] Fri, 22 June 2012 09:06 Go to previous message
antar3s86 is currently offline  antar3s86
Messages: 8
Registered: June 2012
Junior Member
Now I find that it is not exactly what I'm looking for

Suppose my grid is [5,1,12] and I want to find to which of these values a data point of 4 is closest to.

So I write

grid = [5,1,12]
print, VALUE_LOCATE(grid,4)
1

But indeed it should be 0 since the 5 in the grid is closer to my data point...
So in fact I need the nearest neighbor... :(
Re: Assign data point to n-Dimensional grid [message #80595 is a reply to message #80594] Fri, 22 June 2012 08:38 Go to previous message
antar3s86 is currently offline  antar3s86
Messages: 8
Registered: June 2012
Junior Member
On Friday, June 22, 2012 5:14:01 PM UTC+2, Kenneth P. Bowman wrote:
>
>> Hi
>>
>> I face a serious problem in the development of my algorithm.In principle it
>> is very simple:
>>
>> I have a data point in a 9-dimensional parameter space (say,
>> x1,x2,x3,y1,y2,y3,z1,z2,z3) with x,y,z being physical quantities with
>> different units. Furthermore, I have an unequally spaced 9-dimensional
>> reference grid and all i have to do is to compute which grid point is closest
>> to my data point with respect to all 9 dimensions.
>>
>> I have to do this several billion times, so I really want to make sure to do
>> it as fast as possible.
>>
>> Any help with that?
>>
>> cheers
>
> Is your grid separable? That is, does the x-coordinate of
> each grid point depend only on x? If it does, you can find
> the index of each nearest neighbor independently of the others.
>
> If your grids are regular, you should be able to compute the
> nearest neighbor index. Something like this
>
> i = ROUND(nx*(x - xmin)/(xmax - xmin))
>
> If your grids are not regular (not evenly spaced), use
> VALUE_LOCATE to do a binary search.
>
> If your grids are not separable, you have a much more difficult
> problem.
>
> Ken Bowman

Hi

Thanks a lot! My grid is unequally spaced but separable and I think VALUE_LOCATE was just the thing i have been looking for.

You saved my day (or better: week)

cheers
Re: Assign data point to n-Dimensional grid [message #80597 is a reply to message #80595] Fri, 22 June 2012 08:14 Go to previous message
Kenneth P. Bowman is currently offline  Kenneth P. Bowman
Messages: 585
Registered: May 2000
Senior Member
In article <ada6c25c-b056-4578-8d10-f9fb2fa9694d@googlegroups.com>,
antar3s86@gmail.com wrote:

> Hi
>
> I face a serious problem in the development of my algorithm.In principle it
> is very simple:
>
> I have a data point in a 9-dimensional parameter space (say,
> x1,x2,x3,y1,y2,y3,z1,z2,z3) with x,y,z being physical quantities with
> different units. Furthermore, I have an unequally spaced 9-dimensional
> reference grid and all i have to do is to compute which grid point is closest
> to my data point with respect to all 9 dimensions.
>
> I have to do this several billion times, so I really want to make sure to do
> it as fast as possible.
>
> Any help with that?
>
> cheers

Is your grid separable? That is, does the x-coordinate of
each grid point depend only on x? If it does, you can find
the index of each nearest neighbor independently of the others.

If your grids are regular, you should be able to compute the
nearest neighbor index. Something like this

i = ROUND(nx*(x - xmin)/(xmax - xmin))

If your grids are not regular (not evenly spaced), use
VALUE_LOCATE to do a binary search.

If your grids are not separable, you have a much more difficult
problem.

Ken Bowman
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: developing idl applications for use with Siemens e.soft with broker activities
Next Topic: SPLIT numbers into sub-numbers

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

Current Time: Wed Oct 08 15:49:24 PDT 2025

Total time taken to generate the page: 0.00765 seconds