Euclidian distance showing different result for different formula
3 次查看(过去 30 天)
显示 更早的评论
d = (query_feature' - train_feature').^2; % Eucledian distance
d_1 = sqrt(sum((query_feature' - train_feature') .^ 2))
The method with d is giving some error in retrieval, but when using d_1 it always give 100% accurate retrival (all retrieved images are similar as query image)
What can be wrong? Any suggestions appreciated.
2 个评论
Image Analyst
2021-12-29
编辑:Image Analyst
2021-12-29
Not sure what is wrong. Can you attach your data?
d is a list of the squared differences, while d_1 is the root mean square - a single number and a different thing. Not sure what you're expecting. The only way d or d_1 would be zero (meaning no differences and 100% accuracy) would be if query_feature exaclty equaled train_feature. Is that the case?
回答(2 个)
John D'Errico
2021-12-29
What you write in d is simply not Euclidean distance What can be wrong? Your belief that it is so? What you write in d1 IS a Euclidean distance computation, so that it works should be no surprise.
Meg Noah
2021-12-29
Some code - look at the sizes of the arrays to see why:
nsamples = 25;
ncomponents = 4;
s = RandStream('dsfmt19937','Seed',1123581321);
query_feature = rand(s,nsamples,ncomponents);
train_feature = rand(s,1,ncomponents);
% relative vector between query vectors and training vector
d = (query_feature' - train_feature').^2;
% Three ways to compute Eucledian distance between query vectors and a
% training vector
d_1 = sqrt(sum((query_feature' - train_feature') .^ 2))';
d_2 = sqrt(sum(bsxfun(@minus, query_feature, train_feature).^2,2));
d_3 = vecnorm((query_feature'-train_feature'),2)';
2 个评论
Meg Noah
2021-12-29
The code snippet above creates the distances as vectors - arrays that are nsamples in rows and with one column. What matrix deimension is your code expecting?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Banks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!