Finding the most orthogonal set of n vectors from dataset of unit vectors

조회 수: 11 (최근 30일)
Z
Z 2020년 8월 8일
편집: Z 2020년 10월 13일
I am attempting to find the set of determine a subset of vectors in a matrix that are the most dissimilar. Each row in this matrix is a unit vector which is unique.
idx = nchoosek(1:size(dataset, 1), 5); % Produce all possible combinations of indices
score = zeros(size(idx, 1), 1); % Store similarity score of unit vectors into the corresponding row of score
for I = 1 : size(idx, 1)
score(I) = sum(prod(dataset(idx(I, :), :), 1)); % Element-wise multiply this combination's vectors and add
end
[best_scores, best_idx] = mink(score, 10)
  댓글 수: 1
David Goodmanson
David Goodmanson 2020년 8월 8일
Hi Alex
cosider
a = [ 1 1 1 1 1 1 1 1 -2
2 2 2 2 2 2 2 2 -4
3 3 3 3 3 3 3 3 -6]
Since these three vectors are scalar multiples of each other, they are parallel and as mutually nonorthogonal as you can get. But sum(prod (a)) = 0. So that test is not goiing to work.
[the use of 1 in prod(a,1) is superfluous since 1 is the default]

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2020년 8월 8일
편집: Bruno Luong 2020년 8월 8일
I propose this
% random test A, which represents 100 normalized vector in R^5
n = 5;
m = 100;
A = randn(n,m);
A = A ./ sqrt(sum(A.^2,1));
% Want to select k columns of A, most mutually "orthogonal"
k = 3; % requirement: k <= rank(A) <= n
n = size(A,2);
c = nchoosek(1:n,k);
d = arrayfun(@(r) detsub(A(:,c(r,:))), 1:size(c,1));
[~,imax] = max(d);
% selection of best k columns of A
col = c(imax,:);
B = A(:,col)
% check scalar products, it must have small off-diagonal terms
B'*B
function d = detsub(A)
[~,R] = qr(A,0);
d =prod(abs(diag(R)));
end
  댓글 수: 8
Bruno Luong
Bruno Luong 2020년 8월 25일
Yes
Let me explain to you more. When you do qr on A where each column of A is unit vector:
[Q,R] = qr(A)
you have the following properties
  • span {Q(:,1:i)} contains span {A(:,1:i)} for all i.
  • the coefficient R(i,j) is dot(Q(:,i),A(:,j)) for i <= j.
  • Since norm(A(:,j))=1 and R is triangular we have norm(R(1:j,j)) = 1.
Now doing some math. For i < j.
abs(dot(A(:,i),A(:j)) = norm Projection A(:,j) on span{A(:,i)}
<= norm Projection A(:,j) on span{Q(:,1:i)}
= norm(R(1:i;j))
= sqrt(R(1,j)^2 + R(2,j)^2 + ... R(i,j)^2)
You want abs(dot(A(:,i),A(:j)) small (most orthogonal) meanning that you want
R(1,j)^2 + R(2,j)^2 + ... R(i,j)^2
to be small, for all i < j.
Since from the third property
R(1,j)^2 + R(2,j)^2 + ... R(j,j)^2 = 1
you just want the last term R(j,j)^2 is as large as possible (therefore the partial sum is small).
And that you want for all j.
I chose det(A) = prod(R(j,j)) as metric, since it has some geometrical interpretation as the volume of the parallelepipied formed by columns of A.
Argually you could use other metric such as "Trace"(A) = sum (abs (R(j,j)) as metric.
My own intuition tell me the det choice is somewhat better.
Z
Z 2020년 8월 25일
That is a valuable explanation. Thank you so much for your input!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by