我有兩個向量,例如:如何測量兩個向量之間的相似度?
Aideal = rand(256,1);
and A_estimated = rand(256,1);
如何測量相似度?通過相似性,我的意思是我希望A_estimated的每個元素都與Aideal的元素幾乎相同。
任何人都可以請幫忙。
我有兩個向量,例如:如何測量兩個向量之間的相似度?
Aideal = rand(256,1);
and A_estimated = rand(256,1);
如何測量相似度?通過相似性,我的意思是我希望A_estimated的每個元素都與Aideal的元素幾乎相同。
任何人都可以請幫忙。
如果你想兩個向量與下面的代碼respecto餘弦相似度比較足夠你
function [similarity] = CosineSimilarity(x1,x2)
%--------------------------------------------------------------------------
% Syntax: [similarity] = CosineSimilarity(x1,x2);
%
% Definition: Cosine similarity is a measure of similarity between two
% non-zero vectors of an inner product space that measures
% the cosine of the angle between them. The cosine of 0° is
% 1, and it is less than 1 for any other angle. It is thus a
% judgment of orientation and not magnitude: two vectors
% with the same orientation have a cosine similarity of 1,
% two vectors at 90° have a similarity of 0, and two vectors
% diametrically opposed have a similarity of -1, independent
% of their magnitude. Cosine similarity is particularly used
% in positive space, where the outcome is neatly bounded in
% [0,1]. The name derives from the term "direction cosine":
% in this case, note that unit vectors are maximally
% "similar" if they're parallel and maximally "dissimilar"
% if they're orthogonal (perpendicular). This is analogous
% to the cosine, which is unity (maximum value) when the
% segments subtend a zero angle and zero (uncorrelated)
% when the segments are perpendicular.[1].
%
% Inputs: [x1] is a vector
% [x2] is a vector
%
% Outputs: [similarity] is between 0 and 1
%
% Complexity: No
%
% Dependencies No dependency.
%
% Author: Ugur Ayan, PhD
% [email protected]
% http://www.ugurayan.com.tr
%
% Date: May 15, 2016
%
% Refrences [1] https://en.wikipedia.org/wiki/Cosine_similarity
%--------------------------------------------------------------------------
if (length (x1) == length(x2))
similarity = sum(x1.*x2)/(norm(x1) * norm(x2));
else
disp('Vectors dimensions does not match');
end
如果你想要任何額外的相似功能,請給出名稱... –
感謝您的代碼。我想這不是我正在尋找的措施。我需要像Root均方根誤差之類的東西。 – sanjeev
mae(A-B) % mean(abs(A-B)) % Average or mean value of array
sae(A-B) % sum(abs(A-B)) % Sum absolute error performance function
norm(A-B,1) % sum(abs(A-B)) % 1-norm of the vector, which is the sum of the element magnitudes.
norm(A-B,inf) % max(abs(A-B)) % maximum absolute row sum of the diff of vectors.
mse(A-B) % mean((A-B).^2) % Mean of Sum of squared error
sse(A-B) % sum((A-B).^2) % Sum of squared error
norm(A-B) % sqrt(sse(A-B))
什麼做你的意思'幾乎same'? – Divakar
我正在做一個優化問題。我的功能是 Aideal = F(Ein); 我找到Ein的近似值,以便得到相同的輸出。我稱之爲A_estimated。 – sanjeev
這取決於你的情況。通常最小化平方距離的總和並不差,但您必須多說一點關於優化問題的信息。 –