What is the distance used by K-nearest neighbour in opencv
Hello,
I am using the machine learning k-nearest neighbour algrithm c++. I have a dataset with a high dimensional features. So, the euclidian distance will be not the best. I try to find which distance used in knearest.cpp to change it and used different distances but I could not because the code lacks comments. I find this block in the 189 but It seems that it not used in the find_nearest function. Any help?
> for( ; t < d; t++ )
> {
>
> double t0 = u[t] - v[t];
> sum += t0*t0;
>
> }
yes, that's the euclidean distance. (why do you think, the code is not used ?) (why do you think, L2SQR norm is not adequate ?)
(oh, and please, hacking the library sounds like a bad idea, if you don't know, what you're doing, no ?)
you can find a long discussion here distance euclidian problems in high dimensions
So, what is the solution to use other distances than euclidian distance? I think it was a bad idea to use just euclidian distance!! They have to make the distance used as an input parameters!
hmm, the idea of having "means" in the 1st place is closely related to some kind of L2 distance, don't you think ?
i.e, if you need to do a BOW model from ORB features, and thus want hamming distance instead, another algorithm, like kmajority would be more appropriate.
In fact I need to use the chi-2 square distance because I have implemented it on mathematica and it gives a good results in my case. I need to use it with opencv knearest neighbours.
ah, i see now.
The implementation of k nearest neighbour in opencv was not professional! In addition, we can not get the indices of the k-nearest neighbours and we can note use an other distance.