How to find a most reliable basis In a binary matrix?

时间:2017-06-19 14:01:17

标签: matlab matrix

I want to write a MATLAB program that allows to do the following instructions, however i am having some difficulties, so i would be very thankful if someone help me.

Let a binary matrix A. Starting from the first column of A, find the first K linearly independent columns with the largest associated reliability values. Then, these K linearly independent columns are used as the first K columns of a new matrix B, maintaining their reliability order. The remaining (N − K) columns of B are also arranged in decreasing reliability order.

Example :

A = [1 0 0 1 0 0 1 1;
     0 1 0 1 1 0 0 1;
     0 0 1 1 1 0 1 0;
     0 0 0 0 1 1 1 1]

The first three columns of A are linearly independent, the fifth column is linearly independent of the first three columns.

we find :

B = [1 0 0 0 1 0 1 1;
     0 1 0 1 1 0 0 1;
     0 0 1 1 1 0 1 0;
     0 0 0 1 0 1 1 1]

1 个答案:

答案 0 :(得分:1)

您可以使用rank来确定列是否线性独立,如下所示:

K = size(A, 1); % the number of linearly independent columns to find
B = zeros(size(A)); % preallocate output for efficiency
colB = 1; % column index for the next linearly independent column
colBafter = K + 1; % column index for the next linearly dependent column

for i=1:size(A, 2) % loop over all columns in A
  B(:, colB) = A(:, i); % add the next column of A as an independent column to B
  if rank(B(:, 1:colB)) == colB % check if the newly added column is indeed linearly independent
    if colB == K % check if all independent columns are found
      break;
    else
      colB = colB + 1; % increase the independent index as the added column was indeed linearly independent
    end
  else
    B(:, colBafter) = A(:, i); % add the column as a dependent column to B
    colBafter = colBafter + 1; % increase the dependent index as the added column was linearly dependent
  end
end

B(:, colBafter:end) = A(:, i+1:end); % copy the rest of A to B