The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 nearest neighbours algorithm

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
kubra Posted - 11/02/2015 : 09:16:45 AM
Origin Ver. and Service Release (Select Help-->About Origin): 8/8.5
Operating System:Win7

Hello

I have an array of many data points (it depends on measurment, but around few thousands). These data points are not regularly distributed in array, because of measurment errors. However, i need to go through measured points (one by one), find their nearest neighbours and store x and y values in vector. Number of nearest neighbours is given by constant (between 25 and 121, from SF value given by (2*SF+1)^2). I know, these numbers are huge, and i am ok with long duration of calculating.
My algorithm does that. However, it is written to find at least so many nearest neighbours, as the constant is set. So, if constant is 25, for various points it finds 27, 28, 30 etc. points, and stops, when number of them exceed value of constant. If it is less, than value of constant, it erases all values in vector, rises up array, in which it is searching for NN, and does that again. Therefore calculation time (which is by itself long enough) is extending.
My code:
for(C=1; C<=nmbCols-1; C++){
for(R=0; R<=nmbRows-1; R++){
if(!is_missing_value(wks.Cell(R,C))){
i=SF;
j=SF;
do{
for(rR=R-j; rR<=R+j; rR++){
if(rR<0 || rR > nmbRows-1){
;
}
if(rR>=0){
for(cC=C-i; cC<=C+i; cC++){
if(cC<=0 || cC > nmbCols-1){
;
}
if(cC>0){
if(!is_missing_value(wks.Cell(rR,cC))){
vecH.Add(wks.Cell(rR, 0));
vecM.Add(wks.Cell(rR, cC));
}
if(is_missing_value(wks.Cell(rR,cC))){
;
}
if(cC==C+i){
break;
}
}
}
}
if(rR==R+j){
break;
}
}
if((vecM.GetSize())<((2*SF+1)^2)){
i++;
j++;
vecH.RemoveAll();
vecM.RemoveAll();
}
if((vecM.GetSize())>=((2*SF+1)^2)){
;
}
}while((vecM.GetSize())<((2*SF+1)^2));

After code is finished, program does euclidian distances calculations from the calculated data point, and sorts them in vector, and by that it chooses desired number of NN.
I know, it is very specific problem. Maybe if somebody has already done NN algorithm, or there is Origin C command i haven´t found...or has an idea for such edit of code, so it would not have to do repeating calculations... I would really appreciate it :)
2   L A T E S T    R E P L I E S    (Newest First)
kubra Posted - 11/03/2015 : 1:10:18 PM
Hello Sean

Thank you for reply. However, data in my dataset are more-less randomly distributed, and i can´t say beforehand how big is the region, where NN will be. Also, minimum required version is 8.1 SR0 (8.6, eventually), and i need to run my program on version 8.

But thanks again for reply!
Have a nice day
Branislav
SeanMao Posted - 11/03/2015 : 05:28:10 AM
Hi,

We have a built-in X-function levelcrossing that is supported since Origin 8.1 that may help you find the NN X coordinates at a given level. You can find the reference from the link below:

http://www.originlab.com/doc/X-Function/ref/levelcrossing

Give it a try and see if could be some help.

Regards!

Sean

OriginLab Tech. Service

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000