/ / Wie kann man die Ähnlichkeit zwischen zwei Vektoren messen? [Duplizieren] - Matlab, Matrix, Vektor

Wie misst man die Ähnlichkeit zwischen zwei Vektoren? [Duplizieren] - Matlab, Matrix, Vektor

Ich habe zwei Vektoren für zB

Aideal = Rand (256,1);

und A_estimated = Rand (256,1);

Wie kann ich die Ähnlichkeit messen? Mit Ähnlichkeit meine ich, dass jedes Element von A_estimated fast dasselbe ist wie das von Aideal.

Kann mir bitte jemand helfen.

Antworten:

2 für die Antwort № 1
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))

1 für die Antwort № 2

Wenn Sie zwei Vektoren mit respecto Cosinus-Ähnlichkeit unter Code vergleichen möchten, ist genug für Sie

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
%               ugur.ayan@ugurayan.com.tr
%               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