Algorithm to extract linearly dependent columns in a matrix
Mostrar comentarios más antiguos
Is there any general or standard approach to extract columns that are linearly dependent from the given matrix ?
Thanks and any help is apperciated !
Respuesta aceptada
Más respuestas (2)
Bruno Luong
el 3 de Ag. de 2020
Editada: Bruno Luong
el 3 de Ag. de 2020
Test matrix (10 x 6) with rank 4
M = rand(10,4)*rand(4,6)
Automatic selection of independent columns of M
[Q,R,p] = qr(M,'vector');
dr = abs(diag(R));
if dr(1)
tol = 1e-10;
r = find(dr>=tol*dr(1),1,'last');
ci = p(1:r) % here is the index of independent columns
else
r = 0;
ci = [];
end
% Submatrix with r columns (and full column rank).
Mind=M(:,ci)
% Those three rank estimation should be equals
% if it's not then the cause if MATLAB selection of tolerance for rank differs with the above
% and usage of more robust SVD algorithm for rank estimation
rank(Mind)
rank(M)
r
14 comentarios
HN
el 3 de Ag. de 2020
Bruno Luong
el 5 de Ag. de 2020
I can't comment on other people saying without the context. You better returns the question to them.
I don't understand your question of "doesn't have thoretical explantion".
I, John and Matt show you HERE with more or less the same method with explanation that is doable, providing the limitation of numeric rank/vector dependency is a gray notion in finite-precision calculation.
This algorithm works with solid and rigorous algebra logic background, it's not an emperical algorithm that is impossible to explain.
Bruno Luong
el 5 de Ag. de 2020
Editada: Bruno Luong
el 5 de Ag. de 2020
OK here is MY claim: The algorithm I post above works and gives the right answer (otherwise I don't post an anwer to your original question).
If other people statements disturb you please direct your question to THEM. I have no further comment.
I have used this solution for a long time and never seen it fail, but it seems to rely on the assumption that the rows of the matrix abs(R) from the QR decomposition are maximized at the diagonal. Otherwise, why is it sufficient for the code to look only at the diagonal elements dr? Again, I have never seen this fail to be true, but it would be nice to have a source from mathematical literature that confirms this property of the QR decomposition.
but it seems to rely on the assumption that the rows of the matrix abs(R) from the QR decomposition are maximized at the diagonal. Otherwise, why is it sufficient for the code to look only at the diagonal elements dr?
As an example of why this might not always be true, consider the example from this wiki page
When we do a QR decomposition without permutation, some of the off-diagonals dominate the diagonals,
>> M=[12 -51 4;6 167 -68; -4 24 -41];
>> [Q,R]=qr(M,0); R
R =
-14.0000 -21.0000 14.0000
0 -175.0000 70.0000
0 0 -35.0000
So, the question is why doesn't this happen when we include permutation? Is it theoretically guaranteed to always be this way, and if so why?
>> [Q,R,p]=qr(M,0); R
R =
176.2555 -71.1694 1.6680
0 35.4389 -2.1809
0 0 -13.7281
Bruno Luong
el 5 de Ag. de 2020
Editada: Bruno Luong
el 5 de Ag. de 2020
Matt: "but it seems to rely on the assumption that the rows of the matrix abs(R) from the QR decomposition are maximized at the diagonal."
Yes this statement is true
abs(R(i,i)) >= abs(R(i,j)) for all j>=i
But this is not only an assumption, it is a consequence of the pivoting selection of QR algo with permutaion/.
Proof
At iteration #i, the algorithm selects the remaining (n-i+1) columns of A that maximizes the projection on orthogonal of the subspace V_{i-1} (notation used in my explanation below John's answer), which is abs(R(i,i)).
For simplification let denote W_{k} := orthogonal of the subspace V_{k}.
So later on at the iteration step j > i, abs(R(i,j)) is the norm of the projection of A(:,p(j)) on span(Q(:,i)).
As span(Q(:,i)) is included in W_{i-1} by construction, thus
norm(projection x on span(Q(:,i))) <= norm(projection x on W_{i-1}) for any vector x in R^n.
Apply this for x = A(:,p(j)), we get
abs(R(i,j)) <= norm(projection A(:,p(j)), on W_{i-1}) <= norm(projection A(:,p(i)), on W_{i-1}) = abs(R(i,i))
This is the proof of why diag(R) dominates off-diagonal terms row-wise, therefore you can remove the statement as "assumption".
Bruno Luong
el 5 de Ag. de 2020
Editada: Bruno Luong
el 5 de Ag. de 2020
By similar proof we can show that QR factorization with pivotting satisfied
abs(R(j,j)) <= abs(R(i,i)) for j>=i
In other word abs(diag(R)) is decending sorted.
It can easily see that
the absolute value of determinant of A(:,p(1)) projected on span{Q(:,1)} is abs(R(1,1))
the absolute value of determinant of A(:,p(1:2)) projected on span{Q(:,1:2)} is abs(R(1,1)*R(2,2))
...
the absolute value of determinant of A(:,p(1:n)) projected on span{Q(:,1:n)} is abs(R(1,1)*R(2,2)*...*R(n,n)
We also know when determinant ~= 0, column vectors are independant.
All these observations lead to this fact:
A(:,p(1:r)) are independent with r is the last index such that abs(R(r,r)) > 0.
r being the rank of A, since the product after n will result 0.
QED
Matt J
el 5 de Ag. de 2020
Fantastic!!!!
Henry Wolkowicz
el 28 de Oct. de 2021
Editada: Henry Wolkowicz
el 28 de Oct. de 2021
Are you sure about this algorithm? Are you sure it does what you claim?
I have a 500x2000 matrix and I used both [Q,R,E]=qr(X,0); [~,R,E]=qr(X,0)
and then I plotted plot(abs(diag(R(:,1:500)))) and it definitely!!! was NOT monotonically decreasing!!!
In fact there were some elements on the diagonal that were 'tiny' and so the rank estimation was wrong as the tiny elements were in the middle and not at the bottom.
Has the QR changed at all in recent years???
Henry Wolkowicz
el 30 de Oct. de 2021
I now see the problem, i.e. qr behaves differently with sparse input matrix X. It is fine with X=full(X)
Bruno Luong
el 31 de Oct. de 2021
When you apply qr with permutation on sparse matrix S
[Q,R,p] = qr(S,'vector')
MATLAB returns the permutation to have R having "good" sparse pattern, and does not make the diagonal
abs(diag(R))
decreasing (this requirement usually makes R fully filled with non-zeros elements).
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!