Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Multi-dimensional Nearest Neighbor Algorthm: Got one

Can anyone send me an efficient VBA multi-dimensional (2-D or 3-D) for
finding the nearest neighbors to each point in a set of points?
Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Multi-dimensional Nearest Neighbor Algorthm: Got one

This is just a sample.

Let's say we have a set of points in rows 1 thru 100 where column A contains
the x-coordinate and column B contains the y-coordinate.

The first point [A1:B1] is the target point and we want to find which point
in 2 thru 100 that is nearest to this first point.

Enter and run:

Sub nearest_neighbor()
mn = ((Cells(1, 1).Value - Cells(2, 1).Value) ^ 2 + (Cells(1, 2).Value -
Cells(2, 2).Value) ^ 2) ^ 0.5
where = 1
For i = 3 To 100
w = ((Cells(1, 1).Value - Cells(i, 1).Value) ^ 2 + (Cells(1, 2).Value -
Cells(i, 2).Value) ^ 2) ^ 0.5
If w < mn Then
mn = w
where = i
End If
Next
MsgBox (where)
End Sub

It will output the row containing the point nearest to [A1:B1]
--
Gary's Student


"Jim" wrote:

Can anyone send me an efficient VBA multi-dimensional (2-D or 3-D) for
finding the nearest neighbors to each point in a set of points?
Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Multi-dimensional Nearest Neighbor Algorthm: Got one

Thanks, but that one I know.
I need the nearest neighbor to each point, for all points. The method
you used takes of order n^2 operations: 100 for each point and 100 to
search for the minimum distance to that point.
I thought that there were some algorithms that were linear in the
number of points (n^1).
Here's a reference to an N^1.5 algorithm:

http://cgm.cs.mcgill.ca/~soss/cs644/projects/perrier/

Thanks,
Jim

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Dimensional Lookup coolkat Excel Discussion (Misc queries) 1 June 14th 11 11:48 PM
Multi-dimensional arrays gti_jobert[_5_] Excel Programming 6 February 6th 06 04:45 AM
Multi-Dimensional Array Let & Get Trip[_3_] Excel Programming 0 September 21st 05 08:41 PM
Viewing Multi dimensional array Codea[_2_] Excel Programming 0 August 5th 04 12:49 PM
Problem with Multi-Dimensional Array Kirk[_2_] Excel Programming 2 August 26th 03 03:31 PM


All times are GMT +1. The time now is 01:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"