如何测量两个数据的相似性 [英] How to measure the similarity of two data
问题描述
我正在测量两个大小相同为20的数据的相似度.即
I am measuring the similarity of two data with same size is 20. That is
A=[0.915450999999999 0.908220499999997 0.900374999999996 0.890547499999996 0.880455499999997 0.868436999999998 0.853787499999999 0.836066499999999 0.815514999999999 0.785924499999999 0.661612000000002 0.208405500000000 0.0495730000000000 0.0148525000000000 0.00604500000000001 0.00292150000000000 0.00150100000000000 0.000730999999999999 0.000431999999999999 0.000222999999999999]
和
B=[0.915971250000000 0.909765000000000 0.902468749999999 0.894108749999999 0.883719999999998 0.871347499999999 0.857477500000000 0.841131250000000 0.821846250000000 0.796526250000000 0.673128750000000 0.208027500000000 0.0520962500000000 0.0187462500000000 0.00634375000000000 0.00295500000000000 0.00134500000000000 0.000226250000000000 0.000150000000000000 0.000113750000000000]
您能帮我在Matlab中进行计算吗?如果它们相似,则结果显示为1,否则为0. 预先感谢.
Could you help me to calculate it in matlab? The result shows 1 if they are similar, otherwise, 0 is different. Thank in advance.
推荐答案
在MATLAB中计算向量之间距离的最佳解决方案是pdist
方法:
The best solution in MATLAB to calculate the distance between vectors is the pdist
method:
http://www.mathworks.com/help/stats/pdist.html
它可以使用多个指标,并且进行了很好的优化.在文档中,对这些指标进行了很好的描述.
It can use several metrics and it is quite well optimized. In the documantation these metrics are described very well.
pdist
将矩阵中的所有行向量与所有行向量进行比较,并返回所有这些距离.对于两个向量,必须将它们放在一个矩阵中,并且必须使用此矩阵作为输入参数来调用pdist
方法:
pdist
compares all rowvectors with all rowvectors in a matrix and returns all of these distances. For two vectors you have to put them in a matrix and you have to call pdist
method using this matrix as input argument:
% A and B are the vectors of your example
X = [A; B];
D = pdist(X, 'cosine'); % D = 1.0875e-005
如果使用行数更多的矩阵调用pdist
,则输出也将是向量.例如:
If you call pdist
with a matrix with more lines the output will be a vector as well. For example:
% A and B are the vectors of your example
X = [A; A; B; B];
D = pdist(X, 'cosine');
% D = 1.0e-004 * [0 0.1087 0.1087 0.1087 0.1087 0.0000]
与A
(第一行和第二行)相比,
D(1)
为A
.
D(1)
is A
compared with A
(1st row with 2nd row).
D(2)
为A
.
D(3)
为A
.
D(4)
为A
.
D(5)
为A
.
D(6)
为B
.
几年前,我们实现了一个模拟环境,在该环境中比较了从虚拟线扫描相机继承的多个矢量,并使用了这种方法.效果很好.
Few years ago we implemented a simulation environment where several vectors inherit from a virtual line-scan camera are compared, and we used this method. It works perfectly.
这篇关于如何测量两个数据的相似性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!