I have a symmetric matrix and I want it to be as block-like as possible. I don't have a clear definition. I want the smallest number of groups of non zero elements or maybe the most non-zero elements as close as possible to the diagonal.
Example: $ X = \begin{pmatrix}1& 0 & .3& 0& .5& 0\\ 0& 1& 0& .2& 0& .4\\ .3 &0 &1& 0& .3& .1\\ 0 & .2 & 0 & 1 & 0 & .3\\ .5 & 0 & .3 & 0 & 1 & 0\\ 0 & .4 & .1 & .3 & 0 & 1\end{pmatrix}$
Output: $ Y = \begin{pmatrix}1& .5 & .3& 0& 0& 0\\ .5 & 1 & .3 & 0 & 0 & 0\\ .3 & .3 & 1 & 0 & 0 & .1\\ 0 & 0 & 0 & 1 & .2 & .3\\ 0 & 0 & 0 & .2 & 1 & .4\\ 0 & 0 & .1 & .3 & .4 & 1\end{pmatrix}$
I only had to swap column and row 2 with 5 to get this result. My algorithm was that I swapped rows and colums for the largest non-diagonal element (in the upper triangle) to a closer position to the diagonal.
- Is there a Matlab/Octave function that does this?
- What is this process called?
- What should a good algorithm that does this look for? (When to stop, which row to swap, etc). What should be the definition of what I want?
The domain my question is related to is that these is a term-term affinity matrix (from Information Retrieval). So if $a_{ij}$ is large then the terms $i$ and $j$ occur often in the same documents.
I want to sort the matrix such that the blocks (which broadly refer to topics) can be visualised. In the current state (see image) one can't see much.
EDIT: I found out that this is called matrix permutation.