I'm looking for a reordering technique to group connected components of an adjacency matrix together.
For example, I've made an illustration with two groups, blue and green. Initially the '1's entries are distributed across the rows and columns of the matrix. By reordering the rows and columns, all '1''s can be located in two contiguous sections of the matrix, revealing the blue and green components more clearly.
I can't remember what this reordering technique is called. I've searched for many combinations of adjacency matrix, clique, sorting, and reordering.
The closest hits I've found are
symrcm
moves the elements closer to the diagonal, but does not make groups.Is there a way to reorder the rows and columns of matrix to create a dense corner, in R? which focuses on removing completely empty rows and columns
Please either provide the common name for this technique so that I can google more effectively, or point me in the direction of a Matlab function.
I don't know whether there is a better alternative which should give you direct results, but here is one approach which may serve your purpose.
Your input:
Method 1
Get the mask of which values contains ones in both first row, and first column
Rearrange the Rows (according to the Row-mask)
Gives something like this:
Rearrange columns (according to the column-mask)
Gives the desired results:
Just a check whether the indices are where they are supposed to be or if you want the corresponding re-arranged indices ;)
Before Re-arranging:
After re-arranging (same process we did before)
Output:
Method 2
For Generic case, if you don't know the matrix beforehand, here is the procedure to find the
maskRow
andmaskCol
Code:
Here is an example to try that:
Then, repeat the procedure you followed before:
Here is the result:
Here, is an example:
Why does it fail?
Method 3
Procedure:
Previous example is taken (where the previous method fails) and is run with and without
while-loop
Without Brute force:
With Brute-Forcing while loop:
The number of iterations required to get the correct results may vary. But it is safe to have a good number.
Good Luck!